Package org.jboss.byteman.sample.helper
Class JMXHelper
- java.lang.Object
-
- org.jboss.byteman.rule.helper.Helper
-
- org.jboss.byteman.sample.helper.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
JMXHelper.PeriodicHelperThread
background thread which regularly samples the counters updated by the rule set and updates the counters accordingly
-
Field Summary
Fields Modifier and Type Field Description private static javax.management.remote.JMXConnectorServer
connectorServer
a connector server providing RMI access to the mbean serverprivate int[]
counterValues
array storing sampled counter values dimension 1 is keyCountstatic long
DEFAULT_PERIOD
the default period which the helper will wait for between calls to periodicUpdate in milliseconds.static 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 JMXConnectorstatic 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 JMXConnectorstatic int
DEFAULT_SAMPLE_SET_SIZE
default number of samples we are willing to store in order to maintain a running count of all previousprivate static int
END_TIME
index into second dimension of timestamp array containing end timestatic java.lang.String
JMX_URL
JMX Url pattern for use when creating the connector serverprivate KeyInfo
keyInfo
the key information identifying the counters being sampled and the type of information they provideprivate static javax.management.MBeanServer
mbeanServer
an mbean server for registering the mbeanprivate long
period
the interval between wakeups for the helper threadprivate int
ringIndex
ring buffer index identifying nextprivate int
sampleSetSizePlusOne
the number of samples collected plus one.private int[][]
seriesValues
array storing previously sampled counter values dimension 1 is RING_SIZE dimension 2 is keyCountprivate boolean
shutDown
flag used to control shutdownprivate static int
START_TIME
index into first dimension of timestamp array containing start timestatic java.lang.String
SYSPROP_MBEAN_SERVER
This is a system property whose value will determine which MBean Server the MBeans should be registered in.private static JMXHelper
theHelper
singleton instance holding the current periodic helperprivate static JMXHelper.PeriodicHelperThread
theHelperThread
handle on the current helper threadprivate long[][]
timeStamps
array storing timestamps for previously sampled values dimension 1 is RING_SIZE dimension 2 is 2
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
activated()
helper activation method which creates a periodic helper thread to perform periodic calls to the trigger method.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 MBeanstatic void
deactivated()
helper deactivation method which shuts down the periodic helper thread.private boolean
doWait()
method called by the periodic helper thread to wait between calls to the trigger methodjava.lang.Object
getAttribute(java.lang.String attribute)
javax.management.AttributeList
getAttributes(java.lang.String[] attributes)
private KeyInfo
getKeyInfo()
fetch the info describing the counter keys and typesjavax.management.MBeanInfo
getMBeanInfo()
private static javax.management.MBeanServer
getMBeanServer()
a getter called when the helper is activated which computes the mbean server to useprivate long
getPeriodMillisecs()
fetch the current sample period in millisecondsprivate int
getPeriodSecs()
getter for period used by the MBean codejava.lang.Object
getValue(int idx)
getter for counter values used by MBean codeprivate void
initialise()
called by the helper thread when at startup.java.lang.Object
invoke(java.lang.String actionName, java.lang.Object[] params, java.lang.String[] signature)
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.private void
periodicUpdate()
method called at regular intervals by the periodic helper thread to trigger sampling and publishing of counters.private java.lang.String
rmiHost()
method called once by the helper thread when it is activated if rmiServerrequired returns true.private int
rmiPort()
method called once by the helper thread when it is activated if rmiServerrequired returns true.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.private long
samplePeriod()
method called by the helper thread when it is activated to obtain the initial sample period.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.void
setAttribute(javax.management.Attribute attribute)
javax.management.AttributeList
setAttributes(javax.management.AttributeList attributes)
private void
setKeyInfo(KeyInfo keyInfo)
assign the info describing the counter keys and typesprivate void
setPeriodMillisecs(long period)
update the current sample periodprivate void
setPeriodSecs(int period)
setter for period used by the MBean codeprivate void
setSampleSetSize(int sampleSetSize)
update the current sample set sizeprivate void
shutdown()
method called in deactivate to shutdown the helper thread.private void
start()
method called in activate to create and run the shutdown thread.-
Methods inherited from class org.jboss.byteman.rule.helper.Helper
addCountDown, callerCheck, callerEquals, callerEquals, callerEquals, callerEquals, callerEquals, callerEquals, callerEquals, callerEquals, callerEquals, callerMatches, callerMatches, callerMatches, callerMatches, callerMatches, callerMatches, callerMatches, callerMatches, callerMatches, clear, clearLinks, clearLinks, closeTrace, countDown, createCountDown, createCounter, createCounter, createJoin, createLinkMap, createRendezvous, createRendezvous, createTimer, debug, decrementCounter, delay, deleteCounter, deleteLinkMap, deleteRendezvous, deleteTimer, err, errTraceException, flag, flagged, formatAllStacks, formatAllStacks, formatAllStacks, formatAllStacks, formatStack, formatStack, formatStack, formatStack, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackMatching, formatStackMatching, formatStackMatching, formatStackMatching, formatStackMatching, formatStackMatching, formatStackRange, formatThreadStack, formatThreadStack, formatThreadStack, formatThreadStack, getCountDown, getElapsedTimeFromTimer, getObjectSize, getRendezvous, getStack, incrementCounter, incrementCounter, installed, isCountDown, isJoin, isRendezvous, joinEnlist, joinWait, joinWait, killJVM, killJVM, killThread, link, link, linked, linked, linkNames, linkNames, linkValues, linkValues, matchIndex, noisy, noisyTraceException, openTrace, openTrace, out, outTraceException, printFrame, printlnFrame, readCounter, readCounter, rendezvous, rendezvous, resetTimer, setTriggering, signalKill, signalKill, signalThrow, signalThrow, signalWake, signalWake, toString, trace, trace, traceAllStacks, traceAllStacks, traceAllStacks, traceAllStacks, traceAllStacks, traceAllStacks, traceClose, traceln, traceln, traceOpen, traceOpen, traceStack, traceStack, traceStack, traceStack, traceStack, traceStack, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackRange, traceThreadStack, traceThreadStack, traceThreadStack, traceThreadStack, traceThreadStack, traceThreadStack, triggerIndex, uninstalled, unlink, unlink, verbose, verboseTraceException, waitFor, waitFor, waiting
-
-
-
-
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
-
theHelperThread
private static JMXHelper.PeriodicHelperThread theHelperThread
handle on the current helper thread
-
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 interfacejavax.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 interfacejavax.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 interfacejavax.management.DynamicMBean
-
setAttributes
public javax.management.AttributeList setAttributes(javax.management.AttributeList attributes)
- Specified by:
setAttributes
in interfacejavax.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 interfacejavax.management.DynamicMBean
- Throws:
javax.management.MBeanException
javax.management.ReflectionException
-
getMBeanInfo
public javax.management.MBeanInfo getMBeanInfo()
- Specified by:
getMBeanInfo
in interfacejavax.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
-
-