Class SimpleMBean

  • All Implemented Interfaces:
    javax.management.DynamicMBean
    Direct Known Subclasses:
    PlainEditorAdminBean, SimpleAdminBean

    public abstract class SimpleMBean
    extends java.lang.Object
    implements javax.management.DynamicMBean
    A simple MBean which does not require an interface class unlike the StandardMBean class. The methods are exposed through a method call, which in turn then calls the methods using the Reflection API.

    This class is similar to the javax.management.StandardMBean, but it does require the API interface to be declared, so it's simpler. It's not as powerful, but it does not require you to declare two classes (and keep them in sync).

    Since:
    2.6
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.management.MBeanInfo m_beanInfo  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected SimpleMBean()
      Create a new SimpleMBean
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object getAttribute​(java.lang.String name)
      Gets an attribute using reflection from the MBean.
      abstract java.lang.String[] getAttributeNames()
      This method must return a list of attributes which are exposed by the SimpleMBean.
      javax.management.AttributeList getAttributes​(java.lang.String[] arg0)
      Gets multiple attributes at the same time.
      protected java.lang.String getDescription()
      Customization hook: Override this to get a description for your MBean.
      javax.management.MBeanInfo getMBeanInfo()
      Return the MBeanInfo structure.
      abstract java.lang.String[] getMethodNames()
      This method must return a list of operations which are to be exposed by the SimpleMBean.
      java.lang.Object invoke​(java.lang.String arg0, java.lang.Object[] arg1, java.lang.String[] arg2)
      Invokes a particular method.
      void setAttribute​(javax.management.Attribute attr)  
      javax.management.AttributeList setAttributes​(javax.management.AttributeList arg0)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • m_beanInfo

        protected javax.management.MBeanInfo m_beanInfo
    • Constructor Detail

      • SimpleMBean

        protected SimpleMBean()
                       throws javax.management.NotCompliantMBeanException
        Create a new SimpleMBean
        Throws:
        javax.management.NotCompliantMBeanException - if an error occurs registering the MBean.
    • Method Detail

      • getDescription

        protected java.lang.String getDescription()
        Customization hook: Override this to get a description for your MBean. By default, this is an empty string.
        Returns:
        A description for the MBean.
      • getAttribute

        public java.lang.Object getAttribute​(java.lang.String name)
                                      throws javax.management.AttributeNotFoundException,
                                             javax.management.MBeanException,
                                             javax.management.ReflectionException
        Gets an attribute using reflection from the MBean.
        Specified by:
        getAttribute in interface javax.management.DynamicMBean
        Parameters:
        name - Name of the attribute to find.
        Returns:
        The value returned by the corresponding getXXX() call
        Throws:
        javax.management.AttributeNotFoundException - If there is not such attribute
        javax.management.MBeanException
        javax.management.ReflectionException
      • getAttributes

        public javax.management.AttributeList getAttributes​(java.lang.String[] arg0)
        Gets multiple attributes at the same time.
        Specified by:
        getAttributes in interface javax.management.DynamicMBean
        Parameters:
        arg0 - The attribute names to get
        Returns:
        A list of attributes
      • getMBeanInfo

        public javax.management.MBeanInfo getMBeanInfo()
        Return the MBeanInfo structure.
        Specified by:
        getMBeanInfo in interface javax.management.DynamicMBean
        Returns:
        the MBeanInfo
      • invoke

        public java.lang.Object invoke​(java.lang.String arg0,
                                       java.lang.Object[] arg1,
                                       java.lang.String[] arg2)
                                throws javax.management.MBeanException,
                                       javax.management.ReflectionException
        Invokes a particular method.
        Specified by:
        invoke in interface javax.management.DynamicMBean
        Parameters:
        arg0 - Method name
        arg1 - A list of arguments for the invocation
        Throws:
        javax.management.MBeanException
        javax.management.ReflectionException
      • setAttribute

        public void setAttribute​(javax.management.Attribute attr)
                          throws javax.management.AttributeNotFoundException,
                                 javax.management.InvalidAttributeValueException,
                                 javax.management.MBeanException,
                                 javax.management.ReflectionException
        Specified by:
        setAttribute in interface javax.management.DynamicMBean
        Throws:
        javax.management.AttributeNotFoundException
        javax.management.InvalidAttributeValueException
        javax.management.MBeanException
        javax.management.ReflectionException
      • setAttributes

        public javax.management.AttributeList setAttributes​(javax.management.AttributeList arg0)
        Specified by:
        setAttributes in interface javax.management.DynamicMBean
      • getAttributeNames

        public abstract java.lang.String[] getAttributeNames()
        This method must return a list of attributes which are exposed by the SimpleMBean. If there's a getXXX() method available, it'll be exposed as a getter, and if there's a setXXX() method available, it'll be exposed as a setter. For example:
             public void setFoo( String foo ) ...
             public String getFoo() ...
        
             public String[] getAttributeNames()
             {
                 String[] attrs = { "foo" };
        
                 return attrs;
             }
          
        Also, methods starting with "is" are also recognized as getters (e.g. public boolean isFoo().)
        Returns:
        An array of attribute names that can be get and optionally set.
      • getMethodNames

        public abstract java.lang.String[] getMethodNames()
        This method must return a list of operations which are to be exposed by the SimpleMBean. Note that using overloaded method names is not supported - only one will be exposed as a JMX method at random.
        Returns:
        An array of method names that should be exposed as JMX operations.