2 Replies Latest reply on Oct 19, 2002 12:47 PM by Jens Breitenstein

    queryObject (beginner ?) question

    Jens Breitenstein Newbie

      Hi

      I am trying to query all mbeans existing in jboss. This fails with exception (see stack trace below) and the message 'wrong number of arguments'.
      The call m.queryNames(objQueryName, null) fails. I tried different Object names with no success. I found a sample but here queryNames only used one parameter but jBoss 3.0.0 requires two parameters so I simply added 'null' ?

      I pasted the code and exception below.

      Thanks in advance for your answer.

      EXCEPTION
      -----------------------------
      java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
      javax.transaction.TransactionRolledbackException: wrong number of arguments; nested exception is:
      java.lang.IllegalArgumentException: wrong number of arguments
      javax.transaction.TransactionRolledbackException: wrong number of arguments; nested exception is:
      java.lang.IllegalArgumentException: wrong number of arguments
      java.lang.IllegalArgumentException: wrong number of arguments
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
      at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
      at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:128)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:108)
      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:73)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:76)
      at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:111)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
      at $Proxy1.queryNames(Unknown Source)
      at biz.toc.darja.management.server.link.JBossServerLink.main(JBossServerLink.java:133)



      CODE
      --------------------------------
      Hashtable ht = new Hashtable();
      ht.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      ht.put("java.naming.provider.url", "jnp://localhost:1099");
      ht.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");


      try {
      System.setSecurityManager(new RMISecurityManager());

      InitialContext ctx = new InitialContext(ht);
      Object path = ctx.lookup("ejb/mgmt/MEJB");

      ManagementHome mh = (ManagementHome) PortableRemoteObject.narrow(path, ManagementHome.class);
      Management m = mh.create();

      String jBossDefaultDomain = m.getDefaultDomain();
      System.out.println(jBossDefaultDomain);
      System.out.println(m.getMBeanCount());
      ObjectName objQueryName = new ObjectName(jBossDefaultDomain+":j2eeType=EJBObject,*");
      Set nameSet = m.queryNames(objQueryName,null);

      Iterator nameIterator = nameSet.iterator();
      while (nameIterator.hasNext()) {
      ObjectName name = (ObjectName) nameIterator.next();
      System.out.println(name);
      }
      } catch (Exception e) {
      e.printStackTrace();
      }

        • 1. Re: queryObject (beginner ?) question
          Greg Turner Apprentice

          It appears you are using an EJB to query the MBeanServer for MBeans. That does not seem like a good way to do it. Why not do it directly. That is, ask the MBeanServer directly?

          import java.util.*;
          import javax.management.*;
          import javax.naming.*;
          import org.jboss.jmx.adaptor.rmi.*;
          import org.jboss.jmx.connector.*;
          import org.jboss.jmx.connector.rmi.RMIConnectorImpl;


          public class Client {

          public static void main (String[] args) throws Exception {
          try {
          // Set up jndi properties
          Properties props = new Properties();
          props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
          props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
          props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
          InitialContext ctx = new InitialContext(props);
          System.out.println ("Got context");

          // Retrieve the RMI adaptor
          Object obj = ctx.lookup("jmx:<machine name here>:rmi");
          System.out.println ("Got RMI Adapter");
          ctx.close();

          // Wrap it in a connector
          RemoteMBeanServer server = new RMIConnectorImpl((RMIAdaptor)obj);

          // Print the EJB count
          System.out.println(server.queryMBeans(new ObjectName("jboss.j2ee:service=EJB,*"), null).size());
          }
          catch (Exception ex) {
          ex.printStackTrace();
          }
          }
          }

          • 2. Re: queryObject (beginner ?) question
            Jens Breitenstein Newbie

            Now it works ! Many thanks for your immediate help.

            Jens

            Unfortunately I do not understand why the first approach did not work. I believe there may be a problem if the sun jmx jar files are additionally reachable in the classpath. I will check this out...