public class EventWithDst
extends java.util.EventObject
EventObject
. It contains a reference to its destination, which should execute this event,
and to an instance which queues and forces the execution of the event (delegates to the destination).
+----UserEvent | | | -more_Data EventWithDst<|---+ Object<---source------| |-------evDstThread--->UML Presentation seeEventTimerThread_ifc
| |-------------evdst--->EventConsumer
| -dateCreation -dateOrder -stateOfEvent -ctConsumed -orderId
Docu_UML_simpleNotation
Modifier and Type | Field and Description |
---|---|
(package private) boolean |
bAwaitReserve |
protected int |
ctConsumed |
protected java.util.concurrent.atomic.AtomicLong |
dateCreation
Timestamp of the request.
|
(package private) int |
dateOrder |
(package private) EventConsumer |
evDst
The destination instance for the Event.
|
(package private) EventTimerThread_ifc |
evDstThread
The queue for events of the
EventTimerThread if this event should be used
in a really event driven system (without directly callback). |
protected long |
orderId
The commission number for the request, which may be answered by this event.
|
private static long |
serialVersionUID |
char |
stateOfEvent
State of the event:
0 or '
|
(package private) static java.text.SimpleDateFormat |
toStringDateFormat |
static java.lang.String |
version
Version, history and license.
|
Constructor and Description |
---|
EventWithDst()
Creates an event as a static object for re-usage.
|
EventWithDst(EventSource source,
EventConsumer consumer,
EventTimerThread_ifc thread)
Creates an event as static or dynamic object for usage.
|
EventWithDst(java.lang.Object source) |
Modifier and Type | Method and Description |
---|---|
void |
consumed()
This routine should be called after consuming the event.
|
java.util.Date |
dateCreation()
Returns the time stamp of creation or occupying the event.
|
EventConsumer |
evDst()
This method should only be called if the event should be processed.
|
EventConsumer |
getDst()
Returns the destination.
|
EventTimerThread_ifc |
getDstThread()
Returns the stored destination thread for queuing the event.
|
boolean |
hasDst() |
boolean |
isOccupied()
Returns true if the event is occupied.
|
(package private) void |
notifyDequeued()
Informs the
EventSource.notifyDequeued() , invoked on dequeuing. |
private void |
notifyShouldOccupyButInUse() |
boolean |
occupy(EventSource source,
boolean expect) |
boolean |
occupy(EventSource source,
EventConsumer dst,
EventTimerThread thread,
boolean expect)
Check whether this event is free and occupies it.
|
boolean |
occupy(int timeout,
EventSource evSrc,
EventConsumer dst,
EventTimerThread thread)
Try to occupy the event.
|
boolean |
occupyRecall(EventSource source,
boolean expect) |
boolean |
occupyRecall(EventSource source,
EventConsumer dst,
EventTimerThread thread,
boolean expect)
Try to occupy the event for usage, recall it if it is in stored in an event queue.
|
int |
occupyRecall(int timeout,
EventSource source,
boolean expect)
Try to occupy the event for usage, recall it if it is in stored in an event queue, wait till it is available, occupy a hanging event.
|
int |
occupyRecall(int timeout,
EventSource source,
EventConsumer dst,
EventTimerThread thread,
boolean expect)
Try to occupy the event for usage, recall a stored event in queue, wait till it is available and force occupying
on hanging.
|
void |
relinquish()
Relinquishes the event object.
|
boolean |
removeFromQueue()
Try to remove the event from the queue of the destination thread.
|
boolean |
sendEvent()
Sends the event again to the same destination with the same command.
|
void |
setDst(EventConsumer dst) |
void |
setOrderId(long order) |
void |
XXXdonotRelinquish()
Deprecated.
|
private static final long serialVersionUID
public static final java.lang.String version
EventCmdtypeWithBackEvent
with opponent and this class.
A simple event has not an opponent per default. This class is named EventWithDst yet because the destination
is the significant difference to its base class EventObject
.
occupy(int, EventSource, EventConsumer, EventTimerThread)
with timeout
occupyRecall(EventSource, boolean)
return 0,1,2, not boolean.
The state whether the recalled event is processed or it is only removed from the queued, may
be important for usage.
#Event(Enum)
to create an event for direct usage.
#cmde
does not need to be an Atomic, because dateCreation
is Atomic
to designate the occupy-state of the event.
#sendEventAgain()
for deferred events.
DateOrder
to log the date in milliseconds and the order as fine number.
The order of events should be known. The timestamp is imprecise!
occupy(EventSource, boolean)
#refData
. It is not the source (creator) of the event
but a value reference which may be used especially in the callback (#callback
).
Because it is private and the getter method #getRefData()
is duplicated, the
old routine #getSrc()
is deprecated, it is downward compatible still.
#owner
, #forceRelease()
.
It is a problem if a request may be crashed in a remote device, but the event is reserved
for answer in the proxy. It should be freed. Events may be re-used.
#use(long, int, Object, EventConsumer)
needs the dst as parameter.
#callbackThread
, #commisionId
instead order, more #data2
EventTimerThread_ifc evDstThread
EventTimerThread
if this event should be used
in a really event driven system (without directly callback).
If it is null, the dst. EventConsumer#processEvent(EventMsg)
should be called immediately.EventConsumer evDst
public char stateOfEvent
EventConsumer
and the EventTimerThread
is set, but the event
is not in send to the consumer. It is not in a queue and not in process.
boolean bAwaitReserve
protected int ctConsumed
protected long orderId
protected final java.util.concurrent.atomic.AtomicLong dateCreation
occupy(EventSource, boolean)
.
It is for new-obviating usage.int dateOrder
static final java.text.SimpleDateFormat toStringDateFormat
public EventWithDst(java.lang.Object source)
public EventWithDst()
#occupy(Object, EventConsumer, EventTimerThread)
before first usage. relinquish()
will be called on release the usage.public EventWithDst(EventSource source, EventConsumer consumer, EventTimerThread_ifc thread)
source
- Source of the event. If null then the event is not occupied, especially the dateCreation()
is set to 0. Use occupy(EventSource, boolean)
before usage. That is for a static instance.refData
- Associated data to the event. It is the source of the event.consumer
- The destination object for the event.thread
- an optional thread to store the event in an event queue, maybe null.public void setOrderId(long order)
@Deprecated public void XXXdonotRelinquish()
public EventConsumer evDst()
#donotRelinquish()
will be set to false, so that the event will be relinquished
except #donotRelinquish()
is called while processing the event.EventConsumer#processEvent(EventMsg)
.public java.util.Date dateCreation()
public boolean hasDst()
public void setDst(EventConsumer dst)
public boolean occupy(EventSource source, EventConsumer dst, EventTimerThread thread, boolean expect)
dateCreation()
is set, the event is occupied. In a target communication
with embedded devices often the communication resources are limited.
It means that only one order can be requested at one time, and the execution
should be awaited. The usage of an re-used event for such orders can be help to organize the
requests step by step. If the answer-event instance is in use, a request is pending.source
- Source instance able to use for monitoring the event life cycle. null is admissible.dst
- The destination instance which should receive this event.
If null, the dst given by constructor or the last given dst is used.thread
- A thread which queues the event. If null and dst !=null then the dst method
EventConsumer#processEvent(EventMsg)
is invoked in the current thread. If dst ==null this parameter is not used.expect
- If true and the event is not able to occupy, then the method EventSource.notifyShouldOccupyButInUse()
from the given source is invoked. It may cause an exception for example.public boolean occupy(int timeout, EventSource evSrc, EventConsumer dst, EventTimerThread thread)
timeout
- evSrc
- dst
- thread
- public boolean occupy(EventSource source, boolean expect)
public boolean occupyRecall(EventSource source, EventConsumer dst, EventTimerThread thread, boolean expect)
#occupyRecall(int, Object, EventConsumer, EventTimerThread)
.
source
- Source instance able to use for monitoring the event life cycle. null is admissible.dst
- The destination instance which should receive this event.
If null, the dst given by constructor or the last given dst is used.thread
- A thread which queues the event. If null and dst !=null then the dst method
EventConsumer#processEvent(EventMsg)
is invoked in the current thread. If dst ==null this parameter is not used.expect
- If true and the event is not able to occupy, then the method EventSource.notifyShouldOccupyButInUse()
from the given source is invoked. It may cause an exception for example.public boolean occupyRecall(EventSource source, boolean expect)
public int occupyRecall(int timeout, EventSource source, EventConsumer dst, EventTimerThread thread, boolean expect)
relinquish()
because the consumer process was aborted especially by an exception or there is any other error.
If the event was occupied a longer time before it is relinquished by this method and occupied newly.
dateCreation()
is forced to 0,
so the event is free now. Then it is occupied from this routine.
#occupyRecall(Object, EventConsumer, EventTimerThread)
.timeout
- maximal millisecond to wait if the event is yet in processing.source
- Source instance able to use for monitoring the event life cycle. null is admissible.dst
- The destination instance which should receive this event.
If null, the dst given by constructor or the last given dst is used.thread
- A thread which queues the event. If null and dst !=null then the dst method
EventConsumer#processEvent(EventMsg)
is invoked in the current thread. If dst ==null this parameter is not used.expect
- If true and the event is not able to occupy, then the method EventSource.notifyShouldOccupyButInUse()
from the given source is invoked. It may cause an exception for example.public int occupyRecall(int timeout, EventSource source, boolean expect)
occupyRecall(int, EventSource, EventConsumer, EventTimerThread, boolean)
but left the destination unchanged.timeout
- maximal millisecond to wait if the event is yet in processing.source
- Source instance able to use for monitoring the event life cycle. null is admissible.expect
- If true and the event is not able to occupy, then the method EventSource.notifyShouldOccupyButInUse()
from the given source is invoked. It may cause an exception for example.public boolean isOccupied()
occupyRecall(int, EventSource, boolean)
may be called to occupy it though.public EventTimerThread_ifc getDstThread()
public EventConsumer getDst()
public boolean removeFromQueue()
public void relinquish()
#occupy(Object, EventConsumer, EventTimerThread)
method.
The dateCreation
is set to 0 especially to designate the free-state of the Event instance.
The #refData
, evDst()
, evDstThread
and #opponent
are not changed
because the event may be reused in the same context.
All other data are reseted, so no unused references are hold.
Object.notify()
is called. See #occupyRecall(int)
and #occupyRecall(int, Object, EventConsumer, EventTimerThread)
.
#donotRelinquish()
was called inside the EventConsumer#processEvent(EventMsg)
for this event,
this method return without effect. This is helpfully if the event was stored in another queue for any reason.public boolean sendEvent()
public void consumed()
EventSource.notifyConsumed(int)
with this number if a source is given. Usual that is helpfully for debugging.void notifyDequeued()
EventSource.notifyDequeued()
, invoked on dequeuing.private void notifyShouldOccupyButInUse()