Package alpine.event.framework
Class BaseEventService
java.lang.Object
alpine.event.framework.BaseEventService
- All Implemented Interfaces:
IEventService
- Direct Known Subclasses:
EventService,SingleThreadedEventService
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanhasSubscriptions(Event event) Determines if the specified event is able to be processed by the EventService.booleanDetermines if the specified event is currently being processed.booleanisEventBeingProcessed(UUID chainIdentifier) Determines if the specified event is currently being processed.voidPublishes events.protected voidsetExecutorService(ExecutorService executor) protected voidvoidshutdown()Shuts down the executioner.booleanShuts down thisIEventService, and waits for already queued events to be processed until a giventimeoutelapses.voidsubscribe(Class<? extends Event> eventType, Class<? extends Subscriber> subscriberType) Subscribes to an event.voidunsubscribe(Class<? extends Subscriber> subscriberType) Unsubscribes a subscriber.
-
Constructor Details
-
BaseEventService
public BaseEventService()
-
-
Method Details
-
setExecutorService
- Parameters:
executor- an ExecutorService instance- Since:
- 1.0.0
-
setLogger
- Parameters:
logger- the logger instance to use for the executed event- Since:
- 1.0.0
-
publish
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:
publishin interfaceIEventService- Parameters:
event- An Event to publish- Since:
- 1.0.0
-
isEventBeingProcessed
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:
isEventBeingProcessedin interfaceIEventService- Parameters:
event- the event to query- Returns:
- a boolean
- Since:
- 1.4.0
-
isEventBeingProcessed
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:
isEventBeingProcessedin interfaceIEventService- Parameters:
chainIdentifier- the UUID of the event to query- Returns:
- a boolean
- Since:
- 1.4.0
-
subscribe
Subscribes to an event. Subscribes are automatically notified of all events for which they are subscribed.- Specified by:
subscribein interfaceIEventService- Parameters:
eventType- The type of event to subscribe tosubscriberType- The Subscriber that gets informed when the type of event is published- Since:
- 1.0.0
-
unsubscribe
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:
unsubscribein interfaceIEventService- Parameters:
subscriberType- The Subscriber to unsubscribe.- Since:
- 1.0.0
-
hasSubscriptions
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:
hasSubscriptionsin interfaceIEventService- 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:
shutdownin interfaceIEventService- Since:
- 1.0.0
-
shutdown
Shuts down thisIEventService, and waits for already queued events to be processed until a giventimeoutelapses.Events enqueued during shutdown will not be processed.
- Specified by:
shutdownin interfaceIEventService- Parameters:
timeout- TheDurationto wait for event processing to complete- Returns:
truewhen all queued events were processed prior totimeoutelapsing, otherwisefalse
-