public class Sequencer extends Object implements Runnable
The class is parameterised on a Timecode
object which will be used
to determine whether actions should be triggered. The accuracy of the
triggers can be determined by changing the internal timer tick of the
sequencer. For example, if you know that actions will never occur more
than once a second, you can set the tick to something near a second.
This class will automatically start the TimeKeeper
running when
it is run. The time of firing of an event cannot be guaranteed and an event
will always be fired if
Modifier and Type | Class and Description |
---|---|
static interface |
Sequencer.SequencedAction
A class that can be sequenced by the sequencer can implement this
interface.
|
static class |
Sequencer.SequencerEvent
An event in the sequencer, this represents an action occurring at a
specific time.
|
Constructor and Description |
---|
Sequencer(TimeKeeper<? extends Timecode> timeKeeper)
Default constructor that instantiates a sequencer that will check
for actions every 10 milliseconds using the given time keeper.
|
Sequencer(TimeKeeper<? extends Timecode> timeKeeper,
long tickAccuracyMillis)
Constructor that instantiates a sequencer that will check for actions
at the given rate using the given time keeper.
|
Modifier and Type | Method and Description |
---|---|
void |
addEvent(Sequencer.SequencerEvent event)
Add an event to the sequencer.
|
TreeSet<Sequencer.SequencerEvent> |
getEvents()
Returns the set of events in this sequencer.
|
void |
run() |
void |
setRemoveEventsWhenComplete(boolean rewc)
Sets whether to remove events from the event list when they have
been completed.
|
void |
setRetryFailedEvents(boolean rfe)
Sets whether failed events will be retried at the next processing
time.
|
public Sequencer(TimeKeeper<? extends Timecode> timeKeeper)
timeKeeper
- The timekeeper to usepublic Sequencer(TimeKeeper<? extends Timecode> timeKeeper, long tickAccuracyMillis)
timeKeeper
- The timekeeper to usetickAccuracyMillis
- How often the sequencer will check for events.public void addEvent(Sequencer.SequencerEvent event)
event
- The event to add.public void run()
run
in interface Runnable
Runnable.run()
public TreeSet<Sequencer.SequencerEvent> getEvents()
public void setRetryFailedEvents(boolean rfe)
rfe
- TRUE to retry failed events.public void setRemoveEventsWhenComplete(boolean rewc)
getEvents()
to retrieve the
list of events and clone it. Failed events will be removed from
the list only if retryFailedEvents is set to false.rewc
- TRUE to remove successfully completed events.