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:
DynamicMBean
A variant of PeriodicHelper which publishes its stats via JMX
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
background thread which regularly samples the counters updated by the rule set and updates the counters accordingly -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static JMXConnectorServer
a connector server providing RMI access to the mbean serverprivate int[]
array storing sampled counter values dimension 1 is keyCountstatic final long
the default period which the helper will wait for between calls to periodicUpdate in milliseconds.static final String
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 final int
default value for the rmi server port used by the JMX connector server used only if an rmi server is required for the JMXConnectorstatic final int
default number of samples we are willing to store in order to maintain a running count of all previousprivate static final int
index into second dimension of timestamp array containing end timestatic final String
JMX Url pattern for use when creating the connector serverprivate KeyInfo
the key information identifying the counters being sampled and the type of information they provideprivate static MBeanServer
an mbean server for registering the mbeanprivate long
the interval between wakeups for the helper threadprivate int
ring buffer index identifying nextprivate int
the number of samples collected plus one.private int[][]
array storing previously sampled counter values dimension 1 is RING_SIZE dimension 2 is keyCountprivate boolean
flag used to control shutdownprivate static final int
index into first dimension of timestamp array containing start timestatic final String
This is a system property whose value will determine which MBean Server the MBeans should be registered in.private static JMXHelper
singleton instance holding the current periodic helperprivate static JMXHelper.PeriodicHelperThread
handle on the current helper threadprivate long[][]
array storing timestamps for previously sampled values dimension 1 is RING_SIZE dimension 2 is 2 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
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
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 methodgetAttribute
(String attribute) getAttributes
(String[] attributes) private KeyInfo
fetch the info describing the counter keys and typesprivate static MBeanServer
a getter called when the helper is activated which computes the mbean server to useprivate long
fetch the current sample period in millisecondsprivate int
getter for period used by the MBean codegetValue
(int idx) getter for counter values used by MBean codeprivate void
called by the helper thread when at startup.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
method called at regular intervals by the periodic helper thread to trigger sampling and publishing of counters.private 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
method called once by the helper thread when it is activated to decide whether to start up a JMX RMI Connector Service.private long
method called by the helper thread when it is activated to obtain the initial sample period.private int
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
(Attribute attribute) setAttributes
(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 Details
-
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_PERIODthe 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_SIZEdefault number of samples we are willing to store in order to maintain a running count of all previous- See Also:
-
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_PORTdefault 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
JMX Url pattern for use when creating the connector server- See Also:
-
theHelper
singleton instance holding the current periodic helper -
theHelperThread
handle on the current helper thread -
mbeanServer
an mbean server for registering the mbean -
connectorServer
a connector server providing RMI access to the mbean server -
shutDown
private boolean shutDownflag used to control shutdown -
period
private long periodthe interval between wakeups for the helper thread -
sampleSetSizePlusOne
private int sampleSetSizePlusOnethe 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
the key information identifying the counters being sampled and the type of information they provide -
counterValues
private int[] counterValuesarray storing sampled counter values dimension 1 is keyCount -
seriesValues
private int[][] seriesValuesarray storing previously sampled counter values dimension 1 is RING_SIZE dimension 2 is keyCount -
timeStamps
private long[][] timeStampsarray storing timestamps for previously sampled values dimension 1 is RING_SIZE dimension 2 is 2 -
START_TIME
private static final int START_TIMEindex into first dimension of timestamp array containing start time- See Also:
-
END_TIME
private static final int END_TIMEindex into second dimension of timestamp array containing end time- See Also:
-
ringIndex
private int ringIndexring buffer index identifying next
-
-
Constructor Details
-
JMXHelper
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
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
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 Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException - Specified by:
getAttribute
in interfaceDynamicMBean
- Throws:
AttributeNotFoundException
MBeanException
ReflectionException
-
setAttribute
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException - Specified by:
setAttribute
in interfaceDynamicMBean
- Throws:
AttributeNotFoundException
InvalidAttributeValueException
MBeanException
ReflectionException
-
getAttributes
- Specified by:
getAttributes
in interfaceDynamicMBean
-
setAttributes
- Specified by:
setAttributes
in interfaceDynamicMBean
-
invoke
public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException - Specified by:
invoke
in interfaceDynamicMBean
- Throws:
MBeanException
ReflectionException
-
getMBeanInfo
- Specified by:
getMBeanInfo
in interfaceDynamicMBean
-
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
fetch the info describing the counter keys and types- Returns:
-
setKeyInfo
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
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
getter for counter values used by MBean code- Parameters:
idx
- the index into the key list- Returns:
- the associated counter value as an Object
-