0

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?

Mubashar
  • 12,300
  • 11
  • 66
  • 95

1 Answers1

1

Q2 is a stand-alone application and while it can be embedded in other applications, 99% of the deployments and the main development focus targets stand-alone setup, so you might find (as you did) some rough edges when running it in a container.

That said, we understand your problem and have addressed it in jPOS 1.9.9-SNAPSHOT, see 2dbd8de and ChangeLog for details.

apr
  • 1,288
  • 7
  • 8
  • Thanks I noticed email from Aljendro, haven't tried it yet but hope it would work. Can you please where I can find the jar. I tried locally build it fails on singing task although it produced the jar in build dir. Thanks – Mubashar Sep 21 '14 at 01:39
  • Please ignore my previous comment, I found jar under jpos.org/maven I'll give it a go. thanks – Mubashar Sep 21 '14 at 03:46