use of javax.management.openmbean.CompositeType in project hadoop by apache.
the class JMXJsonServlet method writeObject.
private void writeObject(JsonGenerator jg, Object value) throws IOException {
if (value == null) {
jg.writeNull();
} else {
Class<?> c = value.getClass();
if (c.isArray()) {
jg.writeStartArray();
int len = Array.getLength(value);
for (int j = 0; j < len; j++) {
Object item = Array.get(value, j);
writeObject(jg, item);
}
jg.writeEndArray();
} else if (value instanceof Number) {
Number n = (Number) value;
jg.writeNumber(n.toString());
} else if (value instanceof Boolean) {
Boolean b = (Boolean) value;
jg.writeBoolean(b);
} else if (value instanceof CompositeData) {
CompositeData cds = (CompositeData) value;
CompositeType comp = cds.getCompositeType();
Set<String> keys = comp.keySet();
jg.writeStartObject();
for (String key : keys) {
writeAttribute(jg, key, cds.get(key));
}
jg.writeEndObject();
} else if (value instanceof TabularData) {
TabularData tds = (TabularData) value;
jg.writeStartArray();
for (Object entry : tds.values()) {
writeObject(jg, entry);
}
jg.writeEndArray();
} else {
jg.writeString(value.toString());
}
}
}
use of javax.management.openmbean.CompositeType in project hbase by apache.
the class JSONBean method writeObject.
private static void writeObject(final JsonGenerator jg, final boolean description, Object value) throws IOException {
if (value == null) {
jg.writeNull();
} else {
Class<?> c = value.getClass();
if (c.isArray()) {
jg.writeStartArray();
int len = Array.getLength(value);
for (int j = 0; j < len; j++) {
Object item = Array.get(value, j);
writeObject(jg, description, item);
}
jg.writeEndArray();
} else if (value instanceof Number) {
Number n = (Number) value;
jg.writeNumber(n.toString());
} else if (value instanceof Boolean) {
Boolean b = (Boolean) value;
jg.writeBoolean(b);
} else if (value instanceof CompositeData) {
CompositeData cds = (CompositeData) value;
CompositeType comp = cds.getCompositeType();
Set<String> keys = comp.keySet();
jg.writeStartObject();
for (String key : keys) {
writeAttribute(jg, key, null, cds.get(key));
}
jg.writeEndObject();
} else if (value instanceof TabularData) {
TabularData tds = (TabularData) value;
jg.writeStartArray();
for (Object entry : tds.values()) {
writeObject(jg, description, entry);
}
jg.writeEndArray();
} else {
jg.writeString(value.toString());
}
}
}
use of javax.management.openmbean.CompositeType in project hive by apache.
the class JMXJsonServlet method writeObject.
private void writeObject(JsonGenerator jg, Object value) throws IOException {
if (value == null) {
jg.writeNull();
} else {
Class<?> c = value.getClass();
if (c.isArray()) {
jg.writeStartArray();
int len = Array.getLength(value);
for (int j = 0; j < len; j++) {
Object item = Array.get(value, j);
writeObject(jg, item);
}
jg.writeEndArray();
} else if (value instanceof Number) {
Number n = (Number) value;
jg.writeNumber(n.toString());
} else if (value instanceof Boolean) {
Boolean b = (Boolean) value;
jg.writeBoolean(b);
} else if (value instanceof CompositeData) {
CompositeData cds = (CompositeData) value;
CompositeType comp = cds.getCompositeType();
Set<String> keys = comp.keySet();
jg.writeStartObject();
for (String key : keys) {
writeAttribute(jg, key, cds.get(key));
}
jg.writeEndObject();
} else if (value instanceof TabularData) {
TabularData tds = (TabularData) value;
jg.writeStartArray();
for (Object entry : tds.values()) {
writeObject(jg, entry);
}
jg.writeEndArray();
} else {
jg.writeString(value.toString());
}
}
}
use of javax.management.openmbean.CompositeType in project tomcat by apache.
the class JMXAccessorTask method createProperty.
/**
* create result as property with name from property prefix When result is
* an array and isSeparateArrayResults is true, resultproperty used as
* prefix (<code>resultproperty.0-array.length</code> and store the
* result array length at <code>resultproperty.length</code>. Other
* option is that you delimit your result with a delimiter
* (java.util.StringTokenizer is used).
*
* @param propertyPrefix Prefix for the property
* @param result The result
*/
protected void createProperty(String propertyPrefix, Object result) {
if (propertyPrefix == null)
propertyPrefix = "";
if (result instanceof CompositeDataSupport) {
CompositeDataSupport data = (CompositeDataSupport) result;
CompositeType compositeType = data.getCompositeType();
Set<String> keys = compositeType.keySet();
for (Iterator<String> iter = keys.iterator(); iter.hasNext(); ) {
String key = iter.next();
Object value = data.get(key);
OpenType<?> type = compositeType.getType(key);
if (type instanceof SimpleType<?>) {
setProperty(propertyPrefix + "." + key, value);
} else {
createProperty(propertyPrefix + "." + key, value);
}
}
} else if (result instanceof TabularDataSupport) {
TabularDataSupport data = (TabularDataSupport) result;
for (Iterator<Object> iter = data.keySet().iterator(); iter.hasNext(); ) {
Object key = iter.next();
for (Iterator<?> iter1 = ((List<?>) key).iterator(); iter1.hasNext(); ) {
Object key1 = iter1.next();
CompositeData valuedata = data.get(new Object[] { key1 });
Object value = valuedata.get("value");
OpenType<?> type = valuedata.getCompositeType().getType("value");
if (type instanceof SimpleType<?>) {
setProperty(propertyPrefix + "." + key1, value);
} else {
createProperty(propertyPrefix + "." + key1, value);
}
}
}
} else if (result.getClass().isArray()) {
if (isSeparatearrayresults()) {
int size = 0;
for (int i = 0; i < Array.getLength(result); i++) {
if (setProperty(propertyPrefix + "." + size, Array.get(result, i))) {
size++;
}
}
if (size > 0) {
setProperty(propertyPrefix + ".Length", Integer.toString(size));
}
}
} else {
String delim = getDelimiter();
if (delim != null) {
StringTokenizer tokenizer = new StringTokenizer(result.toString(), delim);
int size = 0;
for (; tokenizer.hasMoreTokens(); ) {
String token = tokenizer.nextToken();
if (setProperty(propertyPrefix + "." + size, token)) {
size++;
}
}
if (size > 0)
setProperty(propertyPrefix + ".Length", Integer.toString(size));
} else {
setProperty(propertyPrefix, result.toString());
}
}
}
use of javax.management.openmbean.CompositeType in project druid by alibaba.
the class JdbcStatManager method getDataSourceCompositeType.
public static CompositeType getDataSourceCompositeType() throws JMException {
if (COMPOSITE_TYPE != null) {
return COMPOSITE_TYPE;
}
OpenType<?>[] indexTypes = new OpenType<?>[] { //
SimpleType.LONG, //
SimpleType.STRING, //
SimpleType.STRING, //
new ArrayType<SimpleType<String>>(SimpleType.STRING, false), //
SimpleType.DATE, //
SimpleType.STRING, //
SimpleType.STRING, //
SimpleType.INTEGER, //
SimpleType.INTEGER, //
SimpleType.STRING, //
SimpleType.LONG, //
SimpleType.INTEGER, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.DATE, //
SimpleType.LONG, //
SimpleType.DATE, //
SimpleType.STRING, //
SimpleType.STRING, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.INTEGER, //
SimpleType.INTEGER, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.DATE, //
SimpleType.STRING, //
SimpleType.STRING, //
SimpleType.LONG, //
SimpleType.INTEGER, //
SimpleType.DATE, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.INTEGER, //
SimpleType.INTEGER, //
SimpleType.LONG, SimpleType.DATE, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.DATE, //
SimpleType.STRING, SimpleType.STRING, //
SimpleType.LONG, //
SimpleType.STRING, //
SimpleType.STRING, //
SimpleType.LONG, //
SimpleType.INTEGER, //
SimpleType.LONG, //
SimpleType.DATE, //
SimpleType.LONG, //
SimpleType.LONG, //
new ArrayType<Long>(SimpleType.LONG, true), // 55 -
new ArrayType<Long>(SimpleType.LONG, true) };
String[] indexNames = { // 0 - 4
"ID", "URL", "Name", "FilterClasses", //
"CreatedTime", // 5 - 9
"RawUrl", "RawDriverClassName", "RawDriverMajorVersion", "RawDriverMinorVersion", //
"Properties", // 10 - 14
"ConnectionActiveCount", "ConnectionActiveCountMax", "ConnectionCloseCount", "ConnectionCommitCount", //
"ConnectionRollbackCount", // 15 - 19
"ConnectionConnectLastTime", "ConnectionConnectErrorCount", "ConnectionConnectErrorLastTime", "ConnectionConnectErrorLastMessage", //
"ConnectionConnectErrorLastStackTrace", // 20 - 24
"StatementCreateCount", "StatementPrepareCount", "StatementPreCallCount", "StatementExecuteCount", //
"StatementRunningCount", // 25 - 29
"StatementConcurrentMax", "StatementCloseCount", "StatementErrorCount", "StatementLastErrorTime", //
"StatementLastErrorMessage", // 30 - 34
"StatementLastErrorStackTrace", "StatementExecuteMillisTotal", "ConnectionConnectingCount", "StatementExecuteLastTime", //
"ResultSetCloseCount", // 35 -39
"ResultSetOpenCount", "ResultSetOpenningCount", "ResultSetOpenningMax", "ResultSetFetchRowCount", //
"ResultSetLastOpenTime", //
"ResultSetErrorCount", //
"ResultSetOpenningMillisTotal", //
"ResultSetLastErrorTime", //
"ResultSetLastErrorMessage", //
"ResultSetLastErrorStackTrace", //
"ConnectionConnectCount", //
"ConnectionErrorLastMessage", //
"ConnectionErrorLastStackTrace", //
"ConnectionConnectMillisTotal", "ConnectionConnectingCountMax", //
"ConnectionConnectMillisMax", //
"ConnectionErrorLastTime", //
"ConnectionAliveMillisMax", //
"ConnectionAliveMillisMin", //
"ConnectionHistogram", // 55 -
"StatementHistogram" };
COMPOSITE_TYPE = new CompositeType("DataSourceStatistic", "DataSource Statistic", indexNames, indexNames, indexTypes);
return COMPOSITE_TYPE;
}
Aggregations