Class AbstractSharedEventDispatcher<T extends Event>
java.lang.Object
de.aristaflow.adept2.core.eventmanager.common.AbstractSharedEventDispatcher<T>
- Type Parameters:
T- The type of the (sharing) event, that is the one created for the handling by the sharing event sources. This is not the type of the shared event (provided by the shared event source).
public abstract class AbstractSharedEventDispatcher<T extends Event>
extends Object
implements Callable<Boolean>
This class provides the basic means for handling of shared events. These events are created by a
shared event source which combines several event sources that share a common configuration and
wait for a similar event. This avoids polling overhead. For instance several event sources need
to poll with the same SQL statement for results. The statement is regularly executed by the
shared event source while the event handling will be forwarded to the corresponding sharing event
sources (which are event handlers for the shared event source).
Instances of this class are responsible for dispatching a shared event created by a shared event source. It supports a windowing mechanism so that the event data may be reduced and the sharing event sources only get a partial result. This includes removal of consumed results.
All sharing event sources handle the event exclusively, that is, one event source after the other. for each event source a new (sharing) event will be created containing only the relevant results and only the maximum amount of results specified by the sharing event source. If a sharing event source (or rather the corresponding handlers) consume the event, the current results count as consumed. If there are more results in the original (shared) event, new results will be used for the event provided to the following event sources.
Instances of this class are responsible for dispatching a shared event created by a shared event source. It supports a windowing mechanism so that the event data may be reduced and the sharing event sources only get a partial result. This includes removal of consumed results.
All sharing event sources handle the event exclusively, that is, one event source after the other. for each event source a new (sharing) event will be created containing only the relevant results and only the maximum amount of results specified by the sharing event source. If a sharing event source (or rather the corresponding handlers) consume the event, the current results count as consumed. If there are more results in the original (shared) event, new results will be used for the event provided to the following event sources.
For logging purpose a sharedEventString will be used. This should identify the
shared event source, for instance the SQL statement executed by the shared event source.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final URI[]The URIs of the event manager used for the sharing event.protected final StringThe event type used for the corresponding sharing event.protected final StringThe hierarchical name of the event source used for logging.protected final LoggerThe logger for logging internal problems and behaviour.The maximum amount of results each sharing event source awaits,nullif there is no restriction.protected final StringThe string identifying the shared event (source).protected final StringThe event source ID used for the corresponding sharing event.protected final List<Serializable>The keys identifying the sharing event sources, that is, the data of the sharing event sources.protected final Collection<SharingSource<T>>All sharing event sources waiting for the same data/keys.protected final StringThe event source type used for the corresponding sharing event. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSharedEventDispatcher(List<Serializable> sourceKeys, Collection<SharingSource<T>> sources, Map<String, Integer> maxResults, URI[] emUris, String eventType, String sourceType, String sourceId, String hierSrcName, String sharedEventString, Logger logger) Creates a newCallablefor creating and forwarding shared events to a collection of sharing event sources interested in an event based on the very same event. -
Method Summary
Modifier and TypeMethodDescriptioncall()protected abstract TcreateNextEvent(Integer maxResult, int consumedRes) Creates the event for the next sharing event source with the designated amount of result entries and the designated amount of already consumed results.protected abstract intgetConsumedResults(int consumedRes, T event) Gets the amount of consumed results after the designated amount of results have been consumed together with the results in the designated sharing event.
-
Field Details
-
sourceKeys
The keys identifying the sharing event sources, that is, the data of the sharing event sources. -
sources
All sharing event sources waiting for the same data/keys. -
maxResults
The maximum amount of results each sharing event source awaits,nullif there is no restriction. -
emUris
The URIs of the event manager used for the sharing event. -
eventType
The event type used for the corresponding sharing event. -
sourceType
The event source type used for the corresponding sharing event. -
sourceId
The event source ID used for the corresponding sharing event. -
hierSrcName
The hierarchical name of the event source used for logging. -
logger
The logger for logging internal problems and behaviour.
-
-
Constructor Details
-
AbstractSharedEventDispatcher
protected AbstractSharedEventDispatcher(List<Serializable> sourceKeys, Collection<SharingSource<T>> sources, Map<String, Integer> maxResults, URI[] emUris, String eventType, String sourceType, String sourceId, String hierSrcName, String sharedEventString, Logger logger) Creates a newCallablefor creating and forwarding shared events to a collection of sharing event sources interested in an event based on the very same event.- Parameters:
sourceKeys- The keys identifying the sharing event sources, that is, the data of the sharing event sources.sources- All sharing event sources waiting for the same data/keys.maxResults- The maximum amount of results each sharing event source awaits. If a sharing event source has no limit, it may map tonullor be not in the map at all.emUris- The URIs of the event manager used for the corresponding sharing event.eventType- The event type used for the corresponding sharing event.sourceType- The event source type used for the corresponding sharing set event.sourceId- The event source ID used for the corresponding sharing event.hierSrcName- The hierarchical name of the event source used for logging.sharedEventString- The string identifying the shared event (source). This is used for logging.logger- The logger for logging internal problems and behaviour.
-
-
Method Details
-
call
-
createNextEvent
Creates the event for the next sharing event source with the designated amount of result entries and the designated amount of already consumed results.
This will be called beforeEventHandler.handleEvent(Event, boolean).- Parameters:
maxResult- The maximum amount of result entries the next handled sharing event source expects. This may benullor a non-positive value for no limit.consumedRes- The amount of already consumed results. If all results are consumed, implementations may decide on whether to notify all result entries or to finish handling the completely consumed event.Integer.MAX_VALUEindicates the complete consumption of the result entries.- Returns:
- The event to be handled by the next sharing event source or
nullto skip handling this event.
-
getConsumedResults
Gets the amount of consumed results after the designated amount of results have been consumed together with the results in the designated sharing event. This is called after a sharing event source has handled the event and signalled its consumption. In this case the window of available result entries usually has to be moved to the next result entries.
Integer.MAX_VALUEindicates the complete consumption of the result entries.- Parameters:
consumedRes- The amount of consumed results before the handling of the designated sharing event.event- The sharing event that has been handled and consumed by the last sharing event source.- Returns:
- Whether all result entries have been consumed yet and how many of them.
Integer.MAX_VALUEindicates that all result entries have been consumed.
-