JPOS Q2 initialization using Tomcat6

269 views
Skip to first unread message

Mubashar Ahmad

unread,
Sep 19, 2014, 4:47:39 AM9/19/14
to jpos-...@googlegroups.com
I have already posted following question on Stackoverflow.com, Sorry if it is inappropriate to post same question on multiple places. 

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. QMUXChannelAdaptor 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:164)
 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? 


Victor Salaman

unread,
Sep 19, 2014, 7:41:30 AM9/19/14
to jpos-...@googlegroups.com
Hi:

What can I say, so many bad design choices :)

Although "it works", you should not run Q2 inside your web application. Each web application should be a client to your external Q2 instance running in another JVM. That way when you redeploy your web applications your Q2 instance would be unaffected and you'll be able to run multiple webapps accessing Q2. Another excellent way of doing what you need is running the web container within Q2 as is the case of the excellent Jetty module in jPOS-EE.

Having mentioned "production", remember you need a license for commercial usage, so please contact sal...@jpos.org

/V

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/ee59db6b-d6e1-4b82-bc6a-63748bf4c9b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mubashar Ahmad

unread,
Sep 19, 2014, 9:36:49 AM9/19/14
to jpos-...@googlegroups.com
Hi Victor

Thanks for your quick response. It seems that I was being totally ignorant about how I should use the Q2. However due to this issue I tried to have only one tomcat app which runs Q2 and other two just accessing their relevant QMUX objects using NameRegistrar but apparently it always returns null. May be if you could help me in that regards if you have some kind of sample or a piece of code. 

I understand that above is not exactly what you suggested in your reply because we still have the same JVM but I am interested to know how beans hosted in separate JVM can be accessed in other JVM, Using JDBMSpaces or JESpaces? 

We are already using JPOS in couple of other tomcat webapps which hosts ISOServer and believe that we already have purchased the license, However I'll still confirm the license details from our Architect. 

Thanks a lot

Victor Salaman

unread,
Sep 19, 2014, 9:42:53 AM9/19/14
to jpos-...@googlegroups.com
Hi:

Each web application gets its own Classloader. Each webapp you have is independent of one another... If you want to simplify your architecture, try to run the Jetty module in jPOS-EE, and run your webapps within the Q2 container. I really can't get into details on how to achieve this so you need to do some reading.

/V

Alejandro Revilla

unread,
Sep 19, 2014, 5:04:05 PM9/19/14
to jPOS Users
While your patch solves the problem, it may fail if you deploy more than one WAR containing jPOS.

I believe I may be able to provided a more flexible one. Stay tuned, will follow-up.



Mubashar Ahmad

unread,
Sep 20, 2014, 4:08:43 AM9/20/14
to jpos-...@googlegroups.com
Hi Alejandro 

Thanks a lot, you are always been a great help. 

Regards

Alejandro Revilla

unread,
Sep 20, 2014, 1:18:05 PM9/20/14
to jPOS Users

Can you check if 2dbd8de solves your problem?

It is not the cleanest solution, actually, we'll have a clean solution once we move closer to OSGi, but I believe this patch will help with your Tomcat deployment/re-deployment.



Mubashar Ahmad

unread,
Sep 21, 2014, 9:28:52 AM9/21/14
to jpos-...@googlegroups.com
Hi  Alejandro

Thanks a lot for quick build, working great. In first look I thought that it would make the first loaded app to stop :).
Reply all
Reply to author
Forward
0 new messages