public abstract class TimeOrder extends EventTimeout
executeOrder()
. An instance of this class can be created statically as persistent reference
or on demand with new TimeOrder#TimeOrder(String, EventTimerThread)
. The EventTimerThread
should
be existing as instance before an instance of this class is created.
EventThread thread = new EventThread("name"); ... //a time order as inner anonymous class: EventTimeOrder order = new EventTimeOrder("name", thread) { QOverride protected void executeOrder(){ ...code for time order } } ... thread.start(); order.activate(100); //the order will be executed in the thread in 100 ms.An EventTimeOrder can be enqueued in the EventThread but executed in another thread. It uses an
EventConsumer
, see TestTimeOrder
, with the following pattern:
private static class EnqueueInGraphicThread implements EventConsumer { QOverride public int processEvent(EventObject ev) { execThread.queueOrders.put((< EventTimeOrder >)ev); //casting admissible because special using. return mEventConsumed; } }This class is designated as EventObject because it can be used as event immediately after or independent whether it is handled by the timer.
TimeOrder#TimeOrder(String, EventTimerThread)
,
TimeOrder#TimeOrder(String, EventConsumer, EventTimerThread)
, TimeOrder(String)
.
EventTimeout
: EventTimeout.activate(int)
, EventTimeout.activateAt(long)
, EventTimeout.activateAt(long, long)
EventTimeout.deactivate()
EventTimeout
: EventTimeout.timeExecution()
, EventTimeout.timeExecutionLatest()
, EventTimeout.timeToExecution()
EventTimeout.used()
getCtDone(int)
doExecute()
will be called from the EventTimerThread
, only call by application in a special thread.
awaitExecution(int, int)
.
EventTimeout
.
EventTimerThread
StateMachine
Modifier and Type | Field and Description |
---|---|
private int |
ctDone |
int |
dbgctDone
It is counted only.
|
java.lang.String |
name
The name of the dispatch worker, used for debug at least.
|
private boolean |
reqCtDone
True if a thread waits, see
awaitExecution(int, int) . |
private static long |
serialVersionUID |
static java.lang.String |
version
Version and history.
|
dbgctWindup, timeExecution, timeExecutionLatest
bAwaitReserve, ctConsumed, dateCreation, dateOrder, evDst, evDstThread, orderId, stateOfEvent, toStringDateFormat
Constructor and Description |
---|
TimeOrder(java.lang.String name) |
TimeOrder(java.lang.String name,
EventConsumer dst,
EventTimerThread_ifc thread)
Initializes an time order for usage.
|
TimeOrder(java.lang.String name,
EventTimerThread_ifc thread)
Initializes an time order for usage.
|
Modifier and Type | Method and Description |
---|---|
boolean |
awaitExecution(int ctDoneRequested,
int timeout)
Waits for execution in any other thread.
|
void |
doExecute()
Executes and sets the execute state to false.
|
protected abstract void |
executeOrder()
Executes the order.
|
int |
getCtDone(int setCtDone)
Gets the information, how many times the routine is executed.
|
java.lang.String |
getStateInfo()
Returns the state of the consumer in a manual readable form.
|
java.lang.String |
toString()
Returns the name of this to show it for debugging.
|
activate, activateAt, activateAt, deactivate, doTimeElapsed, timeExecution, timeExecutionLatest, timeToExecution, used
consumed, dateCreation, evDst, getDst, getDstThread, hasDst, isOccupied, notifyDequeued, occupy, occupy, occupy, occupyRecall, occupyRecall, occupyRecall, occupyRecall, relinquish, removeFromQueue, sendEvent, setDst, setOrderId, XXXdonotRelinquish
private static final long serialVersionUID
public static final java.lang.String version
awaitExecution(int, int)
wait if the thread is busy. It should be done
especially if the order is in debug. Not ready checked yet whether it is well running.
OrderForList
#addToList(GralGraphicThread, int)
:
For time saving: If an instance is added already and its new execution time
is up to 5 ms later, nothing is done. It saves time for more as one call of this routine
in a fast loop.
#bAdded
==true
but it wasn't added, Therefore on #addToList(GralGraphicThread, int)
it is removed
from list and added newly. It is more save.
#removeFromList(GralGraphicThread)
. It is a better naming because it is removed from the queue
in the graphic thread. This class is only used in that queue.
name
to identify, proper for debugging
#addToList(GralGraphicThread, int)
and
#removeFromList(GralGraphicThread)
as thread-safe functions which
marks the instance as added (for delayed execution, for re-using).
public final java.lang.String name
private int ctDone
public int dbgctDone
private boolean reqCtDone
awaitExecution(int, int)
.public TimeOrder(java.lang.String name)
public TimeOrder(java.lang.String name, EventTimerThread_ifc thread)
EventTimeout.activate(int)
etc. to activate it.
EventTimeout.activateAt(long, long)
then the executeOrder()
is invoked in the thread. Note: Use TimeOrder#EventTimeOrderBase(String, EventConsumer, EventTimerThread)
if you want to execute the executeOrder()
routine in another thread.name
- the TimeOrder should have a name for debugging.thread
- thread to handle the time order. It is obligatory.public TimeOrder(java.lang.String name, EventConsumer dst, EventTimerThread_ifc thread)
EventTimeout.activate(int)
etc. to activate it.
EventTimeout.activateAt(long, long)
then the EventConsumer.processEvent(EventObject)
is invoked in the thread. This routine can store this instance in another queue of any other thread
to execute the executeOrder()
in any other thread.name
- the TimeOrder should have a name for debugging.dst
- The destination object for the event. If it is null then the overridden executeOrder()
will be executed if the time is expired. If given then EventConsumer.processEvent(EventObject)
is invoked in the given dst instance. The #executeOrder is not invoked. It can be used in the dst for own things.thread
- thread to handle the time order. It is obligatory.public java.lang.String getStateInfo()
protected abstract void executeOrder()
doExecute()
.public final void doExecute()
EventTimeout.activate(int)
etc. to activate the time order for execution.
executeOrder()
, it wraps it.
It is called inside the package private EventTimerThread
or from a special derived instance
which will be invoke executeOrder()
in any other thread.
EventTimeout.activate(int)
etc.public int getCtDone(int setCtDone)
setCtDone
- set the count for a new execution-counting. For example 0.public boolean awaitExecution(int ctDoneRequested, int timeout)
doExecute()
should be invoked to execute the time order
and notify this waiting routine. That is done if the EventTimerThread
is used.ctDoneRequested
- Number of executions requested.timeout
- maximal waiting time in milliseconds, 0 means wait forever.public java.lang.String toString()
toString
in class java.util.EventObject