5 Replies Latest reply on Oct 9, 2003 9:08 AM by marcvh

    findMBeanServer

    marcvh

      Hi,

      I'm new to JBoss and I am using version 3.0.7.
      I have the following problem.
      The file jbossmq_state.xml contains all users that are allowed to subscribe to or publish on a JMS topic. I would like to manage those users programmatically and I thought that the DynamicStateManager would allow me to do so.

      Here's the code I used:
      ObjectName smObjectName = new ObjectName("jboss.mq:service=StateManager");
      // Lookup the state manager.
      List srvrList = MBeanServerFactory.findMBeanServer(null);
      System.out.println(srvrList.size());
      MBeanServer server =(MBeanServer)srvrList.iterator().next();
      System.out.println(server.getMBeanCount().toString());
      DynamicStateManager sm = (DynamicStateManager)server.getAttribute( smObjectName, "Instance");

      The problem with this code is that findMBeanServer returns an empty list.

      JBoss is running on my machine and the same program can publish messages, so I know that JMS works.

      Can anyone give me hint?

      Best regards,

      Marc Vanhoecke
      Project Leader
      B. Rekencentra N.V.

        • 1. Re: findMBeanServer

          Use the RMIAdaptor outside the virtual machine.
          You can see it in jndi.

          Regards,
          Adrian

          • 2. Re: findMBeanServer
            marcvh

            I modified the code and I'm now using the RMIAdaptor:

            // Lookup the state manager.
            InitialContext ic = new InitialContext();
            RMIAdaptor server = (RMIAdaptor)ic.lookup("jmx/rmi/RMIAdaptor");
            ObjectName smObjectName = new ObjectName("jboss.mq:service=StateManager");
            DynamicStateManager sm = (DynamicStateManager)server.getAttribute( smObjectName, "Instance");

            now I get this exception:

            java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
            java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.jboss.mq.sm.file.DynamicStateManager

            jndi.Properties looks like this:
            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
            java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
            # Do NOT uncomment this line as it causes in VM calls to go over
            # RMI!
            java.naming.provider.url=localhost

            What's wrong here?

            Marc.

            • 3. Re: findMBeanServer

              It is an MBean use invoke and get/setAttrbitue.

              The Instance attribute is for the internal use of JBossMQ.

              Regards,
              Adrian

              • 4. Re: findMBeanServer
                marcvh

                It works now.

                Thanks!

                If I need to do the same thing from within a bean, do I use the same code or do I use the code I used before? (findMBeanServer etc.)

                • 5. Re: findMBeanServer
                  marcvh

                  This code works from within a bean:

                  // Add role_id to jbossmq_state.xml using DynamicStateManager
                  ObjectName smObjectName = new ObjectName("jboss.mq:service=StateManager");
                  // Lookup the state manager.
                  List srvrList = MBeanServerFactory.findMBeanServer(null);
                  MBeanServer server =(MBeanServer)srvrList.iterator().next();
                  DynamicStateManager sm = (DynamicStateManager)server.getAttribute( smObjectName, "Instance");

                  So my problem is solved.

                  Thanks for the hints!

                  Regards,

                  Marc vanhoecke
                  Project Leader
                  B. Rekencentra NV