Greetings,
I'm trying to cyclicly sample some of the MBean exposed by Camel. The route is the following:
<camelContext managementNamePattern="#name#" id="monitoringContext" xmlns="http://camel.apache.org/schema/spring">
<jmxAgent id="agent" statisticsLevel="All" />
<route>
<from uri="timer:foo?period=60s" />
<setBody>
<method method="getMetrics" ref="monitoringMBean"></method>
</setBody>
<log message="A monitoring cycle has been performed" />
</route>
</camelContext>
and the Java code is like that:
public String getMetrics() throws Exception
{
Hashtable<String, String
]> env = new Hashtable<String, String[>();
env.put(JMXConnector.CREDENTIALS, new String[]
{ "smx", "smx" });
JMXConnector jmxc = JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root"), env);
MBeanServerConnection server = jmxc.getMBeanServerConnection();
ObjectName objName = new ObjectName("org.apache.camel:type=routes,name=\"
\",");
List<ObjectName> cacheList = new LinkedList<ObjectName>(server.queryNames(objName, null));
for (ObjectName objName2 : cacheList)
for (String op : ops)
{
Object o = server.invoke(objName2, "get" + op, null, null);
if (o != null)
{
EventObject eo = new EventObject(o);
jnen.notify(eo);
}
}
return "done";
}
But before the route starts, the following exception is raised:
java.io.IOException: Cannot bind to URL
rmi://dow-jones:1099/jmxrmi/camel: javax.naming.NameAlreadyBoundException: jmxrmi/camel
Root exception is java.rmi.AlreadyBoundException: jmxrmi/camel
at javax.management.remote.rmi.RMIConnectorServer.newIOException(RMIConnectorServer.java:804)
:1.6.0_31
at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:417)
:1.6.0_31
at org.apache.camel.management.DefaultManagementAgent$1.run(DefaultManagementAgent.java:424)
camel-core-2.9.0.fuse-7-061.jar:2.9.0.fuse-7-061
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
:1.6.0_31
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
:1.6.0_31
at java.lang.Thread.run(Thread.java:662)
:1.6.0_31
Further, the route works correctly. What could be wrong here ?
Many thanks in advance,
Nicolas