5 Replies Latest reply on Apr 21, 2006 4:39 AM by ragsta

    How to push data to JMX components?

    ragsta

      There is a way to use a method of a class that implements an MBean interface but not for that particular method?

      This is the case:

      I want to push data from a stateless session bean into a management component I've developed, so that I can see the total amount of a parameter passed to the slsb at the end of the day.

      The problem is that the management component should expose only readonly properties and no methods through the MBean interface, so I cannot use the usual invoke....

      any idea?
      bye



        • 1. Re: How to push data to JMX components?
          ragsta

          this is the solution i've found:

          my stateless session bean:

          public class CounterBean implements SessionBean {
          
           public static MovementsMgr myMBean=null;
          
           public void ejbCreate() throws CreateException {
           if (myMBean == null){
           myMBean= new com.alblab.management.MovementsMgr();
           MBeanServerLocator.locateJBoss().registerMBean(myMBean,new bjectName("xxx:name=movements"));
           System.out.println("MovementsMgrMBean registered");
           }
           }
          
           .
           .
           .
           // my Ejb remote business method
           public String putMoney(int amount) {
           myMBean.setInbound(amount); //my method on MovementsMgr not exposed in the MBean Interface
           .
           .
           }
          }


          MBean interface:
          public interface MovementsMgrMBean extends ServiceMBean{
           public int getInbound();
           .
           .
           .
          }


          MBean Implementation:

          public class MovementsMgr extends ServiceMBeanSupport implements MovementsMgrMBean {
          
           private int inbound;
           public MovementsMgr(){
           inbound=0;
           }
          
           .
           .
           .
          
           public int getInbound() {
           return inbound;
           }
          
           //not exposed in the MBean interface
           public void setInbound(int amount){
           inbound=inbound+amount;
           }
          }


          Is this a right way to do it?

          • 2. Re: How to push data to JMX components?
            dimitris

            There is an issue with the lifecycle with the mbean, i.e. how it gets destroyed/deregistered?

            My initial idea would be to have an mbean service deployed together with the ejb as an embedded .sar

            The mean would be a frond-end to a data object (pojo) holding the actual metrics. The mbean would register this pojo to the internal jndi, so the ejb can look it up and update it. You need to synchronize access to that pojo, as it will be accessed by many threads (there maybe a performance issue there).

            • 3. Re: How to push data to JMX components?
              ragsta

              I like the idea but I've a question about.
              Does it work in a clustered evironment?

              • 4. Re: How to push data to JMX components?
                dimitris

                Clustering has nothing to do with this, or I don't get you?

                • 5. Re: How to push data to JMX components?
                  ragsta

                  Ok, I follow your hints with only a difference:
                  I've two interfaces implemented by the same pojo, the MBean interface and an interface for internal use.
                  Next I've registered in the jndi this pojo using the Nonserializablefactory.
                  By this way I can cast it in the internal interface for business requirements and use it with the standard MBean interface for management requirements.

                  Tanks again.