6 Replies Latest reply on Nov 15, 2002 10:06 PM by garyg

    how to delete/create queue because InstanceAlreadyExistsExce

    garyg Novice

      If my client for some reason goes down and I have to restart it, I'd get the following exception ...

      ---

      MBeanException: Exception in MBean operation 'createQueue(,java.lang.String,java.lang.String)'
      Cause: javax.management.InstanceAlreadyExistsException: jboss.mq.destination:service=Queue,name=trinity already
      registered. at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:303)

      ---

      The following code is used to created this queue ...

      ---

      MBeanServer server = (MBeanServer)MBeanServerFactory.findMBeanServer(null).iterator().next();

      server.invoke(new ObjectName("JBossMQ", "service", "Server"), "createQueue", new Object[] { bInfo.getNodeName() }, new String[] {"java.lang.String"});

      ---

      So my question is, if this queue already exists, how would I *unregister* it and then recreate it?

      Any help much appreciated.

        • 1. Re: how to delete/create queue because InstanceAlreadyExists
          Adrian Brock Master

          destroyQueue

          Regards,
          Adrian

          • 2. Re: how to delete/create queue because InstanceAlreadyExists
            garyg Novice

            I was hoping I'd be able to catch an InstanceAlreadyExistsException where I'd then call destroyQueue, but since I'm using the http adaptor to createQueue from a client, I can't catch this exception.

            Is there anyway to check to see if the queue exists first?

            • 3. Re: how to delete/create queue because InstanceAlreadyExists
              Adrian Brock Master

              import javax.management.*;

              ObjectName name = new ObjectName(<queue-mbean-here>);

              // Get the MBeanServer
              MBeanServer server = MBeanServerFactory.findMBeanServer(null).iterator().next();

              // Is the queue registered
              boolean registered = server.isRegistered(name);

              You can also use server.invoke(...) to create and
              destroy the queues.

              If you are not local to the VM, you can use the
              RMI or EJB adaptor.

              Regards,
              Adrian

              • 4. Re: how to delete/create queue because InstanceAlreadyExists
                garyg Novice

                So I'm using the RMIAdaptor since I'm not local to the VM. But I'm getting the following exceptions ...

                javax.naming.CommunicationException: Peek timed out. Root exception is java.io.InterruptedIOException: Peek timed out
                at java.net.PlainDatagramSocketImpl.peek(Native Method)
                at java.net.DatagramSocket.receive(DatagramSocket.java:349)
                at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:930)
                at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1017)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:447)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:440)
                at javax.naming.InitialContext.lookup(InitialContext.java:345)

                And here's my clients code ...
                ---

                String adaptorName = "jmx:" + props.getProperty("manager.name")
                + ":rmi";

                try {
                InitialContext ctx = new InitialContext();

                RMIAdaptor adaptor = (RMIAdaptor) ctx.lookup(adaptorName);

                ObjectName name = new ObjectName("jboss.system:service=MainDeployer");

                RemoteMBeanServer server = new RMIConnectorImpl(adaptor);

                boolean registered = server.isRegistered(name);

                if (registered) {
                server.invoke(name, "destroyQueue", new Object[] { server },
                new String[] {});
                }

                server.invoke(name, "createQueue", new Object[] { server },
                new String[] {});


                Any help much appreciated.

                • 5. Re: how to delete/create queue because InstanceAlreadyExists
                  Adrian Brock Master

                  You have a problem with your jndi.properties?

                  When you've fixed that your object names are wrong.

                  The isRegistered() should use the Queue's object name.

                  The create/destroy queue should be against the
                  DestinationManager.

                  Regards,
                  Adrian

                  • 6. Re: how to delete/create queue because InstanceAlreadyExists
                    garyg Novice

                    Still getting the exceptions which I've pasted at the end. I've also included the jndi.properties which I don't see anything wrong with.

                    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                    java.naming.provider.url=jnp://192.168.0.10:1099/
                    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
                    #jnp.socketFactory=org.jnp.interfaces.TimedSocketFactory
                    #jnp.timeout=0
                    #jnp.sotimeout=0

                    --- And here is the new code fixes ...

                    try {
                    InitialContext ctx = new InitialContext();

                    RMIAdaptor adaptor = (RMIAdaptor) ctx.lookup(adaptorName);

                    ObjectName name = new
                    ObjectName("jboss.mq:service=DestinationManager");

                    RemoteMBeanServer server = new RMIConnectorImpl(adaptor);

                    ObjectName queName = new ObjectName("queue/" +
                    props.getProperty("fielder.hostname"));

                    boolean registered = server.isRegistered(queName);

                    String[] sig = {"java.lang.String"};
                    Object[] arg = {props.getProperty("fielder.hostname")};

                    if (registered) {
                    log.info(Fielder.class, "already registered, destroying queue");
                    server.invoke(name, "destroyQueue", arg, sig);
                    }

                    log.info(Fielder.class, "creating queue");
                    server.invoke(name, "createQueue", arg, sig);

                    --- jboss output ---
                    javax.naming.CommunicationException: Peek timed out. Root exception is java.io.InterruptedIOException: Peek timed out
                    at java.net.PlainDatagramSocketImpl.peek(Native Method)
                    at java.net.DatagramSocket.receive(DatagramSocket.java:349)
                    at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:930)
                    at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1017)
                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:447)
                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:440)
                    at javax.naming.InitialContext.lookup(InitialContext.java:345)
                    at com.neuroquest.cais.clients.fielder.Fielder.createPTP(Unknown Source)
                    at com.neuroquest.cais.clients.fielder.Fielder.main(Unknown Source)


                    Any help much appreciated.