Class AbstractSharedEventDispatcher<T extends Event>

  • 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).
    All Implemented Interfaces:
    Callable<Boolean>

    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.

    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 Detail

      • sourceKeys

        protected final List<Serializable> sourceKeys
        The keys identifying the sharing event sources, that is, the data of the sharing event sources.
      • maxResults

        protected final Map<String,​Integer> maxResults
        The maximum amount of results each sharing event source awaits, null if there is no restriction.
      • emUris

        protected final URI[] emUris
        The URIs of the event manager used for the sharing event.
      • eventType

        protected final String eventType
        The event type used for the corresponding sharing event.
      • sourceType

        protected final String sourceType
        The event source type used for the corresponding sharing event.
      • sourceId

        protected final String sourceId
        The event source ID used for the corresponding sharing event.
      • hierSrcName

        protected final String hierSrcName
        The hierarchical name of the event source used for logging.
      • sharedEventString

        protected final String sharedEventString
        The string identifying the shared event (source). This is used for logging.
      • logger

        protected final Logger logger
        The logger for logging internal problems and behaviour.
    • Constructor Detail

      • 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 new Callable for 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 to null or 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 Detail

      • createNextEvent

        protected abstract T createNextEvent​(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.
        This will be called before EventHandler.handleEvent(Event, boolean).
        Parameters:
        maxResult - The maximum amount of result entries the next handled sharing event source expects. This may be null or 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_VALUE indicates the complete consumption of the result entries.
        Returns:
        The event to be handled by the next sharing event source or null to skip handling this event.
      • getConsumedResults

        protected abstract int getConsumedResults​(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. 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_VALUE indicates 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_VALUE indicates that all result entries have been consumed.