12 Replies Latest reply on Jan 12, 2007 8:10 AM by Daniel Destro do Carmo

    Listing all EJBs through JMX

    Daniel Destro do Carmo Newbie

      Hi,

      I want to list the name (or the references) for all EJBs deploy in the container instance (jboss4.0.3-sp1) through JMX.

      The jmx-console have something similiar, but I tried to achieve only the information I need, reading the code, but it is impossible to get it.
      ( http://jboss.org/wiki/Wiki.jsp?page=DisplayTheJDNITreeWithTheJMXConsole )

      Can someone help me to find any documentation about it ou sample code?

      Thanks

        • 1. Re: Listing all EJBs through JMX
          Dimitris Andreadis Master

          You can navigate the jsr77 tree using a simple jmx query:

          *:j2eeType=EjbModule,*

          Try JBOSS_HOME/bin/twiddle jsr77 on the latest jboss or look how it is implemented in the source code.



          • 2. Re: Listing all EJBs through JMX
            Daniel Destro do Carmo Newbie

            Hi dimitris,

            I tried to use twiddle according to the examples (http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch2.chapter.html), but I only got error messages, such as:

            C:\jboss-4.0.3SP1\bin>twiddle query 'jboss:service=JNDIView'
            13:48:38,772 ERROR [Twiddle] Command failure
            org.jboss.console.twiddle.command.CommandException: Unused argument: JNDIView'
             at org.jboss.console.twiddle.command.QueryCommand.processArguments(Query
            Command.java:104)
             at org.jboss.console.twiddle.command.QueryCommand.execute(QueryCommand.j
            ava:119)
             at org.jboss.console.twiddle.Twiddle.main(Twiddle.java:290)
            


            or even

            C:\jboss-4.0.3SP1\bin>twiddle query '*:j2eeType=EjbModule,*'
            13:50:26,810 ERROR [Twiddle] Command failure
            org.jboss.console.twiddle.command.CommandException: Unused argument: EjbModule
             at org.jboss.console.twiddle.command.QueryCommand.processArguments(Query
            Command.java:104)
             at org.jboss.console.twiddle.command.QueryCommand.execute(QueryCommand.j
            ava:119)
             at org.jboss.console.twiddle.Twiddle.main(Twiddle.java:290)


            I am using JBoss-4.0.3-SP1 and Java 5.

            • 3. Re: Listing all EJBs through JMX
              Dimitris Andreadis Master

              Use double quotes.

              twiddle query "*:j2eeType=WebModule,*"

              • 4. Re: Listing all EJBs through JMX
                Daniel Destro do Carmo Newbie

                Hahahaah... different result. But still not satisfied.

                C:\jboss-4.0.3SP1\bin>twiddle query "*:j2eeType=EjbModule,*"
                17:08:19,307 ERROR [Twiddle] Command failure
                org.jboss.console.twiddle.command.CommandException: No MBean matches for query:
                *:j2eeType=EjbModule,*
                 at org.jboss.console.twiddle.command.MBeanServerCommand.queryMBeans(MBea
                nServerCommand.java:60)
                 at org.jboss.console.twiddle.command.QueryCommand.execute(QueryCommand.j
                ava:126)
                 at org.jboss.console.twiddle.Twiddle.main(Twiddle.java:290)


                I am reading the source code and I am gonna try it out.

                • 5. Re: Listing all EJBs through JMX
                  Daniel Destro do Carmo Newbie

                  Ok, better results now:

                  C:\jboss-4.0.3SP1\bin>twiddle query "jboss.j2ee:service=EjbModule,*"
                  jboss.j2ee:service=EjbModule,module=gpa-ejb.jar
                  jboss.j2ee:service=EjbModule,module=mdc-idf.jar
                  jboss.j2ee:service=EjbModule,module=mdc.jar


                  I´ll do some testing with it and try to list the EJBModules´s EJB list.

                  By the way, EJB (CAPITALS) does not work, the correct is "Ejb"

                  • 6. Re: Listing all EJBs through JMX
                    Peter Johnson Master

                    The listing you got was of all the JAR files containing EJBs. If you want all of the EJBs themselves, try:

                    twiddle query "*:j2eeType=StatefulSessionBean,*"

                    and

                    twiddle query "*:j2eeType=StatelessSessionBean,*"

                    Usually, it is easiest to use the jmx-console to view the mbeans, and from there decide what to pass to twiddle (or to use in your code when accessing jmx via the api).

                    • 7. Re: Listing all EJBs through JMX
                      Daniel Destro do Carmo Newbie

                       

                      "PeterJ" wrote:
                      twiddle query "*:j2eeType=StatefulSessionBean,*"
                      and
                      twiddle query "*:j2eeType=StatelessSessionBean,*"


                      Does not work at all for me with twiddle.

                      • 8. Re: Listing all EJBs through JMX
                        Daniel Destro do Carmo Newbie

                        Good news!

                        Ok, this works:

                        String name = "jboss.management.local:*,j2eeType=StatelessSessionBean";
                        server = (MBeanServer) MBeanServerLocator.locateJBoss();
                        Set matches = server.queryMBeans(new ObjectName(name), null);
                        ServerObjectInstance[] names = (ServerObjectInstance[]) matches.toArray( new ServerObjectInstance[matches.size()] );
                        for( int i=0; i< names.length; i++ ) {
                         out.println(names.getObjectName()+" <br>");
                         }


                        And outputs:

                        jboss.management.local:name=ejb/MyCoolEjb,J2EEServer=Local,EJBModule=cool.jar,J2EEApplication=null,j2eeType=StatelessSessionBean
                        jboss.management.local:name=ejb/AnotherCoolEjb,J2EEServer=Local,EJBModule=still-cool.jar,J2EEApplication=null,j2eeType=StatelessSessionBean
                        jboss.management.local:name=ejb/EjbOrNotEjb,J2EEServer=Local,EJBModule=myapp.jar,J2EEApplication=myapp.ear,j2eeType=StatelessSessionBean


                        Very close now.

                        Here I have the JNDI names for lookup. But what I really need is the Bean, and if possible Local and Remote classes/interfaces names.

                        I know it is possible throgh jmx-console. Just need to get things clear. Any help?

                        • 9. Re: Listing all EJBs through JMX
                          Daniel Destro do Carmo Newbie

                          I want to see what info I have inside the bean where "j2eeType=EJBModule", link in the link providade at jmx-console

                          • 10. Re: Listing all EJBs through JMX
                            Peter Johnson Master

                            Look at the methods on MBeanServer.

                            Also google "jboss jmx tutorial".

                            • 11. Re: Listing all EJBs through JMX
                              Daniel Destro do Carmo Newbie

                               

                              "PeterJ" wrote:
                              Also google "jboss jmx tutorial".


                              As if existed any.

                              • 12. Re: Listing all EJBs through JMX
                                Daniel Destro do Carmo Newbie

                                Finally I achieved what I wanted.

                                The code bellow shows all the "ejb-jar.xml" deployed in the container.

                                package test;
                                
                                import java.lang.reflect.Method;
                                import java.util.*;
                                import javax.management.*;
                                import org.jboss.jmx.adaptor.control.*;
                                import org.jboss.mx.server.*;
                                import org.jboss.mx.util.*;
                                
                                public class Test {
                                 public void getDeploymentDescriptors() {
                                 String query = "jboss.management.local:*,j2eeType=EJBModule";
                                 MBeanServer server = (MBeanServer) MBeanServerLocator.locateJBoss();
                                 Set matches = server.queryMBeans( new ObjectName( query ), null );
                                 Iterator it = matches.iterator();
                                 while( it.hasNext() ) {
                                 ObjectInstance soi = (ServerObjectInstance) it.next();
                                 ObjectName objName = soi.getObjectName();
                                
                                 String objectNameString = objName.toString();
                                 MBeanInfo mbeanInfo = server.getMBeanInfo(objName);
                                 MBeanAttributeInfo[] attributeInfo = mbeanInfo.getAttributes();
                                
                                 for( int a=0; a < attributeInfo.length; a++ ) {
                                 MBeanAttributeInfo attrInfo = attributeInfo[a];
                                 if( !"deploymentDescriptor".equals( attrInfo.getName() ) ) {
                                 continue;
                                 }
                                 AttrResultInfo attrResult = Server.getMBeanAttributeResultInfo(objectNameString, attrInfo);
                                 String attrValue = attrResult.getAsText();
                                
                                 //prints out the "ejb-jar.xml"
                                 System.out.println( attrValue );
                                 }
                                 }
                                 }
                                }