3 Replies Latest reply on Jan 6, 2004 5:52 PM by andrewboyd

    Asking Mbean usage.

    scttu

      Hello,

      I am a JMX newbie, i have successfully write some standard mbean follows the example in the Jboss docs. I plan to do some serious component using this model, therefore i post this message to verify with you gurus and hope to get some comments and feedbacks.

      My objective of using mbean is to create a caching layer at the server side where some data retrieve through session bean will be cached at the mbean. The client (web-client, java client) will access the mbean to retrieve data, only if the data is not available in the cache it will invoke the session bean(which will retrieve data from database). So rougly the flow would be

      client -> mbean -> session bean -> database.

      What i currently did were;

      1. Create a mbean that's serializable and bind the mbean to a jndi server using the following code. The mbean have some static Map for caching.

      private void bind(Context ctx, String name, Object val)throws NamingException{

      Name n;
      for (n = ctx.getNameParser("").parse(name); n.size() > 1; n = n.getSuffix(1)){
      String ctxName = n.get(0);
      try{
      ctx = (Context) ctx.lookup(ctxName);
      }catch (NameNotFoundException e){
      ctx = ctx.createSubcontext(ctxName);
      }
      }
      ctx.bind(n.get(0), val);
      }

      2. invoke the mbean through jboss RMIConnector, using the RMIAdapter bind at the
      Following jndi name "jmx/rmi/RMIAdaptor". Then I will invoke the mbean using the
      RemoteMBeanServer instance.

      RMIAdaptor adaptor = (RMIAdaptor)context.lookup(jndiName);
      RemoteMBeanServer server = new RMIConnectorImpl(adaptor);


      My questions are:

      1. Is it appropriate to implement my objective using mbean or there is better altenatives?
      2. I notice in the example there is NonSerializable binding. What is the different in binding
      A serializable or non serializable mbean? If I require to access the mbean remotely which is more appropriate?
      3. If I had a serializable mbean, does that meant each time I invoke the mbean I will get a copy of the mbean or a 'proxy' of the mbean? From my testing I found that whenver I invoke the mbean through the connector, the changes is reflect at the server.
      4. Does the mbean only instantiated once in the server JVM, meaning all the client will access the same mbean instance? If no, can I create a singleton mbean?

      5. what's the different between RMIAdaptor and RMIConnector?

      Thanks.

      Any comments and suggestions are very much appreciated.


      Regards,
      Stephen

        • 1. Re: Asking Mbean usage.
          rameshs

          Dear Stephen,

          You need not bind your MBean to a jndi server. It is enough if you register your MBeans with the MBeanServer of JBoss. You can then invoke operations from your client on the MBeans through the RMI Connector.

          Regards,
          Ramesh.

          • 2. Re: Asking Mbean usage.
            scttu

            Hi Ramesh,

            Do you have any code snippet on how to register mbean to the mbean server? or whereabout i can find this information?

            Thanks

            Stephen

            • 3. Re: Asking Mbean usage.
              andrewboyd

              www.google.com is your friend ;-) ibm developer works is a good
              place to look for tutorials. and of course you could get juha's JMX book.

              but until then:

              import javax.management.ObjectName;
              
              // registering InventoryManager MBean
              
              InventoryManager im = new InventoryManager("Parrot");
              
              try
              {
               mbs.registerMBean(im , new ObjectName("MyServer:type=inventory"));
              }
              catch(Exception e)
              {
               e.printStackTrace();
              }
              
              // registering Cart MBean
              
              Cart crt = new Cart();
              
              try
              {
               mbs.registerMBean ( crt , new ObjectName("ShoppingCart:type=MBean") );
              }
              catch(Exception e)
              {
               e.printStackTrace();
              }
              


              Andrew