Class JMXManagementService

  • All Implemented Interfaces:
    ManagementService, ModuleControl, ManagementMBean

    public final class JMXManagementService
    extends java.lang.Object
    implements ManagementService, ModuleControl
    This class implements the ManagementService interface and provides a simple management and monitoring service. An mbean registered with this service remains until it is unregistered. While registered with this service it may be registered and unregistered with the jmx service a number of times.
    See Also:
    ManagementService
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static SystemPermission CONTROL
      Control permission (permissions are immutable).
      private javax.management.MBeanServer mbeanServer
      Platform MBean server, from ManagementFactory.getPlatformMBeanServer().
      private javax.management.ObjectName myManagementBean
      If this object is registered as a management mbean then myManagementBean represents its name.
      private javax.management.MBeanServer myManagementServer  
      private java.util.Map<javax.management.ObjectName,​javax.management.StandardMBean> registeredMbeans
      The set of mbeans registered to this service by Derby's code.
      private java.lang.String systemIdentifier
      Runtime value to disambiguate multiple Derby systems in the same virtual machine but different class loaders.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void boot​(boolean create, java.util.Properties properties)
      Start the management service if derby.system.jmx is true.
      private void checkJMXControl()
      Require SystemPermission("jmx", "control") to change the management state.
      private void findServer()
      Initialize the management service by obtaining the platform MBeanServer and registering system beans.
      private static ModuleFactory getMonitor()
      Privileged Monitor lookup.
      java.lang.String getSystemIdentifier()
      Get the system identifier that this MBean is managing.
      boolean isManagementActive()
      Is Derby's JMX management active.
      private void jmxRegister​(javax.management.StandardMBean standardMBean, javax.management.ObjectName beanName)
      Register an mbean with the platform mbean server.
      private void jmxUnregister​(javax.management.ObjectName mbeanName)
      Unregister an mbean from the JMX plaform server but leave it registered to this service.
      java.lang.String quotePropertyValue​(java.lang.String value)
      Quote an MBean key property value, so that it is safe to pass to ManagementService.registerMBean(T, java.lang.Class<T>, java.lang.String) even if it potentially contains special characters.
      <T> java.lang.Object registerMBean​(T bean, java.lang.Class<T> beanInterface, java.lang.String keyProperties)
      Registers an MBean with the MBean server as a StandardMBean.
      void startManagement()
      Inform Derby to start its JMX management by registering MBeans relevant to its current state.
      void stop()
      Stop the module.
      void stopManagement()
      Inform Derby to stop its JMX management by unregistering its MBeans.
      void unregisterMBean​(java.lang.Object mbeanIdentifier)
      Unregister an mbean using an object previous returned from registerMBean.
      private void unregisterMBean​(javax.management.ObjectName mbeanName)
      Unregisters an mbean from this service and JMX plaform server
      • Methods inherited from class java.lang.Object

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

      • mbeanServer

        private javax.management.MBeanServer mbeanServer
        Platform MBean server, from ManagementFactory.getPlatformMBeanServer(). If not null then this service has registered mbeans with the plaform MBean server. If null then this service either has no mbeans registered or one mbean registered (representing itself).
      • registeredMbeans

        private java.util.Map<javax.management.ObjectName,​javax.management.StandardMBean> registeredMbeans
        The set of mbeans registered to this service by Derby's code. These beans are registered with the platform mbean server if mbeanServer is not null.
      • myManagementBean

        private javax.management.ObjectName myManagementBean
        If this object is registered as a management mbean then myManagementBean represents its name. This will be non-null when derby.system.jmx is true.
      • myManagementServer

        private javax.management.MBeanServer myManagementServer
      • systemIdentifier

        private java.lang.String systemIdentifier
        Runtime value to disambiguate multiple Derby systems in the same virtual machine but different class loaders. Set as the system attribute in the ObjectName for all MBeans registered.
      • CONTROL

        private static final SystemPermission CONTROL
        Control permission (permissions are immutable).
    • Constructor Detail

      • JMXManagementService

        public JMXManagementService()
    • Method Detail

      • boot

        public void boot​(boolean create,
                         java.util.Properties properties)
                  throws StandardException
        Start the management service if derby.system.jmx is true.

        Starting the service means:

        • getting the platform MBeanServer which may require starting it
        • registering a Version mbean representing the system
        Specified by:
        boot in interface ModuleControl
        Throws:
        StandardException - Module cannot be started.
        See Also:
        Monitor, ModuleFactory
      • stop

        public void stop()
        Description copied from interface: ModuleControl
        Stop the module. The module may be found via a findModule() method until some time after this method returns. Therefore the factory must be prepared to reject requests to it once it has been stopped. In addition other modules may cache a reference to the module and make requests of it after it has been stopped, these requests should be rejected as well.
        Specified by:
        stop in interface ModuleControl
        See Also:
        Monitor, ModuleFactory
      • findServer

        private void findServer()
        Initialize the management service by obtaining the platform MBeanServer and registering system beans. Separate from boot() to allow future changes where the jmx management can be enabled on the fly.
      • registerMBean

        public <T> java.lang.Object registerMBean​(T bean,
                                                  java.lang.Class<T> beanInterface,
                                                  java.lang.String keyProperties)
                                           throws StandardException
        Registers an MBean with the MBean server as a StandardMBean. Use of the StandardMBean allows the implementation details of Derby's mbeans to be hidden from JMX, thus only exposing the MBean's interface in org.apache.derby.mbeans.
        Specified by:
        registerMBean in interface ManagementService
        Parameters:
        bean - The MBean to wrap with a StandardMBean and register
        beanInterface - The management interface for the MBean.
        keyProperties - The String representation of the MBean's key properties, they will be added into the ObjectName with Derby's domain. Key type should be first with a short name for the bean, typically the class name without the package.
        Returns:
        An identifier that can later be used to unregister the mbean.
        Throws:
        StandardException
      • jmxRegister

        private void jmxRegister​(javax.management.StandardMBean standardMBean,
                                 javax.management.ObjectName beanName)
                          throws javax.management.JMException
        Register an mbean with the platform mbean server.
        Throws:
        javax.management.JMException
      • unregisterMBean

        public void unregisterMBean​(java.lang.Object mbeanIdentifier)
        Unregister an mbean using an object previous returned from registerMBean.
        Specified by:
        unregisterMBean in interface ManagementService
        Parameters:
        mbeanIdentifier - An identifier returned by registerMBean.
      • unregisterMBean

        private void unregisterMBean​(javax.management.ObjectName mbeanName)
        Unregisters an mbean from this service and JMX plaform server
        Parameters:
        mbeanName - Bean to unregister.
      • jmxUnregister

        private void jmxUnregister​(javax.management.ObjectName mbeanName)
        Unregister an mbean from the JMX plaform server but leave it registered to this service. This is so that if jmx is reenabled we can reestablish all vaid mbeans (that are still registered with this service).
        Parameters:
        mbeanName -
      • isManagementActive

        public boolean isManagementActive()
        Description copied from interface: ManagementMBean
        Is Derby's JMX management active. If active then Derby has registered MBeans relevant to its current state.
        Specified by:
        isManagementActive in interface ManagementMBean
        Returns:
        true Derby has registered beans, false Derby has not registered any beans.
      • startManagement

        public void startManagement()
        Description copied from interface: ManagementMBean
        Inform Derby to start its JMX management by registering MBeans relevant to its current state. If Derby is not booted then no action is taken.

        Require SystemPermission("jmx", "control") if a security manager is installed.

        Specified by:
        startManagement in interface ManagementMBean
        See Also:
        SystemPermission
      • stopManagement

        public void stopManagement()
        Description copied from interface: ManagementMBean
        Inform Derby to stop its JMX management by unregistering its MBeans. If Derby is not booted then no action is taken.

        Require SystemPermission("jmx", "control") if a security manager is installed.

        Specified by:
        stopManagement in interface ManagementMBean
        See Also:
        SystemPermission
      • checkJMXControl

        private void checkJMXControl()
        Require SystemPermission("jmx", "control") to change the management state.
      • getSystemIdentifier

        public java.lang.String getSystemIdentifier()
        Description copied from interface: ManagementMBean
        Get the system identifier that this MBean is managing. The system identifier is a runtime value to disambiguate multiple Derby systems in the same virtual machine but different class loaders.
        Specified by:
        getSystemIdentifier in interface ManagementMBean
        Returns:
        Runtime identifier for the system, null if Derby is not running.
      • getMonitor

        private static ModuleFactory getMonitor()
        Privileged Monitor lookup. Must be private so that user code can't call this entry point.