public class TimeOrder extends EventSource
EventTimerThread
or another implementation using EventTimerThread_ifc
.
It is also used for the vishia graphical programming (GRAL) referenced in org.vishia.gral.base.GralGraphicOrder
and also for FileRemoteProgressEvData
.
It is referenced by EventWithDst#timeOrder
and only constructed in that class
calling EventWithDst#EventWithDst(String, EventTimerThread_ifc, EventSource, EventConsumer, EventThread_ifc)
or enhanced classes from EventWithDst
if the event should be delayed.
EventCmdtype
with TimeOrderCmd
is used inside StateMachine
as persistent instance
of any parallel state machine or of the top state if timeouts are used in the states.
myEvent.timeOrder.activate(7000); //activate execution of the event in 7 seconds.
TimeOrder#TimeEntry(String, EventTimerThread_ifc, EventWithDst)
.
activate(int)
, activateAt(long)
, activateAt(long, long)
deactivate()
timeExecution()
, timeExecutionLatest()
, timeToExecution()
used()
EventTimerThread
StateMachine
Modifier and Type | Field and Description |
---|---|
protected boolean |
bAwaiting
Set if
#awaitExecution(int, int) is called. |
private boolean |
bCyclic
If this bit is set,
repeatCyclic() activates again. |
protected boolean |
bEventException
True if
EventConsumer.processEvent(java.util.EventObject) has returned the bit EventConsumer.mEventConsumerException . |
protected boolean |
bEventExecuted
True if
EventConsumer.processEvent(java.util.EventObject) has returned the bit EventConsumer.mEventConsumed . |
protected boolean |
bHoldTimeorder
If true then the current active time order should not be send as event if the time is expired,
because some data are changed.
|
protected boolean |
bNotifyAlsoOnException |
protected boolean |
bTimeElapsed |
protected boolean |
bTimeOrderFinished
True if
EventConsumer.processEvent(java.util.EventObject) has returned the bit EventConsumer.mEventConsumFinished . |
protected int |
ctConsumed |
int |
dbgctWindup
It is counted only.
|
protected EventWithDst |
event |
java.lang.String |
name |
private static long |
serialVersionUID |
private int |
timeCycle
The cycle of execution for the first time and cyclic.
|
private int |
timeCycleFirst
The cycle of execution for the first time and cyclic.
|
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. |
EventTimerThread_ifc |
timerThread |
static java.lang.String |
version
Version and history:
2023-03-12 new:
bHoldTimeorder , hold() to change data, prevent processing in EventTimerThread
2023-02-21 new: activateCyclic() . |
nullSource
Constructor and Description |
---|
TimeOrder(java.lang.String name,
EventTimerThread_ifc timerThread,
EventSource src,
EventConsumer consumer,
EventThread_ifc evThread)
Constructs a time order for usage.
|
TimeOrder(java.lang.String name,
EventTimerThread_ifc timerThread,
EventWithDst event)
Construction of a time order with any desired specific event to execute.
|
Modifier and Type | Method and Description |
---|---|
void |
activate(int millisec)
Activate the time order to send the event for the given laps of time.
|
void |
activateAt(long date)
Enters the TimeEntry to activates the event to the given timestamp.
|
void |
activateAt(long executionTime,
long latest)
Enters the TimeEntry to activates the event to the given timestamp with a given latest time stamp.
|
void |
activateCyclic()
Activate the time order for the first time from the source of the event.
|
void |
clear()
Clears the order, set to 0 all data excluded
timeCycleFirst and timeCycle
and removes the order from the queue and also a pending event from the queue. |
void |
deactivate()
Remove this from the queue of timer events and orders
|
EventWithDst |
event() |
boolean |
hold()
Prevent activating a time order because some data may be changed just now.
|
boolean |
isExecuted()
Quest whether the time order was finished executing.
|
void |
notifyConsumed(int state)
This operation should not called by the user.
|
(package private) void |
repeatCyclic()
Repeat activating the time order with the cycle.
|
void |
setCycle(int first,
int cycle)
Sets the cycle of the event for
activateCyclic() . |
(package private) void |
setEvent(EventWithDst event) |
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() |
boolean |
XXXawaitExecution(int timeout,
boolean bAlsoOnException)
Waits for execution in any other thread.
|
notifyDequeued, notifyRelinquished, notifyShouldOccupyButInUse, notifyShouldSentButInUse, notifyUnexpectedException, toString
public static final java.lang.String version
bHoldTimeorder
, hold()
to change data, prevent processing in EventTimerThread
activateCyclic()
. The approach is, that the activating must not initiate from the receiver
because in a remote situation (network device) the receiver has no access to the TimeOrder.
Instead the sender should do it. Hence the setCycle(int, int)
should be called on time to determine the cycle.
The activateCyclic()
should be called only one time if the sender gets active.
The repeatCyclic()
is set by the EventTimerThread
if one event is fired.
clear()
or deactivate()
removes this repeatCyclic()
behavior.
EventWithDst
if necessary.
It aggregates the event by itself. Execution is done only via the event()
and its EventWithDst.evDst
.
activateAt(long, long)
while searching the problem
that the execution sometimes hangs. Now it does not hang since ~10 min , but the reason is not fully clarified.
Before, the problem was that the thread has used its 10 seconds waiting time if the event queue is empty.
It seems to be a missing notify(), but the notify() was programmed.
The problem occurs in the Gral vishiaGui with CurveView for redraw events.
TimeOrder
and as event for timeout for state machines.
private static final long serialVersionUID
public final java.lang.String name
protected EventWithDst event
public final EventTimerThread_ifc timerThread
private int timeCycleFirst
private int timeCycle
private boolean bCyclic
repeatCyclic()
activates again.protected long timeExecution
protected long timeExecutionLatest
activateAt(long)
while it is activated already.protected boolean bAwaiting
#awaitExecution(int, int)
is called.
It means a thread is waiting. this.notify() is necessary.protected boolean bHoldTimeorder
protected boolean bNotifyAlsoOnException
protected boolean bTimeElapsed
protected boolean bEventException
EventConsumer.processEvent(java.util.EventObject)
has returned the bit EventConsumer.mEventConsumerException
.protected int ctConsumed
protected boolean bEventExecuted
EventConsumer.processEvent(java.util.EventObject)
has returned the bit EventConsumer.mEventConsumed
.protected boolean bTimeOrderFinished
EventConsumer.processEvent(java.util.EventObject)
has returned the bit EventConsumer.mEventConsumFinished
.public int dbgctWindup
public TimeOrder(java.lang.String name, EventTimerThread_ifc timerThread, EventSource src, EventConsumer consumer, EventThread_ifc evThread)
name
- for debugging and logtimerThread
- where the time entry should be used in, it is determined.src
- the event is occupied with this given EventSource instance.consumer
- The destination object for the event. If it is null nothing will be executed if the event is expired.
But you can set the consumer with #occupy(EventSource, EventConsumer, EventThread_ifc, boolean)
or with #setDst(EventConsumer)
afterwardsevThread
- if null, then the event is handled by the same thread as the timerThread, immediately after expire.
It means the timeout is handled before the other queued events are handled. This is important for state machine.
It means if a timeout transition has its timeout, then this is prior.
EventConsumer.processEvent(java.util.EventObject)
it is queued in the other thread
and there executed.
With this approach a central timer can be used for several statemachine threads.public TimeOrder(java.lang.String name, EventTimerThread_ifc timerThread, EventWithDst event)
EventWithDst#EventWithDst(String, EventTimerThread_ifc, EventSource, EventConsumer, EventThread_ifc)
.
It means the user constructs the event with time order (any derived event type),
and the ctor of the event calls this ctor to organize a bidirectional aggregation.name
- for debugging and logtimerThread
- where the time entry should be used in, if null use the event's thread.event
- The event for execution.java.lang.IllegalArgumentException
- if timerThread argument is null and the event do not refer an EventTimerThread_ifcvoid setEvent(EventWithDst event)
public void setCycle(int first, int cycle)
activateCyclic()
.
If this operation is never called, the initial values are valid.first
- Milliseconds from activateCyclic()
to the first invocation, default 1 ms.cycle
- Milliseconds for repeated call, used from repeatCyclic()
.public EventWithDst event()
public void clear()
timeCycleFirst
and timeCycle
and removes the order from the queue and also a pending event from the queue.
If any thread has called #awaitExecution(int, boolean)
this thread is notified firstly to prevent a hanging thread.public final void activateCyclic()
activate(int)
with the first time set on setCycle(int, int)
, default 1 ms.final void repeatCyclic()
activate(int)
with the timeCycle
.public final boolean hold()
activate(int)
should be called to activate again.activate(int)
should be called anyway.public final 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 final void activateAt(long date)
activateAt(long, long)
.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 final void activateAt(long executionTime, long latest)
activateAt(long)
or activate(int)
.
If the event is activated already for a shorter time, then the activation time is deferred to this given time
but not later than a latest time given with activateAt(long, long)
.
executionTime
- The time stamp for desired execution, can be delayed on second calls.latest
- The latest time stamp where the event should be processed though it is delayed.
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).
public final void deactivate()
public final long timeExecution()
public final long timeExecutionLatest()
public final boolean used()
public final boolean isExecuted()
bEventExecuted
.public void notifyConsumed(int state)
EventSource
from the event management classes, especially EventTimerThread
or adequate implementations of EventThread_ifc
if EventConsumer.processEvent(java.util.EventObject)
is returned.notifyConsumed
in class EventSource
state
- the return value of processEvent, bits 31..24 is the EventWithDst.ctConsumed
.public final int timeToExecution()
public boolean XXXawaitExecution(int timeout, boolean bAlsoOnException)
ctDoneRequested
- Number of executions requested.timeout
- maximal waiting time in milliseconds, 0 means wait forever.