We are using jpos with Q2
with one of our webapp deployed on tomcat6 and it was all good. Now we have to implemented another jpos application using q2 stuff but when we deployed it on the same tomcat6 server, it didn't load the objects, e.g. QMUX
, ChannelAdaptor
etc. I noticed following exception in tomcat output log
javax.management.InstanceAlreadyExistsException: Q2:type=system,service=loader
at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:453)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.internal_addObject(DefaultMBeanServerInterceptor.java:1484)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:963)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:917)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:312)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:482)
at org.jpos.q2.Q2.run(Q2.java:150)
at java.lang.Thread.run(Thread.java:662)
You can see the source of exception is Q2
class and when I downloaded the source I noticed following piece of the code in run
method.
ArrayList mbeanServerList = MBeanServerFactory.findMBeanServer(null);
if (mbeanServerList.isEmpty()) {
server = MBeanServerFactory.createMBeanServer (JMX_NAME);
} else {
server = (MBeanServer) mbeanServerList.get(0);
}
So I decided to include jpos source code into the project replace the above code with following (note commented code) and everything start working as expected.
//ArrayList mbeanServerList = MBeanServerFactory.findMBeanServer(null);
//if (mbeanServerList.isEmpty()) {
server = MBeanServerFactory.createMBeanServer (JMX_NAME);
//} else {
// server = (MBeanServer) mbeanServerList.get(0);
//}
Please note that in modified code I am no longer testing whether we already have MBeanServer available or not just create new one.
Question
Now the problem is I am not exactly sure what I am dealing with no idea what MBeanServer is for as my background is .Net. So the question is; is it safe to go with above change into the production?