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 method periodicTrigger()
. The rule will
be triggered at 10 second intervals. If the period needs to be altered then a rule attached to method
getPeriod()
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 method resetPeriod(long)
can be used to return the desired value. The input argument is
the value returned by the call to getPeriod()
.
Field Summary |
static long |
DEFAULT_PERIOD
the default period which the helper will wait for between calls to periodicTrigger in milliseconds. |
Fields inherited from class org.jboss.byteman.rule.helper.Helper |
rule |
Method Summary |
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. |
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. |
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. |
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, closeTrace, countDown, createCountDown, createCounter, createCounter, createJoin, createRendezvous, createRendezvous, createTimer, debug, decrementCounter, delay, deleteCounter, deleteRendezvous, deleteTimer, flag, flagged, formatStack, formatStack, formatStack, formatStack, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackMatching, formatStackMatching, formatStackMatching, formatStackMatching, formatStackMatching, formatStackMatching, formatStackRange, getCountDown, getElapsedTimeFromTimer, getRendezvous, getStack, incrementCounter, incrementCounter, installed, isCountDown, isJoin, isRendezvous, joinEnlist, joinWait, killJVM, killJVM, killThread, matchIndex, openTrace, openTrace, printFrame, printlnFrame, readCounter, readCounter, rendezvous, resetTimer, setTriggering, signalKill, signalKill, signalThrow, signalThrow, signalWake, signalWake, toString, trace, trace, 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, triggerIndex, uninstalled, waitFor, waitFor, waiting |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
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
PeriodicHelper
public PeriodicHelper(Rule rule)
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.
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
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
Copyright © 2012. All Rights Reserved.