9 Replies Latest reply on May 17, 2006 3:00 PM by Diego Leal

    Restart a pool MBean

    k2c Newbie

      Hi to all,

      I am using jboss 2.4.9 and i am trying to solve the problem with DB pool when a DB connection is lost and after a while is up again. In this case the beans which use this pool will give an exception error like
      '[11:45:52,125,testEJB] testDb 1872488 *** Exception in testDb()! Error: java.lang.RuntimeException: No ManagedConnections Available!'

      My solution might be restarting the Mbean which manages the pool i am using when the DB is up again, instead of restarting jboss all over again. Is this possible?

      I have tried to do this in the jmx-console but with no sucess. I tried to execute the stop method and it returned with sucess. Then i tried to execute the start method and it gave me the following error:

      'The MBean [DefaultDomain:service=XADataSource,name=CORE_DB] throws an MBeanException when calling [start]:
      javax.naming.NameAlreadyBoundException: java:/CORE_DB already exists in the NonSerializableFactory map '


      And in my server.log:

      '[12:18:44,704,testEJB] testDb *** testEJB.testDb - Exception! Error: javax.naming.NameNotFoundException: CORE_DB not bound'

      So the pool Mbean is not working anymore. What can i do to solve this situation? How can i bound again the MBean?

      Is this a good solution to solve this kind of problems with the pools ?

      Thanks to all in advance.

      P.S: I have seen in several posts that the best solution is to upgrade to a 3.x or 4 jboss version, but in my case i must use the 2.4.9 version.

        • 1. Re: Restart a pool MBean
          Juha Lindfors Master

          Try undeploying the components that depend on the datasource (the EJBs), then bounce the datasource and redeploy the applications. Maybe that yields a better result.

          • 2. Re: Restart a pool MBean
            k2c Newbie

            Hi juha!

            Thanks for your quick reply! :)

            I am a newbie to jboss and i have a doubt. What do you mean by 'bounce the datasource' ? What are the actions to follow to do that action?

            I understand that deploy and undeploy is place and remove the ejb from the deploy directory.

            Thanks once more for your help.

            • 3. Re: Restart a pool MBean
              Juha Lindfors Master

              Hmm, right. 2.x doesn't have redeployable services, only EJBs. Undeploy EJB, stop/start datasource, deploy EJB.

              • 4. Re: Restart a pool MBean
                k2c Newbie

                Ok this is my output from the server.log file
                when i do those actions:

                '
                [12:58:49,715,CORE_DB] Stopping
                [12:58:49,716,CORE_DB] XA Connection pool CORE_DB removed from JNDI
                [12:58:49,716,XAPoolDataSource] Closing DataSource
                [12:58:49,716,XAPoolDataSource] Binding to JNDI name null
                [12:58:49,716,ObjectPool] Removing pool: CORE_DB
                [12:58:49,719,CORE_DB] XA Connection pool CORE_DB shut down
                [12:58:49,719,CORE_DB] Stopped
                [12:58:57,185,Connection] PING
                [12:58:57,185,Connection] PONG, serverIL=org.jboss.mq.il.jvm.JVMServerIL@1fe451
                [12:59:03,094,Connection] PING
                [12:59:03,094,Connection] PONG, serverIL=org.jboss.mq.il.jvm.JVMServerIL@1fe451
                [12:59:03,271,CORE_DB] Starting
                [12:59:03,272,CORE_DB] setGCInterval(30000)
                [12:59:03,272,CORE_DB] setGCMinIdleTime(60000)
                [12:59:03,272,CORE_DB] setIdleTimeout(60000)
                [12:59:03,272,CORE_DB] setTimestampUsed(true)
                [12:59:03,272,XAConnectionFactory] Starting
                [12:59:03,331,ObjectPool] Adding pool: CORE_DB, GC enabled: true
                [12:59:03,339,CORE_DB] Stopped
                javax.naming.NameAlreadyBoundException: java:/CORE_DB already exists in the NonSerializableFactory map
                at org.jboss.naming.NonSerializableFactory.bind(NonSerializableFactory.java:88)
                at org.jboss.jdbc.XADataSourceLoader.bind(XADataSourceLoader.java:486)
                at org.jboss.jdbc.XADataSourceLoader.startService(XADataSourceLoader.java:439)
                at org.jboss.util.ServiceMBeanSupport.start(ServiceMBeanSupport.java:103)
                at java.lang.reflect.Method.invoke(Native Method)
                at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
                at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
                at com.sun.jdmk.comm.HtmlInvokePage.buildPage(HtmlInvokePage.java:240)
                at com.sun.jdmk.comm.HtmlRequestHandler.processGetRequest(HtmlRequestHandler.java:325)
                at com.sun.jdmk.comm.HtmlRequestHandler.processRequest(HtmlRequestHandler.java:152)
                at com.sun.jdmk.comm.HtmlRequestHandler.doRun(HtmlRequestHandler.java:79)
                at com.sun.jdmk.comm.ClientHandler.run(ClientHandler.java:84)
                at java.lang.Thread.run(Thread.java:479)
                '
                Probably we should unregister the Name CORE_DB from the NonSerializableFactory....

                Any help ?

                Thanks

                • 5. Re: Restart a pool MBean
                  Juha Lindfors Master

                  javax.naming.Context.rebind()

                  don't know if it is exposed as an MBean anywhere (naming service, or JNDI View), if not you'll have to implement your own MBean that does.

                  • 6. Re: Restart a pool MBean
                    k2c Newbie

                    Hi juha!

                    Do you know some source of information where can i learn how to implement the method rebind() in a MBean ?

                    Another aproach .... What if we use RMI to start and stop the MBean? Would that be the same as manually stopping and starting the Mbean ?

                    Thanks

                    • 7. Re: Restart a pool MBean
                      Juha Lindfors Master

                      Any tutorial that explains how to use JNDI should do. RMI works the same.

                      • 8. Re: Restart a pool MBean
                        k2c Newbie

                        Hi to all!

                        I have tried the rebind and unbind commands with no success. Below are the steps i have followed:

                        1. Went to the JNDIView in the console and it showed me an entry to the mbean CORE_DB like this:
                        CORE_DB (class: org.jboss.pool.jdbc.xa.XAPoolDataSource)

                        2. Then i made a stop in the CORE_DB service service=XADataSource,name=CORE_DB

                        3. went again to the JNDIView service and the CORE_DB entry no longer exists.

                        4. Then tried to start the CORE_DB mbean again and the same error appeared like the one i have showed before.
                        javax.naming.NameAlreadyBoundException: java:/CORE_DB already exists in the NonSerializableFactory map

                        5. The next step was to implement an mbean which might do a rebind.

                        This is the code of the rebind method:
                        public void rebindDBMb() {

                        try {
                        System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
                        System.setProperty("java.naming.provider.url", "localhost:8082");
                        System.out.println("[stopDBMb] : get Context");
                        Context ctx = new InitialContext();

                        System.out.println("[stopDBMb] : lookup");
                        XAPoolDataSource ref = (XAPoolDataSource) ctx.lookup("java:/CORE_DB");
                        System.out.println("[stopDBMb] : rebind");
                        ctx.rebind("java:/CORE_DB",ref);

                        } catch (Exception e) {
                        System.out.println("ERROR in MBean MyMonitor: stopDBMb");
                        }
                        }

                        But it did not work

                        This is the result from the server.log which shows the sequence i have made:

                        [17:26:36,799,CORE_DB] Stopping
                        [17:26:36,800,CORE_DB] XA Connection pool CORE_DB removed from JNDI
                        [17:26:36,800,XAPoolDataSource] Closing DataSource
                        [17:26:36,800,XAPoolDataSource] Binding to JNDI name null
                        [17:26:36,801,ObjectPool] Removing pool: CORE_DB
                        [17:26:36,805,CORE_DB] XA Connection pool CORE_DB shut down
                        [17:26:36,805,CORE_DB] Stopped
                        [17:26:55,798,CORE_DB] Starting
                        [17:26:55,799,CORE_DB] setGCInterval(30000)
                        [17:26:55,799,CORE_DB] setGCMinIdleTime(60000)
                        [17:26:55,799,CORE_DB] setIdleTimeout(60000)
                        [17:26:55,799,CORE_DB] setTimestampUsed(true)
                        [17:26:55,800,XAConnectionFactory] Starting
                        [17:26:55,867,ObjectPool] Adding pool: CORE_DB, GC enabled: true
                        [17:26:55,875,CORE_DB] Stopped
                        javax.naming.NameAlreadyBoundException: java:/CORE_DB already exists in the NonSerializableFactory map
                        at org.jboss.naming.NonSerializableFactory.bind(NonSerializableFactory.java:88)
                        at org.jboss.jdbc.XADataSourceLoader.bind(XADataSourceLoader.java:486)
                        at org.jboss.jdbc.XADataSourceLoader.startService(XADataSourceLoader.java:439)
                        at org.jboss.util.ServiceMBeanSupport.start(ServiceMBeanSupport.java:103)
                        at java.lang.reflect.Method.invoke(Native Method)
                        at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
                        at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
                        at com.sun.jdmk.comm.HtmlInvokePage.buildPage(HtmlInvokePage.java:240)
                        at com.sun.jdmk.comm.HtmlRequestHandler.processGetRequest(HtmlRequestHandler.java:325)
                        at com.sun.jdmk.comm.HtmlRequestHandler.processRequest(HtmlRequestHandler.java:152)
                        at com.sun.jdmk.comm.HtmlRequestHandler.doRun(HtmlRequestHandler.java:79)
                        at com.sun.jdmk.comm.ClientHandler.run(ClientHandler.java:84)
                        at java.lang.Thread.run(Thread.java:479)

                        [17:27:03,714,STDOUT] [stopDBMb] : get Context
                        [17:27:03,714,STDOUT] [stopDBMb] : lookup
                        [17:27:03,715,STDOUT] ERROR in MBean MyMonitor: stopDBMb

                        So as you see an error has occured in my mbean after the lookup command.

                        6. Next i try to view the JNDIView service and the console just hangs. It does not shows nothing and the browser keeps waiting for information to arrive. Probably i have messed with the Naming factory properties. But what am i doing wrong?

                        Does the system properties are not right?

                        Thanks to all in advance.

                        • 9. Re: Restart a pool MBean
                          Diego Leal Newbie

                          I had to use

                          Hashtable ht = new Hashtable();
                          ht.put(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE, "true");
                          JMXConnectorServer jmxCS = JMXConnectorServerFactory.newJMXConnectorServer(url, ht, mbs);


                          where mbs is my MBeanServer