Class JMXHelper

  • All Implemented Interfaces:
    javax.management.DynamicMBean

    public class JMXHelper
    extends Helper
    implements javax.management.DynamicMBean
    A variant of PeriodicHelper which publishes its stats via JMX
    • Field Detail

      • SYSPROP_MBEAN_SERVER

        public static final java.lang.String SYSPROP_MBEAN_SERVER
        This is a system property whose value will determine which MBean Server the MBeans should be registered in. If the system property is not defined, the default will be the platform MBeanServer itself. If this system property is set, it will be assumed to be a default domain name of an existing MBeanServer. The existing MBeanServer with that default domain name will be used to house the MBeans. If there is no existing MBeanServer with the given default domain name, one will be created. Note that if this sysprop has the special value "*platform*", then the platform MBeanServer will be used (i.e. it will be as if this sysprop was not set).
        See Also:
        Constant Field Values
      • DEFAULT_PERIOD

        public static final long DEFAULT_PERIOD
        the default period which the helper will wait for between calls to periodicUpdate in milliseconds. this can be redefined either by overriding defaultPeriod
        See Also:
        Constant Field Values
      • DEFAULT_SAMPLE_SET_SIZE

        public static final int DEFAULT_SAMPLE_SET_SIZE
        default number of samples we are willing to store in order to maintain a running count of all previous
        See Also:
        Constant Field Values
      • DEFAULT_RMI_HOST

        public static final java.lang.String DEFAULT_RMI_HOST
        default value for the rmi server host address used by the JMX onnector server used only if an rmi server is required for the JMXConnector
        See Also:
        Constant Field Values
      • DEFAULT_RMI_PORT

        public static final int DEFAULT_RMI_PORT
        default value for the rmi server port used by the JMX connector server used only if an rmi server is required for the JMXConnector
        See Also:
        Constant Field Values
      • JMX_URL

        public static final java.lang.String JMX_URL
        JMX Url pattern for use when creating the connector server
        See Also:
        Constant Field Values
      • theHelper

        private static JMXHelper theHelper
        singleton instance holding the current periodic helper
      • mbeanServer

        private static javax.management.MBeanServer mbeanServer
        an mbean server for registering the mbean
      • connectorServer

        private static javax.management.remote.JMXConnectorServer connectorServer
        a connector server providing RMI access to the mbean server
      • shutDown

        private boolean shutDown
        flag used to control shutdown
      • period

        private long period
        the interval between wakeups for the helper thread
      • sampleSetSizePlusOne

        private int sampleSetSizePlusOne
        the number of samples collected plus one. this allows for the fact that one of the sample slots will be live and so will not contain a valid end time.
      • keyInfo

        private KeyInfo keyInfo
        the key information identifying the counters being sampled and the type of information they provide
      • counterValues

        private int[] counterValues
        array storing sampled counter values dimension 1 is keyCount
      • seriesValues

        private int[][] seriesValues
        array storing previously sampled counter values dimension 1 is RING_SIZE dimension 2 is keyCount
      • timeStamps

        private long[][] timeStamps
        array storing timestamps for previously sampled values dimension 1 is RING_SIZE dimension 2 is 2
      • START_TIME

        private static final int START_TIME
        index into first dimension of timestamp array containing start time
        See Also:
        Constant Field Values
      • END_TIME

        private static final int END_TIME
        index into second dimension of timestamp array containing end time
        See Also:
        Constant Field Values
      • ringIndex

        private int ringIndex
        ring buffer index identifying next
    • Constructor Detail

      • JMXHelper

        public JMXHelper​(Rule rule)
        constructor allowing this helper to be used as a helper
        Parameters:
        rule - the rule this helper is attached to
    • Method Detail

      • activated

        public static void activated()
        helper activation method which creates a periodic helper thread to perform periodic calls to the trigger method. should only be called when synchronized on PeriodicHelper.class.
      • deactivated

        public static void deactivated()
        helper deactivation method which shuts down the periodic helper thread. will only be called when synchronized on PeriodicHelper.class
      • samplePeriod

        private long samplePeriod()
        method called by the helper thread when it is activated to obtain the initial sample period. this is provided so that a rule set can inject an initial value to be used a the sample period. it should return a time interval in milliseconds.
        Returns:
      • sampleSetSize

        private int sampleSetSize()
        method called by the helper thread when it is activated to obtain the number of samples over which counter rates or counter means should be averaged. this is provided so that a rule set can inject an initial value to be used a the sample period. it should return a positive integer ibetween 1 and 10.
        Returns:
      • keyInfo

        private KeyInfo keyInfo()
        method called once by the helper thread when it is activated to obtain the list of keys identifying counters which are to be displayed by the helper mbean. this is provided so that a rule set inject a rule which creates and returns a value identifying the counters the rule set is collecting.
        Returns:
      • rmiServerRequired

        private boolean rmiServerRequired()
        method called once by the helper thread when it is activated to decide whether to start up a JMX RMI Connector Service. this is provided so that a rule set can inject a rule which returns true to enable startup. this method returns false which means it is disabled by default.
        Returns:
      • rmiHost

        private java.lang.String rmiHost()
        method called once by the helper thread when it is activated if rmiServerrequired returns true. this is provided so that a rule set can inject a rule which returns a host name to use for the connection. this method returns localhost as the default value.
        Returns:
      • rmiPort

        private int rmiPort()
        method called once by the helper thread when it is activated if rmiServerrequired returns true. this is provided so that a rule set can inject a rule which returns a port to use for the connection. this method returns "1234" as the default value.
        Returns:
      • getAttribute

        public java.lang.Object getAttribute​(java.lang.String attribute)
                                      throws javax.management.AttributeNotFoundException,
                                             javax.management.MBeanException,
                                             javax.management.ReflectionException
        Specified by:
        getAttribute in interface javax.management.DynamicMBean
        Throws:
        javax.management.AttributeNotFoundException
        javax.management.MBeanException
        javax.management.ReflectionException
      • setAttribute

        public void setAttribute​(javax.management.Attribute attribute)
                          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
      • getAttributes

        public javax.management.AttributeList getAttributes​(java.lang.String[] attributes)
        Specified by:
        getAttributes in interface javax.management.DynamicMBean
      • setAttributes

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

        public java.lang.Object invoke​(java.lang.String actionName,
                                       java.lang.Object[] params,
                                       java.lang.String[] signature)
                                throws javax.management.MBeanException,
                                       javax.management.ReflectionException
        Specified by:
        invoke in interface javax.management.DynamicMBean
        Throws:
        javax.management.MBeanException
        javax.management.ReflectionException
      • getMBeanInfo

        public javax.management.MBeanInfo getMBeanInfo()
        Specified by:
        getMBeanInfo in interface javax.management.DynamicMBean
      • getPeriodMillisecs

        private long getPeriodMillisecs()
        fetch the current sample period in milliseconds
      • setPeriodMillisecs

        private void setPeriodMillisecs​(long period)
        update the current sample period
        Parameters:
        period - the new period in milliseconds which must be greater than one second
      • setSampleSetSize

        private void setSampleSetSize​(int sampleSetSize)
        update the current sample set size
        Parameters:
        period - the new period in milliseconds which must be greater than one second
      • getKeyInfo

        private KeyInfo getKeyInfo()
        fetch the info describing the counter keys and types
        Returns:
      • setKeyInfo

        private void setKeyInfo​(KeyInfo keyInfo)
        assign the info describing the counter keys and types
        Parameters:
        keyInfo -
      • start

        private void start()
        method called in activate to create and run the shutdown thread. will only be called when synchronized on PeriodicHelper.class
      • shutdown

        private void shutdown()
        method called in deactivate to shutdown the helper thread. will only be called when synchronized on PeriodicHelper.class
      • getMBeanServer

        private static javax.management.MBeanServer getMBeanServer()
        a getter called when the helper is activated which computes the mbean server to use
      • initialise

        private void initialise()
        called by the helper thread when at startup. this calls the trigger methods which the rule set should short circuit to return information used to parameterise operation of the dynamic MBean
      • cleanup

        private void cleanup()
        this gets called by the helper thread when it starts and calls the trigger methods which the rule set can use to provide the information which parameterises operation of the MBean
      • doWait

        private boolean doWait()
        method called by the periodic helper thread to wait between calls to the trigger method
      • getPeriodSecs

        private int getPeriodSecs()
        getter for period used by the MBean code
        Returns:
      • setPeriodSecs

        private void setPeriodSecs​(int period)
        setter for period used by the MBean code
        Parameters:
        period -
      • periodicUpdate

        private void periodicUpdate()
        method called at regular intervals by the periodic helper thread to trigger sampling and publishing of counters.
      • getValue

        public java.lang.Object getValue​(int idx)
        getter for counter values used by MBean code
        Parameters:
        idx - the index into the key list
        Returns:
        the associated counter value as an Object