9 Replies Latest reply on Mar 23, 2004 1:01 PM by alanc_yang

    from session bean to invoke mbean's method

    alanc_yang

      If I have to invoke from a session bean the mbean's method, how to do that, can people shed some lights?

      Thanks in advance.

      Alan

        • 1. Re: from session bean to invoke mbean's method
          starksm64

          Look up the MBeanServer via the MBeanServerFactory and invoke away.

          • 2. Re: from session bean to invoke mbean's method
            alanc_yang

            for instance, the MBean server illustrated in chap2, the JNDIMap example, how can a session bean find it. not sure what the agentId should be for MBeanServerFactory.findMBeanServer().

            ArrayList mbs = MBeanServerFactory.findMBeanServer("chap2.xmbean:service=JNDIMap");

            this doesn't seem to find JNDIMap MBean server.

            Please help!

            • 3. Re: from session bean to invoke mbean's method
              alanc_yang

              moving forward a bit. but still get the reflection exception on the following:

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

              // invoke it's XML command receiver
              Boolean ret = Boolean.TRUE;
              try {
              ObjectName lName = new ObjectName("chap2.xmbean:service=JNDIMap");

              String[] params = { xml };
              String[] signature = { "java.lang.String" };

              ret = (Boolean) lServer.invoke(lName, "onCommand", params, signature);

              ......

              and the MBean (JNDIMap) has the method:
              public Boolean onCommand(String xml)
              {
              log.info("onCommand =====>> xml = " + xml);
              return Boolean.TRUE;
              }

              wonder why onCommand method cannot be found?

              Thanks for your help!


              • 4. Re: from session bean to invoke mbean's method
                starksm64

                It can't be found because there is no such operation. The management interface is dicated by the JNDIMapMBean.java

                public interface JNDIMapMBean
                {
                 public String getJndiName();
                 public void setJndiName(String jndiName) throws NamingException;
                
                 public String[] getInitialValues();
                 public void setInitialValues(String[] keyValuePairs);
                
                 public void start() throws Exception;
                 public void stop() throws Exception;
                }
                


                This has a start/stop operations and a JndiName RW attribute and a InitialValues RW attribute. I don't know where you getting the onCommand from.



                • 5. Re: from session bean to invoke mbean's method
                  alanc_yang

                  it's from ClientInterface.java. what this interface is for?

                  package org.jboss.chap2.xmbean;

                  /**
                  * @author Scott.Stark@jboss.org
                  * @version $Revision: 1.1 $
                  */
                  public interface ClientInterface
                  {
                  public String[] getInitialValues();
                  public void setInitialValues(String[] keyValuePairs);
                  public Object get(Object key);
                  public void put(Object key, Object value);
                  public Boolean onCommand(String xml);
                  }

                  • 6. Re: from session bean to invoke mbean's method
                    starksm64

                    You tell me because you had to have added it as my version does not include such a method:

                    package org.jboss.chap2.xmbean;
                    
                    /**
                     * @author Scott.Stark@jboss.org
                     * @version $Revision: 1.1 $
                     */
                    public interface ClientInterface
                    {
                     public String[] getInitialValues();
                     public void setInitialValues(String[] keyValuePairs);
                     public Object get(Object key);
                     public void put(Object key, Object value);
                    }
                    


                    This interface is used as the remote rpc interface of the xmbean pojo as implemented by the InvokerInterceptor. If you add a method your going to have to add support for it.


                    • 7. Re: from session bean to invoke mbean's method
                      alanc_yang

                      i copied JNDIMapMBean.java as listed in the following to ~chap2/xmbean dir and rebuild/deploy:

                      package org.jboss.chap2.xmbean;

                      import javax.naming.NamingException;

                      /** An example MBean that implicitly implements the Service interface methods.
                      This is version 1 as shown in Listing 2.7.
                      */
                      public interface JNDIMapMBean
                      {
                      public String getJndiName();
                      public void setJndiName(String jndiName) throws NamingException;

                      public String[] getInitialValues();
                      public void setInitialValues(String[] keyValuePairs);

                      public void start() throws Exception;
                      public void stop() throws Exception;

                      public Boolean onCommand(String xml);
                      }

                      from running the test program, still not seeing onCommand listed as an operation, wonder why?

                      run-examplexmbean1:
                      [copy] Copying 1 file to R:\server\default\deploy
                      [java] JNDIMap Class: org.jboss.mx.modelmbean.XMBean
                      [java] JNDIMap Operations: 8
                      [java] + void start()
                      [java] + void stop()
                      [java] + void put(java.lang.Object chap2.xmbean:service=JNDIMap,java.lang.Object cha
                      p2.xmbean:service=JNDIMap)
                      [java] + java.lang.Object get(java.lang.Object chap2.xmbean:service=JNDIMap)
                      [java] + java.lang.String getJndiName()
                      [java] + void setJndiName(java.lang.String chap2.xmbean:service=JNDIMap)
                      [java] + [Ljava.lang.String; getInitialValues()
                      [java] + void setInitialValues([Ljava.lang.String; chap2.xmbean:service=JNDIMap)

                      • 8. Re: from session bean to invoke mbean's method
                        alanc_yang

                        what does it take to add an mbean method using chap2 xmbean example?

                        1) in JNDIMap.java file,

                        public class JNDIMap extends ServiceMBeanSupport
                        implements InvocationHandler, JNDIMapMBean
                        {
                        .....
                        public Boolean onCommand(String xml)
                        {
                        log.info("onCommand =====>> xml = " + xml);
                        return Boolean.TRUE;
                        }

                        2) the JNDIMapMBean.java

                        public interface JNDIMapMBean
                        {
                        public String getJndiName();
                        public void setJndiName(String jndiName) throws NamingException;

                        public String[] getInitialValues();
                        public void setInitialValues(String[] keyValuePairs);

                        public void start() throws Exception;
                        public void stop() throws Exception;

                        public Boolean onCommand(String xml);
                        }

                        3) the jndimap-xmbean1.xml file

                        <!-- Operations -->

                        The onCommand method call
                        onCommand


                        when deploy the chap2-ex1xmbean1.sar file, it has the following exception:

                        org.jboss.deployment.DeploymentException: create operation failed for package file:/R:/ser
                        ver/default/deploy/chap2-ex1xmbean1.sar; - nested throwable: (org.jboss.deployment.Deploym
                        entException: - nested throwable: (ReflectionException: null
                        Cause: javax.management.IntrospectionException: no method found for operation: onCommand))

                        at org.jboss.deployment.SARDeployer.create(SARDeployer.java:202)
                        at org.jboss.deployment.MainDeployer.create(MainDeployer.java:786)
                        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:641)
                        at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:605)

                        wonder what's missing?
                        Thanks in advance!

                        • 9. Re: from session bean to invoke mbean's method
                          alanc_yang

                          ok, based on my onCommand method, it should have the following definitions:


                          The onCommand method call
                          onCommand

                          The XML command
                          xml
                          java.lang.String

                          <return-type>java.lang.Boolean</return-type>


                          no problem!