use of javax.management.openmbean.TabularData in project camel by apache.
the class ManagedSendProcessorTest method testManageSendProcessor.
public void testManageSendProcessor() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedMessageCount(1);
MockEndpoint foo = getMockEndpoint("mock:foo");
foo.expectedMessageCount(0);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
// get the object name for the delayer
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");
// should be on route1
String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
assertEquals("route1", routeId);
String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
assertEquals("camel-1", camelId);
String state = (String) mbeanServer.getAttribute(on, "State");
assertEquals(ServiceStatus.Started.name(), state);
String destination = (String) mbeanServer.getAttribute(on, "Destination");
assertEquals("mock://result", destination);
String pattern = (String) mbeanServer.getAttribute(on, "MessageExchangePattern");
assertNull(pattern);
TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
assertNotNull(data);
assertEquals(2, data.size());
data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
assertNotNull(data);
assertEquals(5, data.size());
String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
assertNotNull(json);
assertTrue(json.contains("\"description\": \"Sends the message to a static endpoint\""));
assertTrue(json.contains(" \"uri\": { \"kind\": \"attribute\", \"required\": \"true\", \"type\": \"string\", \"javaType\": \"java.lang.String\"," + " \"deprecated\": \"false\", \"value\": \"mock:result\""));
}
use of javax.management.openmbean.TabularData in project camel by apache.
the class ManagedRoundRobinLoadBalancerTest method testManageRoundRobinLoadBalancer.
public void testManageRoundRobinLoadBalancer() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MockEndpoint foo = getMockEndpoint("mock:foo");
foo.expectedMessageCount(1);
MockEndpoint bar = getMockEndpoint("mock:bar");
bar.expectedMessageCount(1);
template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
template.sendBodyAndHeader("direct:start", "Bye World", "foo", "123");
assertMockEndpointsSatisfied();
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
// get the object name for the delayer
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");
// should be on route1
String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
assertEquals("route1", routeId);
String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
assertEquals("camel-1", camelId);
String state = (String) mbeanServer.getAttribute(on, "State");
assertEquals(ServiceStatus.Started.name(), state);
Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
assertEquals(2, size.intValue());
String last = (String) mbeanServer.getAttribute(on, "LastChosenProcessorId");
assertEquals("bar", last);
TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
assertNotNull(data);
assertEquals(2, data.size());
data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
assertNotNull(data);
assertEquals(5, data.size());
String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
assertNotNull(json);
assertTrue(json.contains("\"description\": \"Balances message processing among a number of nodes"));
}
use of javax.management.openmbean.TabularData 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.TabularData 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.TabularData 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());
}
}
}
Aggregations