use of javax.management.QueryExp in project camel by apache.
the class ManagedResetIncludeProcessorsTest method testReset.
public void testReset() 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();
QueryExp queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("first"));
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
assertEquals(1, set.size());
ObjectName on = set.iterator().next();
// send in 5 messages
template.sendBody("direct:start", "A");
template.sendBody("direct:start", "B");
template.sendBody("direct:start", "C");
template.sendBody("direct:start", "D");
template.sendBody("direct:start", "E");
// and 1 for the 2nd route
template.sendBody("direct:baz", "F");
assertMockEndpointsSatisfied();
// should be 5 on the route
Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(5, completed.longValue());
// and on the processors as well
set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
assertEquals(3, set.size());
for (ObjectName name : set) {
completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
assertEquals(5, completed.longValue());
}
// reset which should reset all processors also
mbeanServer.invoke(on, "reset", new Object[] { true }, new String[] { "boolean" });
// should be 0 on the route
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(0, completed.longValue());
// and on the processors as well
set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
assertEquals(3, set.size());
for (ObjectName name : set) {
completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
assertEquals(0, completed.longValue());
}
// test that the 2nd route is untouched, as we only reset the first route
queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("second"));
set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
assertEquals(1, set.size());
on = set.iterator().next();
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(1, completed.longValue());
// and on the processors as well
set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
assertEquals(1, set.size());
for (ObjectName name : set) {
completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
assertEquals(1, completed.longValue());
}
}
use of javax.management.QueryExp in project camel by apache.
the class ManagedResetIncludeRoutesTest method testReset.
public void testReset() 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();
QueryExp queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("first"));
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
assertEquals(1, set.size());
ObjectName on = set.iterator().next();
// send in 5 messages
template.sendBody("direct:start", "A");
template.sendBody("direct:start", "B");
template.sendBody("direct:start", "C");
template.sendBody("direct:start", "D");
template.sendBody("direct:start", "E");
// and 1 for the 2nd route
template.sendBody("direct:baz", "F");
assertMockEndpointsSatisfied();
// should be 5 on the route
Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(5, completed.longValue());
// and on the processors as well
set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
assertEquals(3, set.size());
for (ObjectName name : set) {
completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
assertEquals(5, completed.longValue());
}
// reset which should reset all routes also
ObjectName ctx = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
mbeanServer.invoke(ctx, "reset", new Object[] { true }, new String[] { "boolean" });
// should be 0 on the route
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(0, completed.longValue());
// and on the processors as well
set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
assertEquals(3, set.size());
for (ObjectName name : set) {
completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
assertEquals(0, completed.longValue());
}
// test that the 2nd route is also reset
queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("second"));
set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
assertEquals(1, set.size());
on = set.iterator().next();
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(0, completed.longValue());
// and on the processors as well
set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
assertEquals(1, set.size());
for (ObjectName name : set) {
completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
assertEquals(0, completed.longValue());
}
}
use of javax.management.QueryExp in project geode by apache.
the class MBeanServerConnectionRule method getProxyMBean.
/**
* Retrieve a new proxy MBean
*
* @return A new proxy MBean of the same type with which the class was constructed
*/
public <T> T getProxyMBean(Class<T> proxyClass, String beanQueryName) throws MalformedObjectNameException, IOException {
ObjectName name = null;
QueryExp query = null;
if (proxyClass != null) {
query = Query.isInstanceOf(Query.value(proxyClass.getName()));
}
if (beanQueryName != null) {
name = ObjectName.getInstance(beanQueryName);
}
Set<ObjectInstance> beans = con.queryMBeans(name, query);
assertEquals("failed to find only one instance of type " + proxyClass.getName() + " with name " + beanQueryName, 1, beans.size());
return JMX.newMXBeanProxy(con, ((ObjectInstance) beans.toArray()[0]).getObjectName(), proxyClass);
}
use of javax.management.QueryExp in project geode by apache.
the class LauncherLifecycleCommandsDUnitTest method getMemberId.
protected static String getMemberId(final String jmxManagerHost, final int jmxManagerPort, final String memberName) throws Exception {
JMXConnector connector = null;
try {
connector = JMXConnectorFactory.connect(new JMXServiceURL(String.format("service:jmx:rmi://%1$s/jndi/rmi://%1$s:%2$d/jmxrmi", jmxManagerHost, jmxManagerPort)));
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName objectNamePattern = ObjectName.getInstance("GemFire:type=Member,*");
QueryExp query = Query.eq(Query.attr("Name"), Query.value(memberName));
Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query);
assertNotNull(objectNames);
assertFalse(objectNames.isEmpty());
assertEquals(1, objectNames.size());
// final ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,Name=" +
// memberName);
ObjectName objectName = objectNames.iterator().next();
return ObjectUtils.toString(connection.getAttribute(objectName, "Id"));
} finally {
IOUtils.close(connector);
}
}
use of javax.management.QueryExp in project geode by apache.
the class MXBeanProvider method getMemberMXBean.
public static MemberMXBean getMemberMXBean(final String serviceName, final String member) throws IOException {
assertState(Gfsh.isCurrentInstanceConnectedAndReady(), "Gfsh must be connected in order to get proxy to a GemFire Member MBean.");
MemberMXBean memberBean = null;
try {
String objectNamePattern = ManagementConstants.OBJECTNAME__PREFIX;
objectNamePattern += (org.apache.geode.internal.lang.StringUtils.isBlank(serviceName) ? org.apache.geode.internal.lang.StringUtils.EMPTY : "service=" + serviceName + org.apache.geode.internal.lang.StringUtils.COMMA_DELIMITER);
objectNamePattern += "type=Member,*";
// NOTE throws a MalformedObjectNameException, however, this should not happen since the
// ObjectName is constructed
// here in a conforming pattern
final ObjectName objectName = ObjectName.getInstance(objectNamePattern);
final QueryExp query = Query.or(Query.eq(Query.attr("Name"), Query.value(member)), Query.eq(Query.attr("Id"), Query.value(member)));
final Set<ObjectName> memberObjectNames = Gfsh.getCurrentInstance().getOperationInvoker().queryNames(objectName, query);
if (!memberObjectNames.isEmpty()) {
memberBean = Gfsh.getCurrentInstance().getOperationInvoker().getMBeanProxy(memberObjectNames.iterator().next(), MemberMXBean.class);
}
} catch (MalformedObjectNameException e) {
Gfsh.getCurrentInstance().logSevere(e.getMessage(), e);
}
return memberBean;
}
Aggregations