use of javax.management.openmbean.CompositeData in project camel by apache.
the class ManagedTransformerRegistryTest method testManageTransformerRegistry.
public void testManageTransformerRegistry() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"), null);
List<ObjectName> list = new ArrayList<ObjectName>(set);
ObjectName on = null;
for (ObjectName name : list) {
if (name.getCanonicalName().contains("DefaultTransformerRegistry")) {
on = name;
break;
}
}
assertNotNull("Should have found TransformerRegistry", on);
Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumCacheSize");
assertEquals(1000, max.intValue());
Integer current = (Integer) mbeanServer.getAttribute(on, "Size");
assertEquals(3, current.intValue());
current = (Integer) mbeanServer.getAttribute(on, "StaticSize");
assertEquals(0, current.intValue());
current = (Integer) mbeanServer.getAttribute(on, "DynamicSize");
assertEquals(3, current.intValue());
String source = (String) mbeanServer.getAttribute(on, "Source");
assertTrue(source.startsWith("TransformerRegistry"));
assertTrue(source.endsWith("capacity: 1000"));
TabularData data = (TabularData) mbeanServer.invoke(on, "listTransformers", null, null);
for (Object row : data.values()) {
CompositeData composite = (CompositeData) row;
String scheme = (String) composite.get("scheme");
String from = (String) composite.get("from");
String to = (String) composite.get("to");
String description = (String) composite.get("description");
boolean isStatic = (boolean) composite.get("static");
boolean isDynamic = (boolean) composite.get("dynamic");
LOG.info("[{}][{}][{}][{}][{}][{}]", scheme, from, to, isStatic, isDynamic, description);
if (description.startsWith("ProcessorTransformer")) {
assertEquals(null, scheme);
assertEquals("xml:foo", from);
assertEquals("json:bar", to);
} else if (description.startsWith("DataFormatTransformer")) {
assertEquals(null, scheme);
assertEquals("java:" + ManagedTransformerRegistryTest.class.getName(), from);
assertEquals("xml:test", to);
} else if (description.startsWith("MyTransformer")) {
assertEquals("custom", scheme);
assertEquals(null, from);
assertEquals(null, to);
} else {
fail("Unexpected transformer:" + description);
}
}
assertEquals(3, data.size());
}
use of javax.management.openmbean.CompositeData in project camel by apache.
the class ManagedValidatorRegistryTest method testManageValidatorRegistry.
public void testManageValidatorRegistry() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"), null);
List<ObjectName> list = new ArrayList<ObjectName>(set);
ObjectName on = null;
for (ObjectName name : list) {
if (name.getCanonicalName().contains("DefaultValidatorRegistry")) {
on = name;
break;
}
}
assertNotNull("Should have found ValidatorRegistry", on);
Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumCacheSize");
assertEquals(1000, max.intValue());
Integer current = (Integer) mbeanServer.getAttribute(on, "Size");
assertEquals(3, current.intValue());
current = (Integer) mbeanServer.getAttribute(on, "StaticSize");
assertEquals(0, current.intValue());
current = (Integer) mbeanServer.getAttribute(on, "DynamicSize");
assertEquals(3, current.intValue());
String source = (String) mbeanServer.getAttribute(on, "Source");
assertTrue(source.startsWith("ValidatorRegistry"));
assertTrue(source.endsWith("capacity: 1000"));
TabularData data = (TabularData) mbeanServer.invoke(on, "listValidators", null, null);
for (Object row : data.values()) {
CompositeData composite = (CompositeData) row;
String type = (String) composite.get("type");
String description = (String) composite.get("description");
boolean isStatic = (boolean) composite.get("static");
boolean isDynamic = (boolean) composite.get("dynamic");
LOG.info("[{}][{}][{}][{}]", type, isStatic, isDynamic, description);
if (description.startsWith("ProcessorValidator")) {
if (description.contains("direct://transformer")) {
assertEquals("xml:foo", type);
} else if (description.contains("validate(simple{${body}} is not null")) {
assertEquals("json:test", type);
} else {
fail("Unexpected validator:" + description);
}
} else if (description.startsWith("MyValidator")) {
assertEquals("custom", type);
} else {
fail("Unexpected validator:" + description);
}
}
assertEquals(3, data.size());
}
use of javax.management.openmbean.CompositeData 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.CompositeData 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.CompositeData 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());
}
}
}
Aggregations