Package org.jboss.byteman.sample.helper
Class PeriodicHelper
- java.lang.Object
-
- org.jboss.byteman.rule.helper.Helper
-
- org.jboss.byteman.sample.helper.PeriodicHelper
-
public class PeriodicHelper extends Helper
A helper class which adds a background thread when the helper class is activated and removes the background thread when it is deactivated. The thread loops, calling a specific trigger method,periodicTrigger()
and then waiting for a fixed time. Rule sets which employ the helper class can attach rules to the periodic trigger method in order to perform operations which should happen at regular intervalsx. This is useful, for example, for rule sets which collect statistical information. A periodically triggered rule can read and then rezero a set of stats counters, allowing it to provide regular interval statistics. The basic way to use this class is to employ attach a rule to methodperiodicTrigger()
. The rule will be triggered at 10 second intervals. If the period needs to be altered then a rule attached to methodgetPeriod()
can be used to return an alternative value.getPeriod()
is called once when the periodic trigger thread is created. If the wait interval needs to be recomputed before each wait then a rule attached to methodresetPeriod(long)
can be used to return the desired value. The input argument is the value returned by the call togetPeriod()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
PeriodicHelper.PeriodicHelperThread
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_PERIOD
the default period which the helper will wait for between calls to periodicTrigger in milliseconds.private boolean
shutDown
flag which enforces shutdownprivate static PeriodicHelper
theHelper
singleton instance holding the current periodic helperprivate static PeriodicHelper.PeriodicHelperThread
theHelperThread
handle on the current helper thread
-
Constructor Summary
Constructors Constructor Description PeriodicHelper(Rule rule)
-
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.static void
deactivated()
helper deactivation method which shuts down the periodic helper thread.private boolean
doWait(long periodMilliSecs)
method called by the periodic helper thread to wait between calls to the trigger methodprotected long
getPeriod()
a method which is called when the periodic helper thread is started to compute the interval in milliseconds for which the thread should wait between calls to the trigger method which by default returns the default interval of 10 seconds.protected void
periodicTrigger()
a method which is called at regular intervals by the periodic helper thread to trigger rule processing.protected long
resetPeriod(long initialPeriod)
a method which is called when the periodic helper thread is about to wait which by default returns the input value.private void
shutdown()
method called in deactivate 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
-
DEFAULT_PERIOD
public static final long DEFAULT_PERIOD
the default period which the helper will wait for between calls to periodicTrigger in milliseconds. this can be redefined either by overriding defaultPeriod- See Also:
- Constant Field Values
-
theHelper
private static PeriodicHelper theHelper
singleton instance holding the current periodic helper
-
theHelperThread
private static PeriodicHelper.PeriodicHelperThread theHelperThread
handle on the current helper thread
-
shutDown
private boolean shutDown
flag which enforces shutdown
-
-
Constructor Detail
-
PeriodicHelper
public PeriodicHelper(Rule rule)
-
-
Method Detail
-
periodicTrigger
protected void periodicTrigger()
a method which is called at regular intervals by the periodic helper thread to trigger rule processing. This can be redefined by attaching one or more rules to the method. It is also possible to override this method in a subclass
-
getPeriod
protected long getPeriod()
a method which is called when the periodic helper thread is started to compute the interval in milliseconds for which the thread should wait between calls to the trigger method which by default returns the default interval of 10 seconds. This can either be overridden or redefined by attaching a rule to the method.- Returns:
- the wait period
-
resetPeriod
protected long resetPeriod(long initialPeriod)
a method which is called when the periodic helper thread is about to wait which by default returns the input value. this can be overridden or redefined by attaching a rule to the method.- Parameters:
initialPeriod
- the initial wait time returned by getPeriod when the periodic thread was created- Returns:
- the wait period
-
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
-
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 the helper thread. will only be called when synchronized on PeriodicHelper.class
-
doWait
private boolean doWait(long periodMilliSecs)
method called by the periodic helper thread to wait between calls to the trigger method
-
-