Class JMXHelper

java.lang.Object
org.jboss.byteman.rule.helper.Helper
org.jboss.byteman.sample.helper.JMXHelper
All Implemented Interfaces:
DynamicMBean

public class JMXHelper extends Helper implements DynamicMBean
A variant of PeriodicHelper which publishes its stats via JMX
  • Field Details

    • SYSPROP_MBEAN_SERVER

      public static final 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:
    • 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:
    • 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:
    • DEFAULT_RMI_HOST

      public static final 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:
    • 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:
    • JMX_URL

      public static final String JMX_URL
      JMX Url pattern for use when creating the connector server
      See Also:
    • theHelper

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

      private static JMXHelper.PeriodicHelperThread theHelperThread
      handle on the current helper thread
    • mbeanServer

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

      private static 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:
    • END_TIME

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

      private int ringIndex
      ring buffer index identifying next
  • Constructor Details

    • 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 Details

    • 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 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

      Specified by:
      getAttribute in interface DynamicMBean
      Throws:
      AttributeNotFoundException
      MBeanException
      ReflectionException
    • setAttribute

      Specified by:
      setAttribute in interface DynamicMBean
      Throws:
      AttributeNotFoundException
      InvalidAttributeValueException
      MBeanException
      ReflectionException
    • getAttributes

      public AttributeList getAttributes(String[] attributes)
      Specified by:
      getAttributes in interface DynamicMBean
    • setAttributes

      public AttributeList setAttributes(AttributeList attributes)
      Specified by:
      setAttributes in interface DynamicMBean
    • invoke

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

      public MBeanInfo getMBeanInfo()
      Specified by:
      getMBeanInfo in interface 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 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 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