2 Replies Latest reply on May 3, 2008 6:45 PM by redcar

    MBean deployment - EJB3 and call

    redcar

      Hallo,

      I try to deploy a MBean with EJB3 annotation on the server and call it from a sessionBean. The MBean looks like:

      package trail.jmx;
      
      import org.jboss.annotation.ejb.Service;
      import org.jboss.annotation.ejb.Management;
      
      @Service (objectName="trail:service=calculator")
      @Management(Calculator.class)
      public class CalculatorMBean implements Calculator {
      
       public double calculate (int start, int end, double saving) {
       double tmp = Math.pow(1. + growthrate / 12., 12. * (end - start) + 1);
       return saving * 12. * (tmp - 1) / growthrate;
       }
      ....
      


      In My SessionBean I want to call it with:

       private Object callXMB_Calculator(String operationName, Object[] params)
       {
       Object result = null;
      
       try
       {
       MBeanServer mbs = (MBeanServer) MBeanServerFactory.findMBeanServer(null).iterator().next();
       ObjectName oName = new ObjectName("jboss.j2ee:jar=CalcMBean.jar,name=CalculatorMBean,service=EJB3");
      
       String[] signature = null;
       if (params != null)
       {
       signature = new String[params.length];
      
       for (int i = 0; i < params.length; ++i)
       {
       signature = params.getClass().getName();
       }
       }
      
       result = mbs.invoke(oName, operationName, params, signature);
      


      I call the function like this:

       callXMB_Calculator("calculate", new Object[]{1,2,4d});
      


      But when I call the service-Method, I get a ReflectionException
      Caused by: java.lang.IllegalArgumentException: Unable to find operation calculate(java.lang.Integer,java.lang.Integer,java.lang.Double)

      When the server ist starting, I get the message:
      2008-05-02 09:30:35,281 INFO [org.jboss.ejb3.JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=CalcMBean.jar,name=CalculatorMBean,service=EJB3 with dependencies:
      2008-05-02 09:30:35,468 INFO [org.jboss.ejb3.EJBContainer] STARTED EJB: trail.jmx.CalculatorMBean ejbName: CalculatorMBean
      2008-05-02 09:30:35,531 INFO [STDOUT] Calculator - Creating
      


      To deploy the service, I have only copied the .jar file into the deploy directory. It contains only the .class files.
      With the use of 'old' XMBean' I have no problem, but I would prefere the EJB3 style. What can I do?

      Thank you,
      Werner Hofmann


        • 1. Re: MBean deployment - EJB3 and call
          jaikiran

          Does changing the method to

          private Object callXMB_Calculator(String operationName, Object[] params, String[] signature)
           {
           Object result = null;
          
           try
           {
           MBeanServer mbs = (MBeanServer) MBeanServerFactory.findMBeanServer(null).iterator().next();
           ObjectName oName = new ObjectName("jboss.j2ee:jar=CalcMBean.jar,name=CalculatorMBean,service=EJB3");
          
          
           }
          
           result = mbs.invoke(oName, operationName, params, signature);
          
           }


          and also changing the code, for invoking, to:

          callXMB_Calculator("calculate", new Object[]{1,2,4d},new String[] {"int","int","double"});


          work?

          • 2. Re: MBean deployment - EJB3 and call
            redcar

            I know what you are thinking: the Objecttype of the parameters in the service is int and not java.lang.Integer.

            I have changed the code inside the Service to java.lang.Integer and so on. And I have used your type of service-call.

            But I allways get the ReflectionException. The parameter type now equals. I think this is not the error anymore.

            A XMBean I have to install into a sar directory. The ejb3-Service I have installed as .jar file inside a normal folder in the deploy directory. Can this be the error?