8 Replies Latest reply: Jun 23, 2010 8:57 AM by 687626 RSS

    Invoke method to pause JMSQueue consumption using an MBean

    780508
      Hi All,
      I want to try pausing the consumption of the queue using an MBeanAgent class, which I am unable to do.I was successful in getting the MBeanServerConnection instance but when I am trying to invoke the method to pause the consumption of my queue I am getting an InstanceNotFound exception.
      Any assistance on this would be of great help.

      Thanks in Advance,
      Sri.
        • 1. Re: Invoke method to pause JMSQueue consumption using an MBean
          Kalyan Pasupuleti-Oracle
          HI Sri,

          Can you put the error here so that I can help you on this issue.

          Regards,
          Kal.
          • 2. Re: Invoke method to pause JMSQueue consumption using an MBean
            780508
            Hi Kal,
            This the exception:
            myserver is my admin server,GeneralQueue is the queue for which i want to pause the consumption and EwpJmsServer is my JMS server, I am not sure what has to be given in the
            Name,here I have given 'interop-jms' is the name of the jms-interop-module.
            If my approach is wrong please let me know any other approach, I have the connection object with me.
            javax.management.InstanceNotFoundException: com.bea:ServerRuntime=myserver,Name=interop-jms!GeneralQueue,Type=JMSDestinationRuntime,JMSServerRuntime=EwpJmsServer
            javax.management.InstanceNotFoundException: com.bea:ServerRuntime=myserver,Name=interop-jms!GeneralQueue,Type=JMSDestinationRuntime,JMSServerRuntime=EwpJmsServer
                 at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:211)
                 at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:224)
                 at javax.management.remote.rmi.RMIConnectionImpl_922_WLStub.getObjectInstance(Unknown Source)
                 at weblogic.management.remote.common.RMIConnectionWrapper$6.run(ClientProviderBase.java:409)
                 at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
                 at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
                 at weblogic.security.Security.runAs(Security.java:61)
                 at weblogic.management.remote.common.RMIConnectionWrapper.getObjectInstance(ClientProviderBase.java:407)
                 at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.getObjectInstance(RMIConnector.java:763)
                 at MBeanAgent.main(MBeanAgent.java:70)
            Caused by: javax.management.InstanceNotFoundException: com.bea:ServerRuntime=myserver,Name=interop-jms!GeneralQueue,Type=JMSDestinationRuntime,JMSServerRuntime=EwpJmsServer
                 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1010)
                 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getObjectInstance(DefaultMBeanServerInterceptor.java:419)
                 at com.sun.jmx.mbeanserver.JmxMBeanServer.getObjectInstance(JmxMBeanServer.java:545)
                 at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.getObjectInstance(WLSMBeanServerInterceptorBase.java:90)
                 at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.getObjectInstance(WLSMBeanServerInterceptorBase.java:90)
                 at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.getObjectInstance(WLSMBeanServerInterceptorBase.java:90)
                 at weblogic.management.jmx.mbeanserver.WLSMBeanServer.getObjectInstance(WLSMBeanServer.java:222)
                 at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1405)
                 at javax.management.remote.rmi.RMIConnectionImpl.access$100(RMIConnectionImpl.java:81)
                 at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1245)
                 at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1348)
                 at javax.management.remote.rmi.RMIConnectionImpl.getObjectInstance(RMIConnectionImpl.java:460)
                 at javax.management.remote.rmi.RMIConnectionImpl_WLSkel.invoke(Unknown Source)
                 at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:550)
                 at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:440)
                 at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
                 at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
                 at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:436)
                 at weblogic.rmi.internal.BasicServerRef.access$300(BasicServerRef.java:58)
                 at weblogic.rmi.internal.BasicServerRef$BasicExecuteRequest.run(BasicServerRef.java:975)
                 at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
                 at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
            I am also giving the code snippet i used to get the ObjectName and invoke method i called on the connection.

            private static String wlSrvNm = "myserver";
                 private static String jmsResTag = "interop-jms";
                 private static String jmsQNm = "GeneralQueue";
                 private static String jmsSrvNm = "EwpJmsServer";

            //Getting the object name
            ObjectName qBeanObjNm = new ObjectName("com.bea:ServerRuntime="
                           + wlSrvNm + "," + "Name=" + jmsResTag + "!" + jmsQNm + ","
                           + "Type=JMSDestinationRuntime,JMSServerRuntime=" + jmsSrvNm);
                           System.out.println("Using ObjNm=[" + qBeanObjNm + "]");

            // Pause JMS msg consumption on 'jmsQNm' destination
            connection.invoke(qBeanObjNm , "pauseConsumption", null, null);
            Thanks,
            Sri.
            • 3. Re: Invoke method to pause JMSQueue consumption using an MBean
              Kalyan Pasupuleti-Oracle
              Hi Sri,

              here I have given 'interop-jms' is the name of the jms-interop-module.

              javax.management.InstanceNotFoundException: com.bea:ServerRuntime=myserver,Name=interop-jms!GeneralQueue,Type=JMSDestinationRuntime,JMSServerRuntime=EwpJmsServer


              is this Jms-interop-module is your JMS module name or what

              here we need to keep Module name of the JMS.

              Where it consist Queue / Topic and Connection Factories.....


              if you check teh Name=interop-jms!GernalQueue it is looking for the queue from your JMS Module

              Keep your JMS module name there.

              Hope this will help you to resolve the issue.

              Regards,
              Kal.
              • 4. Re: Invoke method to pause JMSQueue consumption using an MBean
                780508
                Hi Kal,
                Yes interop-jms is my JMS Module name.
                As you have rightly said my connection factory,topic and queue are within this interop-jms.
                So the parameters I passed might be right I guess, but I cant figure out why I am getting this exception.

                Thanks,
                Sri.
                • 5. Re: Invoke method to pause JMSQueue consumption using an MBean
                  Kalyan Pasupuleti-Oracle
                  HI Sri,


                  Ok Can you give me the MBean Class details so that I provide actual parameter to pass with in it.

                  Regards,
                  Kal.
                  • 6. Re: Invoke method to pause JMSQueue consumption using an MBean
                    780508
                    Hi Kal,

                    import java.io.IOException;
                    import java.net.InetAddress;
                    import java.net.MalformedURLException;
                    import java.util.Hashtable;
                    import java.util.Set;
                    import javax.management.*;
                    import javax.management.remote.*;

                    import javax.management.InstanceNotFoundException;
                    import javax.management.IntrospectionException;
                    import javax.management.MBeanInfo;
                    import javax.management.MBeanOperationInfo;
                    import javax.management.MBeanParameterInfo;
                    import javax.management.MBeanServerConnection;
                    import javax.management.ObjectName;
                    import javax.management.ReflectionException;
                    import javax.management.remote.JMXConnector;
                    import javax.management.remote.JMXConnectorFactory;
                    import javax.management.remote.JMXServiceURL;
                    import javax.naming.Context;


                    public class MBeanAgent {
                         // Defines the JNDI context factory.
                         public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";
                         private static MBeanServerConnection connection = null;
                         private static JMXConnector connector = null;
                         private static ObjectName service = null;
                         private static String wlSrvNm = "myserver";
                         private static String jmsResTag = "interop-jms";
                         private static String jmsQNm = "GeneralQueue";
                         private static String jmsSrvNm = "EwpJmsServer";

                         /**
                         * @param args
                         */
                         public static void main(String[] args) {
                              // Some info here on how to program with JMX in WL:
                              // http://download.oracle.com/docs/cd/E13222_01/wls/docs90/jmx/accessWLS.html#1074616
                              try {
                                   String hostname = "localhost"; // host to the Q to b manipulated
                                   String portString = "7001"; // port to be connected on
                                   String username = "weblogic"; // uid to log in to weblogic
                                   String password = "password";
                    String hostnameex=InetAddress.getLocalHost().getHostName();
                                   //String portno=InetAddress.getLocalHost().ge
                    service = new ObjectName(
                                             "com.bea:Name=RuntimeService,"
                                                       + "Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");

                                   initConnection(hostname, portString, username, password);

                                   // http://java.sun.com/j2se/1.5.0/docs/api/javax/management/ObjectName.html
                                   ObjectName qBeanObjNm = new ObjectName("com.bea:ServerRuntime="
                                   + wlSrvNm + "," + "Name=" + jmsResTag + "!" + jmsQNm + ","
                                   + "Type=JMSDestinationRuntime,JMSServerRuntime=" + jmsSrvNm);
                                   System.out.println("Using ObjNm=[" + qBeanObjNm + "]");
                                   System.out.println("Default Domain---->"+connection.getDefaultDomain());


                                   //ObjectName qBeanObjNm = new ObjectName("com.bea:Name=Core_Q1_Domain,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
                                   //MBeanHome home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
                                   //Set queueNames = bSvr.queryNames(new ObjectName(weblogicDomain+":Type=JMSQueue,Name="+jmsQueue+",*"),query);
                                   System.out.println("Using ObjNm=[" + qBeanObjNm + "]");
                                   if ("pauseConsumption".equalsIgnoreCase("pauseConsumption")) {
                                        // Pause JMS msg consumption on 'jmsQNm' destination
                                   int mbeanCnt=connection.getMBeanCount();
                                        connection.invoke(qBeanObjNm, "pauseConsumption", null, null);
                                        System.out.println("JMS Message Consumption PAUSEd on ["
                                                  + qBeanObjNm.getCanonicalName() + "]");
                                   } else if ("resumeConsumption".equalsIgnoreCase(args[4])) {
                                        // Resume JMS msg consumption on 'jmsQNm' destination
                                        connection.invoke(qBeanObjNm, "resumeConsumption", null, null);
                                        System.out.println("JMS Message Consumption RESUMEd on ["
                                                  + qBeanObjNm.getCanonicalName() + "]");
                                   } else if ("pauseInsertion".equalsIgnoreCase(args[4])) {
                                        // Pause JMS msg consumption on 'jmsQNm' destination
                                        connection.invoke(qBeanObjNm, "pauseInsertion", null, null);
                                        System.out.println("JMS Message Insertion PAUSEd on ["
                                                  + qBeanObjNm.getCanonicalName() + "]");
                                   } else if ("dbg".equalsIgnoreCase(args[4])) {
                                        System.out.println("MBeanSrv.bean-count="
                                                  + connection.getMBeanCount());
                                        System.out.println("MBeanSrv.cls="
                                                  + connection.getClass().getName());
                                        dumpMBeanOperations(qBeanObjNm);
                                        // printNameAndState();
                                   }
                              } catch (Exception e) {
                                   System.err.println("FAIL! " + e);
                                   e.printStackTrace();
                              } /*finally {
                                   try {
                                        connector.close();
                                   } catch (IOException e) {
                                        System.err.println("FINAL Connector.close() FAIL! " + e);
                                        e.printStackTrace();
                                   }
                              }*/
                         }

                         /*
                         * Initialize connection to the Domain Runtime MBean Server.
                         */
                         public static void initConnection(String hostname, String portString,
                                   String username, String password) throws IOException,
                                   MalformedURLException {

                              String protocol = "t3";
                              Integer portInteger = Integer.valueOf(portString);
                              int port = portInteger.intValue();
                              String jndiroot = "/jndi/";
                              String mserver = "weblogic.management.mbeanservers.runtime";

                              JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port,
                                        jndiroot + mserver);

                              Hashtable<String, String> h = new Hashtable<String, String>();
                              h.put(Context.SECURITY_PRINCIPAL, username);
                              h.put(Context.SECURITY_CREDENTIALS, password);
                              h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
                                        "weblogic.management.remote");
                              connector = JMXConnectorFactory.connect(serviceURL, h);
                              connection = connector.getMBeanServerConnection();
                         }

                         private static void dumpMBeanOperations(ObjectName qBeanObjNm)
                                   throws InstanceNotFoundException, IntrospectionException,
                                   ReflectionException, IOException {
                              MBeanInfo beanInfo = connection.getMBeanInfo(qBeanObjNm);
                              MBeanOperationInfo[] ops = beanInfo.getOperations();
                              System.out.println("Listing <" + ops.length + "> operations.");
                              for (MBeanOperationInfo op : ops) {
                                   MBeanParameterInfo[] parmInfos = op.getSignature();
                                   System.out.println("Operation.nm=" + op.getName());
                                   System.out.println("\t .dsc=" + op.getDescription());
                                   System.out.println("\t .Parm=");
                                   for (MBeanParameterInfo parmInfo : parmInfos) {
                                        System.out.println("\t\t.nm=" + parmInfo.getName());
                                        System.out.println("\t\t.typ=" + parmInfo.getType());
                                        System.out.println("\t\t.dsc=" + parmInfo.getDescription());
                                   }
                                   System.out.println("\t .ret=" + op.getReturnType());
                              }
                         }

                    }

                    This is the class, it goes into the first if block of the main method.
                    connection.invoke(qBeanObjNm, "pauseConsumption", null, null);//At this point exception occurs.

                    Thanks,
                    Sri.
                    • 7. Re: Invoke method to pause JMSQueue consumption using an MBean
                      Kalyan Pasupuleti-Oracle
                      Hi Sri,


                      I think we can figure out this issue with WLST script.


                      Here is a sample script

                      1) start a server in an empty dir
                      2) java weblogic.WLST .. connect(..)
                      3) edit()
                      4) startEdit()
                      5) deploy("myLibapp","./libApp.ear", serverName,libraryModule="true")
                      This should just install and not activate because the edit lock is open.
                      6) Now go to serverRuntime()
                      check for invoke method


                      just try this and let me know I think every thing on code side is fine can you give me invoke implementation code too to check the issue as


                      when I saw the doc it give details about the invoke method like this.

                      ===

                      invoke

                      Object invoke(ObjectName name,
                      String operationName,
                      Object[] params,
                      String[] signature)
                      throws InstanceNotFoundException,
                      MBeanException,
                      ReflectionException,
                      IOException

                      Invokes an operation on an MBean.

                      Parameters:
                      name - The object name of the MBean on which the method is to be invoked.
                      operationName - The name of the operation to be invoked.
                      params - An array containing the parameters to be set when the operation is invoked
                      signature - An array containing the signature of the operation. The class objects will be loaded using the same class loader as the one used for loading the MBean on which the operation was invoked.
                      Returns:
                      The object returned by the operation, which represents the result of invoking the operation on the MBean specified.
                      Throws:
                      InstanceNotFoundException - The MBean specified is not registered in the MBean server.
                      MBeanException - Wraps an exception thrown by the MBean's invoked method.
                      ReflectionException - Wraps a java.lang.Exception thrown while trying to invoke the method.
                      IOException - A communication problem occurred when talking to the MBean server.

                      ===

                      Regards,
                      Kal.
                      • 8. Re: Invoke method to pause JMSQueue consumption using an MBean
                        687626
                        Hi Sri,

                        Can you check JMS Servers --> Monitoring --> Active Destinations and see under what name is this queue registered ( Name Column). This I think will give the right name of the queue including the right name for the interop module.

                        Regards,
                        Atheek