public final class EventWithDst<T_Payload extends Payload,T_PayloadOpp extends Payload>
extends java.util.EventObject
EventObject
.
It contains a reference to its destination, which should execute this event,
and optional to an instance of EventThread_ifc
which is used as first destination to queue the events
and forces the execution (delegates to the destination).
The super class from java standard EventObject does only contain the reference to the source.
Object <--source-+ +---->UML Presentation seePayload
<|--T_Payload EventObject <|-+ | | | | -more_Data EventWithDst -d--+ | |-------evDstThread--->EventTimerThread_ifc
| |-------evDst--------->EventConsumer
| |-------evOpp--------->EventWithDst
-name -dateCreation -dateOrder -stateOfEvent -ctConsumed -orderId
Docu_UML_simpleNotation
Application evDst instance of EventConsumer +-->set any data | | to thisEvent payload | +-->sendEvent(thisEvent)------>| +--processEvent()
sendEvent(Object)
: emit the event to the dedicated evDst()
instance (given by construction or occupy(EventSource, EventConsumer, EventThread_ifc, boolean)
processEvent()
is called immediately in the same thread, it calls in the evDst instance: EventConsumer.processEvent(EventObject)
.
This can evaluate the data of the event.
FileRemote.mkdir(boolean, EventWithDst)
.
If the 'make dir' operation is executed in the same thread because it is a cheap operation on the local file system,
the 'Application' of the above sequence diagram is the 'mkdir' operation.
The EventConsumer
should be given with the event. It is only an instance, not related to another thread.
EventConsumer
More simple form, only using the payload:Application +-->do any which uses the event +-->set any data +<---------+ to thisEvent payload +<--read data | from the events payloadIn this also sensible case the event is only used to store some data. The called operation which uses the event fills some feedback data but don't send the event. The event instance is only used as data transporter. This is for example done if some operations of FileRemote such asFileRemote.mkdir(boolean, EventWithDst)
and the operation is executed in the same
... no the using operation should call anyway sendEvent and a #evDst should be available.
Note: If the message for this event was transferred via for example socket connection, its data of the derived "UserEvent" should be received as payload and reconstructed. The aggregated dataevDstThread
andevDst()
are set by initialization in the received environment.
Modifier and Type | Field and Description |
---|---|
(package private) boolean |
bAwaitReserve |
protected int |
ctConsumed |
(package private) T_Payload |
d
All data to this event, should be transferred via InterProcessComm.
|
protected java.util.concurrent.atomic.AtomicLong |
dateCreation
Timestamp of the request.
|
(package private) int |
dateOrder
Order of time stamps created in the same millisec of #dateCreation.
|
(package private) EventConsumer |
evDst
The destination instance for the Event.
|
(package private) EventThread_ifc |
evDstThread
The queue for events of the
EventThread_ifc if this event should be used
in a really event driven system (without directly callback). |
(package private) EventWithDst<T_PayloadOpp,T_Payload> |
evOpp
This is an associated event which can be used for the back direction.
|
(package private) EventSource |
evOwner |
java.lang.String |
name
The current owner of the event.
|
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.
|
Modifier | Constructor and Description |
---|---|
|
EventWithDst(java.lang.String name,
EventSource source,
EventConsumer consumer,
EventThread_ifc evThread,
T_Payload d)
Creates an event as static or dynamic object for usage.
|
private |
EventWithDst(java.lang.String name,
EventSource source,
EventConsumer consumer,
EventThread_ifc evThread,
T_Payload d,
EventWithDst<T_PayloadOpp,T_Payload> evOpp)
Only used in
EventWithDst(String, EventSource, EventConsumer, EventThread_ifc, Payload, String, EventSource, EventConsumer, EventThread_ifc, Payload)
to create the opponent itself with this as reference. |
|
EventWithDst(java.lang.String name,
EventSource source,
EventConsumer consumer,
EventThread_ifc evThread,
T_Payload d,
java.lang.String nameOpp,
EventSource sourceOpp,
EventConsumer consumerOpp,
EventThread_ifc evThreadOpp,
T_PayloadOpp dOpp)
Creates an event as static or dynamic object for usage with its opponent event
with a given opponent event.
|
|
EventWithDst(java.lang.String name,
EventSource source,
EventConsumer consumer,
EventThread_ifc evThread,
T_Payload d,
T_PayloadOpp dOpp)
Creates an event as static or dynamic object for usage with its opponent event.
|
|
EventWithDst(java.lang.String name,
java.lang.Object source,
T_Payload data) |
|
EventWithDst(java.lang.String name,
java.lang.Object source,
T_Payload data,
EventWithDst<T_PayloadOpp,T_Payload> evOpp) |
|
EventWithDst(java.lang.String name,
T_Payload data)
Creates an event as a static object for re-usage.
|
|
EventWithDst(java.lang.String name,
T_Payload data,
EventWithDst<T_PayloadOpp,T_Payload> evOpp) |
Modifier and Type | Method and Description |
---|---|
void |
clean() |
protected void |
cleanData()
This is an empty operation for the basic event.
|
T_Payload |
data() |
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.
|
EventThread_ifc |
getDstThread()
Returns the stored destination thread for queuing the event.
|
EventWithDst<T_PayloadOpp,T_Payload> |
getOpponent() |
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,
EventThread_ifc thread,
boolean expect)
Check whether this event is free and occupies it.
|
boolean |
occupy(int timeout,
EventSource evSrc,
EventConsumer dst,
EventThread_ifc thread)
Try to occupy the event.
|
boolean |
occupyRecall(EventSource source,
boolean expect) |
boolean |
occupyRecall(EventSource source,
EventConsumer dst,
EventThread_ifc 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,
EventThread_ifc 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.
|
int |
processEvent()
Applies the event to its
evDst() to processes it (EventConsumerprocessEvent() )
On #sendEvent() this operation is called immediately if the #evDstThread is not set. |
void |
relinquish()
Relinquishes the event object.
|
boolean |
removeFromQueue()
Try to remove the event from the queue of the destination thread.
|
boolean |
sendEvent(java.lang.Object source)
Sends the event to the given destination.
|
void |
setDst(EventConsumer dst) |
void |
setOrderId(long order) |
(package private) void |
setSource(java.lang.Object src) |
void |
XXXdonotRelinquish()
Deprecated.
|
private static final long serialVersionUID
public static final java.lang.String version
evOpp
was not used till now.
d
is now typed with the new interface Payload
.
For serialize of the payload some thinking should be done.
EventObject.source
: originally it should be the creator of the event.
But intrinsic it should be the instance which emits the event. The last one is only important on debugging.
It is interesting on receiving from a queue, from where comes the event.
Intrinsically it should show a __FILE__ and __LINE__ (as in C) to see where the event was emitted.
That may be possible with StackTrace entries. Yet only sometimes a string is stored for that reason.
The source is filled as argument now on sendEvent(Object)
.
The up to now usage of source as the owner of the event is now stored in evOwner
in this class.
evOpp
is now contained here.
It is null if a back event is not given.
TimeOrder
is no more aggregated, but the TimeOrder aggregates its event.
EventConsumer
can decide about the thread.
occupy(EventSource, EventConsumer, EventThread_ifc, boolean)
is related only to the dateCreation
and not to the evDst
The evDst()
can be determined by construction, as well as the EventObject.source
.
#timeOrder
as possible aggreation (on construction) with the proper ctor:
#EventWithDst(String, EventTimerThread_ifc, EventSource, EventConsumer, EventThread_ifc)
name
, helps on debug
EventThread_ifc
.
this has less impact on usage.
#bStaticOccupied
: now eventually clarified, necessary using occupy or not.
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, EventThread_ifc)
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
public final java.lang.String name
EventSource evOwner
EventThread_ifc evDstThread
EventThread_ifc
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
T_Payload extends Payload d
final EventWithDst<T_PayloadOpp extends Payload,T_Payload extends Payload> evOpp
public char stateOfEvent
EventConsumer
and the EventThread_ifc
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.String name, T_Payload data)
#occupy(Object, EventConsumer, EventThread_ifc)
before first usage. relinquish()
will be called on release the usage.name
- of the event used only for debug.public EventWithDst(java.lang.String name, T_Payload data, EventWithDst<T_PayloadOpp,T_Payload> evOpp)
public EventWithDst(java.lang.String name, java.lang.Object source, T_Payload data)
public EventWithDst(java.lang.String name, java.lang.Object source, T_Payload data, EventWithDst<T_PayloadOpp,T_Payload> evOpp)
public EventWithDst(java.lang.String name, EventSource source, EventConsumer consumer, EventThread_ifc evThread, T_Payload d)
name
- of the event used only for debug.source
- Source of the event.consumer
- If null then the event should be occupied before usage.
If given occupy(EventSource, boolean)
is not necessary for usage but possible.thread
- an optional thread to store the event in an event queue, maybe null.
If null but the EventConsumer.evThread()
returns not null, it is used.
It means the EventConsumer
can decide about the event thread.
But this argument is used if given.d
- the instance for the payload for this event. If the event is transmitted via a medium,
the payload will be serialized.public EventWithDst(java.lang.String name, EventSource source, EventConsumer consumer, EventThread_ifc evThread, T_Payload d, T_PayloadOpp dOpp)
EventConsumer
and without a specified event thread.
It means the opponent event can be used in a specific kind (for example to transmit the data)
or this information should be given using occupy(EventSource, EventConsumer, EventThread_ifc, boolean)
.
But the payload for the opponent is referenced if the dOpp argument is not null.name
- of the event used only for debug. The opponent gets the name + "~".source
- Source of the event. Can be null, then a default source is used, or can be also a string literal.consumer
- If null then the event should be occupied before usage.
If given occupy(EventSource, boolean)
is not necessary for usage but possible.thread
- an optional thread to store the event in an event queue, maybe null.
If null but the EventConsumer.evThread()
returns not null, it is used.
It means the EventConsumer
can decide about the event thread.
But this argument is used if given.d
- the instance for the payload for this event. If the event is transmitted via a medium,
the payload will be serialized.dOpp
- the instance for the payload for the opponent of the event. If the event is transmitted via a medium,
the payload will be serialized. This instance is then used as destination for deserialize.private EventWithDst(java.lang.String name, EventSource source, EventConsumer consumer, EventThread_ifc evThread, T_Payload d, EventWithDst<T_PayloadOpp,T_Payload> evOpp)
EventWithDst(String, EventSource, EventConsumer, EventThread_ifc, Payload, String, EventSource, EventConsumer, EventThread_ifc, Payload)
to create the opponent itself with this as reference.
If this class would be used in an application the opponent would not refer its mutual opponent.
Hence it is private.name
- fed with the nameOppsource
- consumer
- evThread
- d
- evOpp
- thispublic EventWithDst(java.lang.String name, EventSource source, EventConsumer consumer, EventThread_ifc evThread, T_Payload d, java.lang.String nameOpp, EventSource sourceOpp, EventConsumer consumerOpp, EventThread_ifc evThreadOpp, T_PayloadOpp dOpp)
EventConsumer
, EventThread_ifc
and Payload
.
The implementation type of Payload should match the T_PayloadOpp in this class and vice versa.name
- of the event used only for debug. The opponent gets the name + "~".source
- Source of the event. Can be null, then a default source is used, or can be also a string literal.consumer
- If null then the event should be occupied before usage.
If given occupy(EventSource, boolean)
is not necessary for usage but possible.thread
- an optional thread to store the event in an event queue, maybe null.
If null but the EventConsumer.evThread()
returns not null, it is used.
It means the EventConsumer
can decide about the event thread.
But this argument is used if given.d
- the instance for the payload for this event. If the event is transmitted via a medium,
the payload will be serialized.opponent
- Already created opponent first as event without opponent.
The type of Payload
(generic types of this class) should match.void setSource(java.lang.Object src)
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 T_Payload data()
public java.util.Date dateCreation()
public boolean hasDst()
public void setDst(EventConsumer dst)
protected void cleanData()
public void clean()
public boolean occupy(EventSource source, EventConsumer dst, EventThread_ifc 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, stored in evDstThread
.
If null, then the given thread by constructor or the last given thread is used.
If null and dst !=null then the EventConsumer.evThread()
is used, but it can be also null.
If the evDstThread
remains null, then the event is used as callback,
the EventConsumer.processEvent(EventObject)
is immediately called on #sendEvent()
.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, EventThread_ifc thread)
timeout
- evSrc
- dst
- thread
- public boolean occupy(EventSource source, boolean expect)
public boolean occupyRecall(EventSource source, EventConsumer dst, EventThread_ifc thread, boolean expect)
#occupyRecall(int, Object, EventConsumer, EventThread_ifc)
.
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, EventThread_ifc 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, EventThread_ifc)
.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, EventThread_ifc, 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 EventThread_ifc getDstThread()
public EventConsumer getDst()
public EventWithDst<T_PayloadOpp,T_Payload> getOpponent()
public boolean removeFromQueue()
public void relinquish()
#occupy(Object, EventConsumer, EventThread_ifc)
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, EventThread_ifc)
.
#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(java.lang.Object source)
evDstThread
is given on construction or on occupy(int, EventSource, EventConsumer, EventThread_ifc)
then the event is stored in the queue of this thread to execute it using EventThread_ifc.storeEvent(EventObject)
.
EventConsumer.processEvent(EventObject)
is called to execute the event in the current thread.
EventSource
is informed if the event is processed,
see description of EventConsumer.processEvent(EventObject)
.
It means, if the event is applied or processed, it is free for further usage or it can contain back information,
then it should be evaluated and freed by the application. This is decided with the return value of the processEvent operation.
evDst()
must no == null, should be given by construction with EventWithDst#EventWithDst(String, EventSource, EventConsumer, EventThread_ifc)
or by occupy(EventSource, EventConsumer, EventThread_ifc, boolean)
. If it is null, an exception is thrown.public int processEvent()
evDst()
to processes it (EventConsumerprocessEvent()
)
On #sendEvent()
this operation is called immediately if the #evDstThread is not set. For callback like events.
This operation should not be called immediately from the user, call #sendEvent()
,
but it is equal to #sendEvent()
if no thread is given.
It is called from EventTimerThread
and it is intent to call from other event queue organizations.void notifyDequeued()
EventSource.notifyDequeued()
, invoked on dequeuing.private void notifyShouldOccupyButInUse()