Class BaseEventService

  • All Implemented Interfaces:
    IEventService
    Direct Known Subclasses:
    EventService, SingleThreadedEventService

    public abstract class BaseEventService
    extends Object
    implements IEventService
    A publish/subscribe (pub/sub) event service that provides the ability to publish events and asynchronously inform all subscribers to subscribed events. Defaults to a single thread event system when extending this class. This can be changed by specifying an alternative executor service.
    Since:
    1.0.0
    Author:
    Steve Springett
    • Constructor Detail

      • BaseEventService

        public BaseEventService()
    • Method Detail

      • setExecutorService

        protected void setExecutorService​(ExecutorService executor)
        Parameters:
        executor - an ExecutorService instance
        Since:
        1.0.0
      • setLogger

        protected void setLogger​(Logger logger)
        Parameters:
        logger - the logger instance to use for the executed event
        Since:
        1.0.0
      • publish

        public void publish​(Event event)
        Publishes events. Published events will get dispatched to all subscribers in the order in which they subscribed. Subscribers are informed asynchronously one after the next.
        Specified by:
        publish in interface IEventService
        Parameters:
        event - An Event to publish
        Since:
        1.0.0
      • isEventBeingProcessed

        public boolean isEventBeingProcessed​(ChainableEvent event)
        Determines if the specified event is currently being processed. Processing may indicate the the subscriber task is in the queue and work has not started yet, or may indicate the task is currently being executed. When this event returns false, it does not indicate completion, only that there are no subscriber tasks waiting or working on the specified event.
        Specified by:
        isEventBeingProcessed in interface IEventService
        Parameters:
        event - the event to query
        Returns:
        a boolean
        Since:
        1.4.0
      • isEventBeingProcessed

        public boolean isEventBeingProcessed​(UUID chainIdentifier)
        Determines if the specified event is currently being processed. Processing may indicate the the subscriber task is in the queue and work has not started yet, or may indicate the task is currently being executed. When this event returns false, it does not indicate completion, only that there are no subscriber tasks waiting or working on the specified event.
        Specified by:
        isEventBeingProcessed in interface IEventService
        Parameters:
        chainIdentifier - the UUID of the event to query
        Returns:
        a boolean
        Since:
        1.4.0
      • subscribe

        public void subscribe​(Class<? extends Event> eventType,
                              Class<? extends Subscriber> subscriberType)
        Subscribes to an event. Subscribes are automatically notified of all events for which they are subscribed.
        Specified by:
        subscribe in interface IEventService
        Parameters:
        eventType - The type of event to subscribe to
        subscriberType - The Subscriber that gets informed when the type of event is published
        Since:
        1.0.0
      • unsubscribe

        public void unsubscribe​(Class<? extends Subscriber> subscriberType)
        Unsubscribes a subscriber. All event types the subscriber has subscribed to will be unsubscribed. Once unsubscribed, the subscriber will no longer be informed of published events.
        Specified by:
        unsubscribe in interface IEventService
        Parameters:
        subscriberType - The Subscriber to unsubscribe.
        Since:
        1.0.0
      • hasSubscriptions

        public boolean hasSubscriptions​(Event event)
        Determines if the specified event is able to be processed by the EventService. If a subscriber exists for the event type, this method will return true, otherwise false.
        Specified by:
        hasSubscriptions in interface IEventService
        Parameters:
        event - the event to query if subscribers exist
        Returns:
        true if the event has subscribers, false it not
        Since:
        1.2.0
      • shutdown

        public void shutdown()
        Shuts down the executioner. Once shut down, future work will not be performed. This should only be called prior to the application being shut down.
        Specified by:
        shutdown in interface IEventService
        Since:
        1.0.0