Package alpine.event.framework
Class BaseEventService
- java.lang.Object
-
- alpine.event.framework.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 Summary
Constructors Constructor Description BaseEventService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasSubscriptions(Event event)Determines if the specified event is able to be processed by the EventService.booleanisEventBeingProcessed(ChainableEvent event)Determines if the specified event is currently being processed.booleanisEventBeingProcessed(UUID chainIdentifier)Determines if the specified event is currently being processed.voidpublish(Event event)Publishes events.protected voidsetExecutorService(ExecutorService executor)protected voidsetLogger(Logger logger)voidshutdown()Shuts down the executioner.voidsubscribe(Class<? extends Event> eventType, Class<? extends Subscriber> subscriberType)Subscribes to an event.voidunsubscribe(Class<? extends Subscriber> subscriberType)Unsubscribes a subscriber.
-
-
-
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:
publishin interfaceIEventService- 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:
isEventBeingProcessedin interfaceIEventService- 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:
isEventBeingProcessedin interfaceIEventService- 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:
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
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:
unsubscribein interfaceIEventService- 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:
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
-
-