Module org.refcodes.eventbus
Package org.refcodes.eventbus
Class AbstractEventBus<EVT extends EventBrokerEvent<?>,O extends org.refcodes.observer.Observer<EVT>,MATCH extends EventBrokerEventMatcher<EVT>,META extends org.refcodes.observer.EventMetaData,H>
java.lang.Object
org.refcodes.eventbus.AbstractEventBus<EVT,O,MATCH,META,H>
- Type Parameters:
EVT
- the element typeO
- the generic typeMATCH
- the generic typeMETA
- the generic typeH
- the generic type
- All Implemented Interfaces:
Destroyable
,org.refcodes.component.HandleLookup<H,
,O> DispatchStrategyAccessor
,EventBusObservable<EVT,
,O, MATCH, H> EventBusPublisher<EVT>
,EventDispatcher<EVT,
,O, MATCH, META, H> org.refcodes.matcher.Matchable<EVT>
,org.refcodes.observer.Publisher<EVT>
- Direct Known Subclasses:
EventBus
public abstract class AbstractEventBus<EVT extends EventBrokerEvent<?>,O extends org.refcodes.observer.Observer<EVT>,MATCH extends EventBrokerEventMatcher<EVT>,META extends org.refcodes.observer.EventMetaData,H>
extends Object
implements EventDispatcher<EVT,O,MATCH,META,H>, Destroyable
The Class AbstractEventBus.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.refcodes.eventbus.DispatchStrategyAccessor
DispatchStrategyAccessor.DispatchStrategyMutator, DispatchStrategyAccessor.DispatchStrategyProperty
-
Constructor Summary
ConstructorDescriptionAbstractEventBus
(boolean isDaemon, org.refcodes.component.HandleGenerator<H> aHandleGenerator) Constructs theAbstractEventBus
with theDispatchStrategy
beingDispatchStrategy.CASCADE
when publishing events and the given handle generator.AbstractEventBus
(org.refcodes.component.HandleGenerator<H> aHandleGenerator) Constructs theAbstractEventBus
with theDispatchStrategy
beingDispatchStrategy.CASCADE
when publishing events and the given handle generator, anyThread
instances created are created as daemon threads.AbstractEventBus
(org.refcodes.component.HandleGenerator<H> aHandleGenerator, ExecutorService aExecutorService) Constructs theAbstractEventBus
with theDispatchStrategy
beingDispatchStrategy.CASCADE
when publishing events and the given handle generator.AbstractEventBus
(DispatchStrategy aDispatchStrategy, boolean isDaemon, org.refcodes.component.HandleGenerator<H> aHandleGenerator) Constructs theAbstractEventBus
with the givenDispatchStrategy
when publishing events and the given handle generator.AbstractEventBus
(DispatchStrategy aDispatchStrategy, org.refcodes.component.HandleGenerator<H> aHandleGenerator) Constructs theAbstractEventBus
with the givenDispatchStrategy
when publishing events and the given handle generator, anyThread
instances created are created as daemon threads.AbstractEventBus
(DispatchStrategy aDispatchStrategy, org.refcodes.component.HandleGenerator<H> aHandleGenerator, ExecutorService aExecutorService) Constructs theAbstractEventBus
with the givenDispatchStrategy
when publishing events and the given handle generator. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
cascadeDispatch
(EVT aEvent, Object aMonitor) Hook implementing the cascaded dispatch method as ofDispatchStrategy.CASCADE
.void
destroy()
Shuts down anyExecutorService
by callingExecutorService.shutdown()
causing theEventDispatcher
to be disposed.Retrieves theDispatchStrategy
property from the property.boolean
boolean
isMatching
(EVT aEvent) lookupHandle
(H aHandle) protected void
parallelDispatch
(EVT aEvent) Hook implementing the parallel dispatch method as ofDispatchStrategy.PARALLEL
.void
publishEvent
(EVT aEvent, DispatchStrategy aDispatchStrategy) Publishes an event using the givenDispatchStrategy
.removeHandle
(H aHandle) protected void
sequentialDispatch
(EVT aEvent) Hook implementing the sequential dispatch method as ofDispatchStrategy.SEQUENTIAL
.Subscribes a listener to the event bus.void
unsubscribeAll
(O aObserver) Unsubscribes all registrations to a specific listener, even if that listener is involved in several subscriptions.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.security.auth.Destroyable
isDestroyed
Methods inherited from interface org.refcodes.eventbus.EventBusObservable
subscribe, subscribe
Methods inherited from interface org.refcodes.eventbus.EventDispatcher
onAction, onAction, onActions, onActions, onAlias, onAlias, onCatchAll, onChannel, onChannel, onEvent, onEvent, onEvent, onEvent, onEvent, onEvent, onEvent, onEvent, onEvent, onEvent, onEvent, onEvent, onEvent, onEvent, onGroup, onGroup, onType, onUniversalId, onUniversalId, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent, publishEvent
-
Constructor Details
-
AbstractEventBus
public AbstractEventBus(boolean isDaemon, org.refcodes.component.HandleGenerator<H> aHandleGenerator) Constructs theAbstractEventBus
with theDispatchStrategy
beingDispatchStrategy.CASCADE
when publishing events and the given handle generator. -
AbstractEventBus
Constructs theAbstractEventBus
with theDispatchStrategy
beingDispatchStrategy.CASCADE
when publishing events and the given handle generator, anyThread
instances created are created as daemon threads.- Parameters:
aHandleGenerator
- The handle generator to be used.
-
AbstractEventBus
public AbstractEventBus(org.refcodes.component.HandleGenerator<H> aHandleGenerator, ExecutorService aExecutorService) Constructs theAbstractEventBus
with theDispatchStrategy
beingDispatchStrategy.CASCADE
when publishing events and the given handle generator.- Parameters:
aHandleGenerator
- The handle generator to be used.aExecutorService
- TheExecutorService
to be used when creating threads.
-
AbstractEventBus
public AbstractEventBus(DispatchStrategy aDispatchStrategy, org.refcodes.component.HandleGenerator<H> aHandleGenerator) Constructs theAbstractEventBus
with the givenDispatchStrategy
when publishing events and the given handle generator, anyThread
instances created are created as daemon threads.- Parameters:
aDispatchStrategy
- TheDispatchStrategy
to be used when publishing events.aHandleGenerator
- The handle generator to be used.
-
AbstractEventBus
public AbstractEventBus(DispatchStrategy aDispatchStrategy, boolean isDaemon, org.refcodes.component.HandleGenerator<H> aHandleGenerator) Constructs theAbstractEventBus
with the givenDispatchStrategy
when publishing events and the given handle generator.- Parameters:
aDispatchStrategy
- TheDispatchStrategy
to be used when publishing events.isDaemon
- True when to create daemon dispatchThread
instances (shutdown upon last applicationThread
shutdown), else applicationThread
instances are created for dispatch.aHandleGenerator
- The handle generator to be used.
-
AbstractEventBus
public AbstractEventBus(DispatchStrategy aDispatchStrategy, org.refcodes.component.HandleGenerator<H> aHandleGenerator, ExecutorService aExecutorService) Constructs theAbstractEventBus
with the givenDispatchStrategy
when publishing events and the given handle generator.- Parameters:
aDispatchStrategy
- TheDispatchStrategy
to be used when publishing events.aHandleGenerator
- The handle generator to be used.aExecutorService
- TheExecutorService
to be used when creating threads.
-
-
Method Details
-
isMatching
- Specified by:
isMatching
in interfaceorg.refcodes.matcher.Matchable<EVT extends EventBrokerEvent<?>>
-
subscribe
Subscribes a listener to the event bus. In case the handle is being ignored, use the "unsubscribeAll" method where all subscriptions for a listener are removed.- Specified by:
subscribe
in interfaceEventBusObservable<EVT extends EventBrokerEvent<?>,
O extends org.refcodes.observer.Observer<EVT>, MATCH extends EventBrokerEventMatcher<EVT>, META extends org.refcodes.observer.EventMetaData> - Parameters:
aEventMatcher
- TheEventMatcher
to guard theObserver
.aObserver
- TheObserver
to subscribe.- Returns:
- A handle to unsubscribe this combination.
-
unsubscribeAll
Unsubscribes all registrations to a specific listener, even if that listener is involved in several subscriptions.- Specified by:
unsubscribeAll
in interfaceEventBusObservable<EVT extends EventBrokerEvent<?>,
O extends org.refcodes.observer.Observer<EVT>, MATCH extends EventBrokerEventMatcher<EVT>, META extends org.refcodes.observer.EventMetaData> - Parameters:
aObserver
- the observer
-
hasHandle
- Specified by:
hasHandle
in interfaceorg.refcodes.component.HandleLookup<EVT extends EventBrokerEvent<?>,
O extends org.refcodes.observer.Observer<EVT>>
-
lookupHandle
- Specified by:
lookupHandle
in interfaceorg.refcodes.component.HandleLookup<EVT extends EventBrokerEvent<?>,
O extends org.refcodes.observer.Observer<EVT>>
-
removeHandle
- Specified by:
removeHandle
in interfaceorg.refcodes.component.HandleLookup<EVT extends EventBrokerEvent<?>,
O extends org.refcodes.observer.Observer<EVT>>
-
getDispatchStrategy
Retrieves theDispatchStrategy
property from the property. Determines in whichDispatchStrategy
status a component is in.- Specified by:
getDispatchStrategy
in interfaceDispatchStrategyAccessor
- Returns:
- Returns the
DispatchStrategy
property stored by the property.
-
publishEvent
Publishes an event using the givenDispatchStrategy
.- Specified by:
publishEvent
in interfaceEventDispatcher<EVT extends EventBrokerEvent<?>,
O extends org.refcodes.observer.Observer<EVT>, MATCH extends EventBrokerEventMatcher<EVT>, META extends org.refcodes.observer.EventMetaData, H> - Parameters:
aEvent
- aEvent The event to be published.aDispatchStrategy
- TheDispatchStrategy
to be used when publishing the event.
-
destroy
public void destroy()Shuts down anyExecutorService
by callingExecutorService.shutdown()
causing theEventDispatcher
to be disposed.- Specified by:
destroy
in interfaceDestroyable
-
sequentialDispatch
Hook implementing the sequential dispatch method as ofDispatchStrategy.SEQUENTIAL
.- Parameters:
aEvent
- The event to be dispatched sequentially.
-
parallelDispatch
Hook implementing the parallel dispatch method as ofDispatchStrategy.PARALLEL
.- Parameters:
aEvent
- The event to be dispatched sequentially.
-
cascadeDispatch
Hook implementing the cascaded dispatch method as ofDispatchStrategy.CASCADE
.- Parameters:
aEvent
- The event to be dispatched cascading.aMonitor
- The monitor used for synchronizing this cascade.
-