public class EventTimeout extends EventWithDst
StateMachine
as persistent instance
of a parallel state machine or of the top state if timeouts are used in the states.
EventThread thread = new EventThread("stateThread"); //uses the thread as timer manager and as event executer EventTimeout timeout = new EventTimeout(stateMachine, thread);Activate the timeout event:
timeout.activate(7000); //in 7 seconds.
EventTimeout#EventTimeout(EventConsumer, EventTimerThread)
, EventTimeout()
.
activate(int)
, activateAt(long)
, activateAt(long, long)
deactivate()
timeExecution()
, timeExecutionLatest()
, timeToExecution()
used()
TimeOrder
.
EventTimerThread
StateMachine
Modifier and Type | Field and Description |
---|---|
int |
dbgctWindup
It is counted only.
|
private static long |
serialVersionUID |
protected long |
timeExecution
If not 0, it is the time to execute it.
|
protected long |
timeExecutionLatest
If not 0, it is the last time to execute it if the execution will be deferred by additional invocation of
activateAt(long) while it is activated already. |
static java.lang.String |
version
Version and history:
2015-01-02 Hartmut created: as super class of
TimeOrder and as event for timeout for state machines. |
bAwaitReserve, ctConsumed, dateCreation, dateOrder, evDst, evDstThread, orderId, stateOfEvent, toStringDateFormat
Constructor and Description |
---|
EventTimeout()
Creates an event as a static object for re-usage.
|
EventTimeout(EventConsumer consumer,
EventTimerThread_ifc thread)
Creates an event as static or dynamic object for usage.
|
Modifier and Type | Method and Description |
---|---|
void |
activate(int millisec)
Activate the event for the given laps of time.
|
void |
activateAt(long date)
Activates the timeout event to the given timestamp.
|
void |
activateAt(long date,
long latest)
Activate the event at the given absolute time
If the event is activated already for a shorter time, the activation time is deferred to this given time
but not later than a latest time given with
activateAt(long, long) . |
void |
deactivate()
Remove this from the queue of timer events and orders
|
protected void |
doTimeElapsed()
Processes the event or timeOrder.
|
long |
timeExecution()
Returns the time stamp where the time is elapsed
|
long |
timeExecutionLatest()
Returns the time stamp where the time is elapsed latest.
|
int |
timeToExecution()
Checks whether it should be executed.
|
boolean |
used() |
consumed, dateCreation, evDst, getDst, getDstThread, hasDst, isOccupied, notifyDequeued, occupy, occupy, occupy, occupyRecall, occupyRecall, occupyRecall, occupyRecall, relinquish, removeFromQueue, sendEvent, setDst, setOrderId, XXXdonotRelinquish
public static final java.lang.String version
TimeOrder
and as event for timeout for state machines.
private static final long serialVersionUID
protected long timeExecution
protected long timeExecutionLatest
activateAt(long)
while it is activated already.public int dbgctWindup
public EventTimeout()
EventWithDst.occupy(EventSource, EventConsumer, EventTimerThread, boolean)
before first usage. Use EventWithDst.relinquish()
to release the usage.
Usual the parameterized method EventTimeout#EventTimeout(EventSource, EventConsumer, EventThreadIfc)
should be used.public EventTimeout(EventConsumer consumer, EventTimerThread_ifc thread)
EventWithDst#EventWithDst(EventSource, EventConsumer, EventThreadIfc)
The timeout instance may be static usual (permanent referenced) and not allocated on demand (with new)
because it is used whenever a special state is entered.consumer
- The destination object for the event. If it is null nothing will be executed if the event is expired.thread
- thread to handle the time order. It is obligatory.public void activate(int millisec)
activateAt(long, long)
.millisec
- if a negative value or a value less then 3 is given the event is processed immediately.activateAt(long, long).
public void activateAt(long date)
date
- The absolute time stamp in seconds after 1970 UTC like given with System.currentTimeMillis()
.
To set a relative time you must write myEvent.activateAt(System.currentTimeMillis() + delay);
public void activateAt(long date, long latest)
activateAt(long, long)
.date
- The time stamp.latest
- The latest time stamp where the event should be processed though it is deferred.
If the event is activated already for a earlier latest time, this argument is ignored.
The earlier latest time is valid. Use deactivate()
before this method to set the latest processing time newly.activateAt(long, long).
public void deactivate()
public long timeExecution()
public long timeExecutionLatest()
public boolean used()
protected final void doTimeElapsed()
EventTimerThread
if the time is elapsed.
EventWithDst.evDst()
is given the EventConsumer.processEvent(java.util.EventObject)
is called
though this instance may be a timeOrder. This method can enqueue this instance in another queue for execution
in any other thread which invokes then TimeOrder.doExecute()
.
TimeOrder
and the #evDst is not given by constructor
then the TimeOrder.doExecute()
is called to execute the time order.
activate(int)
etc. enqueues this instance newly
with a new time for elapsing. It is executed newly therefore.public int timeToExecution()