Announcement Announcement Module
Collapse
No announcement yet.
JMXExporter for Dynamic Beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JMXExporter for Dynamic Beans

    Friends ..

    I have some configurations which has been configured in Database,
    base on the configuration my programe is instantiating 5 processor objects,(Thats why i called those objects as Dynamic bean)and i have to monitor(start and stop ) some methods using jmx client remortly(using RMI)
    If so how can i export those beans(5 processor)through org.springframework.jmx.export.MBeanExporter, Please help me out.

    Advance thanks.

    Cheers
    Dominic Soundranayagam

  • #2
    any responses ?

    Comment


    • #3
      after all round of debug i have written my custom exporter as follows

      import javax.management.modelmbean.ModelMBean;
      import javax.management.modelmbean.ModelMBeanInfo;


      import org.springframework.jmx.export.MBeanExporter;
      import org.springframework.jmx.export.SpringModelMBean;
      import org.springframework.jmx.export.assembler.MBeanInfo Assembler;
      import org.springframework.jmx.export.assembler.SimpleRef lectiveMBeanInfoAssembler;
      import org.springframework.util.ObjectUtils;




      /**
      *
      * @author dominic.s
      *
      */
      public class CustomMBeanExporter extends MBeanExporter {


      private static final String MR_TYPE_OBJECT_REFERENCE = "ObjectReference";

      /** Stores the MBeanInfoAssembler to use for this exporter */
      private MBeanInfoAssembler customAssembler = new SimpleReflectiveMBeanInfoAssembler();

      public void doCustomRegister(String objectName, Object obj) throws RuntimeOperationsException, JMException, InvalidTargetObjectTypeException{
      String objectTmp = "domain: key1 = value1 , key2 = value2";
      ObjectName customObjectName = ObjectName.getInstance(objectTmp);

      ModelMBean mbean = new SpringModelMBean();// Model Bean new SpringModelMBean()
      mbean.setModelMBeanInfo(getMBeanDetails(obj, objectTmp));
      mbean.setManagedResource(obj, MR_TYPE_OBJECT_REFERENCE);

      doRegister(mbean, customObjectName);

      }


      /**
      * Gets the <code>ModelMBeanInfo</code> for the bean with the supplied key
      * and of the supplied type.
      * Overide method of getMBeanInfo of Parent.
      */
      private ModelMBeanInfo getMBeanDetails(Object managedBean, String beanKey) throws JMException {
      ModelMBeanInfo info = this.customAssembler.getMBeanInfo(managedBean, beanKey);

      return info;
      }


      -------------------------------------------------------------------------------------------------------------
      Here is my Dynamic Class
      package com.habuma.spitter.jmx;


      import java.io.Serializable;


      import javax.inject.Named;




      public class CustomMBean implements Serializable {

      private String name = "Default";


      public String getName() {
      return name;
      }


      public void setName(String name) {
      this.name = name;
      }




      }
      ------------------------------------------------------------------------------------------------------------
      Here is my Sample Test Main
      package com.testing;


      import javax.management.JMException;
      import javax.management.RuntimeOperationsException;
      import javax.management.modelmbean.InvalidTargetObjectTyp eException;


      import org.springframework.context.ApplicationContext;
      import org.springframework.context.support.ClassPathXmlAp plicationContext;
      import org.springframework.jmx.export.MBeanExporter;


      import com.habuma.spitter.jmx.CustomMBean;
      import com.habuma.spitter.jmx.CustomMBeanExporter;
      import com.habuma.spitter.jmx.SpittleNotifier;


      public class TestJmx {


      /**
      * @param args
      * @throws InterruptedException
      * @throws InvalidTargetObjectTypeException
      * @throws JMException
      * @throws RuntimeOperationsException
      */
      public static void main(String[] args) throws InterruptedException, RuntimeOperationsException, JMException, InvalidTargetObjectTypeException {
      //Load the Application Context.
      ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:jmx-context.xml","classpath:mbean-exporter-context-basic.xml");



      CustomMBeanExporter exporter = (CustomMBeanExporter)applicationContext.getBean("m beanExporter");

      CustomMBean customMBean = new CustomMBean();

      exporter.doCustomRegister("CustomMBeans", customMBean);

      System.out.println("Application Sucessfully loaded....");

      while(true){
      System.out.println(customMBean.getName());
      Thread.sleep(2000l);
      }
      }


      }


      Thanks and Regards

      Dominic
      R&D Apple.

      Comment

      Working...
      X