use of javax.management.openmbean.TabularData in project camel by apache.
the class ManagedInflightRepository method browse.
@Override
public TabularData browse(String routeId, int limit, boolean sortByLongestDuration) {
try {
TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listInflightExchangesTabularType());
Collection<InflightRepository.InflightExchange> exchanges = inflightRepository.browse(routeId, limit, sortByLongestDuration);
for (InflightRepository.InflightExchange entry : exchanges) {
CompositeType ct = CamelOpenMBeanTypes.listInflightExchangesCompositeType();
String exchangeId = entry.getExchange().getExchangeId();
String fromRouteId = entry.getFromRouteId();
String atRouteId = entry.getAtRouteId();
String nodeId = entry.getNodeId();
String elapsed = "" + entry.getElapsed();
String duration = "" + entry.getDuration();
CompositeData data = new CompositeDataSupport(ct, new String[] { "exchangeId", "fromRouteId", "routeId", "nodeId", "elapsed", "duration" }, new Object[] { exchangeId, fromRouteId, atRouteId, nodeId, elapsed, duration });
answer.put(data);
}
return answer;
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
use of javax.management.openmbean.TabularData in project camel by apache.
the class ManagedTopicLoadBalancerTest method testManageTopicLoadBalancer.
public void testManageTopicLoadBalancer() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
// 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());
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 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.TabularData in project camel by apache.
the class ManagedTypeConverterRegistryTest method testTypeConverterRegistry.
public void testTypeConverterRegistry() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:a").expectedMessageCount(2);
template.sendBody("direct:start", "3");
template.sendBody("direct:start", "7");
assertMockEndpointsSatisfied();
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=services,*");
// number of services
Set<ObjectName> names = mbeanServer.queryNames(on, null);
ObjectName name = null;
for (ObjectName service : names) {
if (service.toString().contains("DefaultTypeConverter")) {
name = service;
break;
}
}
assertNotNull("Cannot find DefaultTypeConverter", name);
// is disabled by default
Boolean enabled = (Boolean) mbeanServer.getAttribute(name, "StatisticsEnabled");
assertEquals(Boolean.FALSE, enabled);
// need to enable statistics
mbeanServer.setAttribute(name, new Attribute("StatisticsEnabled", Boolean.TRUE));
Long failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
assertEquals(0, failed.intValue());
Long miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
assertEquals(0, miss.intValue());
try {
template.sendBody("direct:start", "foo");
fail("Should have thrown exception");
} catch (Exception e) {
// expected
}
// should now have a failed
failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
assertEquals(1, failed.intValue());
miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
assertEquals(0, miss.intValue());
// reset
mbeanServer.invoke(name, "resetTypeConversionCounters", null, null);
failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
assertEquals(0, failed.intValue());
miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
assertEquals(0, miss.intValue());
// we have more than 150 converters out of the box
Integer converters = (Integer) mbeanServer.getAttribute(name, "NumberOfTypeConverters");
assertTrue("Should be more than 150 converters, was: " + converters, converters >= 150);
Boolean has = (Boolean) mbeanServer.invoke(name, "hasTypeConverter", new Object[] { "String", "java.io.InputStream" }, new String[] { "java.lang.String", "java.lang.String" });
assertTrue("Should have type converter", has.booleanValue());
has = (Boolean) mbeanServer.invoke(name, "hasTypeConverter", new Object[] { "java.math.BigInteger", "int" }, new String[] { "java.lang.String", "java.lang.String" });
assertFalse("Should not have type converter", has.booleanValue());
// we have more than 150 converters out of the box
TabularData data = (TabularData) mbeanServer.invoke(name, "listTypeConverters", null, null);
assertTrue("Should be more than 150 converters, was: " + data.size(), data.size() >= 150);
}
use of javax.management.openmbean.TabularData in project camel by apache.
the class ManagedRoutingSlipTest method testManageRoutingSlip.
public void testManageRoutingSlip() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MockEndpoint foo = getMockEndpoint("mock:foo");
foo.expectedMessageCount(2);
MockEndpoint bar = getMockEndpoint("mock:bar");
bar.expectedMessageCount(1);
template.sendBodyAndHeader("direct:start", "Hello World", "whereTo", "direct:foo,direct:foo,direct:bar");
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 lan = (String) mbeanServer.getAttribute(on, "ExpressionLanguage");
assertEquals("header", lan);
String uri = (String) mbeanServer.getAttribute(on, "Expression");
assertEquals("whereTo", uri);
TabularData data = (TabularData) mbeanServer.invoke(on, "extendedInformation", null, null);
assertNotNull(data);
assertEquals(2, data.size());
data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
assertNotNull(data);
assertEquals(3, data.size());
data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
assertNotNull(data);
assertEquals(6, data.size());
String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
assertNotNull(json);
assertTrue(json.contains("\"description\": \"Routes a message through a series of steps that are pre-determined (the slip)"));
}
Aggregations