Package org.refcodes.eventbus
Class AbstractEventBus<E extends org.refcodes.observer.GenericEvent<?>,O extends org.refcodes.observer.Observer<E>,MATCH extends org.refcodes.observer.EventMatcher<E>,META extends org.refcodes.observer.EventMetaData,H>
- java.lang.Object
-
- org.refcodes.eventbus.AbstractEventBus<E,O,MATCH,META,H>
-
- Type Parameters:
E- the element typeO- the generic typeMATCH- the generic typeMETA- the generic typeH- the generic type
- All Implemented Interfaces:
org.refcodes.component.HandleLookup<E,O>,DispatchStrategyAccessor,GenericBusObservable<E,O,MATCH,META>,GenericBusPublisher<E>,GenericEventBus<E,O,MATCH,META,H>,org.refcodes.matcher.Matcher<E>,org.refcodes.observer.EventMatcher<E>,org.refcodes.observer.Publisher<E>
- Direct Known Subclasses:
EventBusImpl
public abstract class AbstractEventBus<E extends org.refcodes.observer.GenericEvent<?>,O extends org.refcodes.observer.Observer<E>,MATCH extends org.refcodes.observer.EventMatcher<E>,META extends org.refcodes.observer.EventMetaData,H> extends java.lang.Object implements GenericEventBus<E,O,MATCH,META,H>
The Class AbstractEventBus.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.eventbus.DispatchStrategyAccessor
DispatchStrategyAccessor.DispatchStrategyMutator, DispatchStrategyAccessor.DispatchStrategyProperty
-
-
Constructor Summary
Constructors Constructor Description AbstractEventBus(int aCorePoolSize, org.refcodes.component.HandleGenerator<H> aHandleGenerator)Constructs theAbstractEventBuswith theDispatchStrategybeingDispatchStrategy.CASCADEwhen publishing events and the given handle generator.AbstractEventBus(org.refcodes.component.HandleGenerator<H> aHandleGenerator)Constructs theAbstractEventBuswith theDispatchStrategybeingDispatchStrategy.CASCADEwhen publishing events and the given handle generator.AbstractEventBus(org.refcodes.component.HandleGenerator<H> aHandleGenerator, java.util.concurrent.ExecutorService aExecutorService)Constructs theAbstractEventBuswith theDispatchStrategybeingDispatchStrategy.CASCADEwhen publishing events and the given handle generator.AbstractEventBus(DispatchStrategy aDispatchStrategy, int aCorePoolSize, org.refcodes.component.HandleGenerator<H> aHandleGenerator)Constructs theAbstractEventBuswith the givenDispatchStrategywhen publishing events and the given handle generator.AbstractEventBus(DispatchStrategy aDispatchStrategy, org.refcodes.component.HandleGenerator<H> aHandleGenerator)Constructs theAbstractEventBuswith the givenDispatchStrategywhen publishing events and the given handle generator.AbstractEventBus(DispatchStrategy aDispatchStrategy, org.refcodes.component.HandleGenerator<H> aHandleGenerator, java.util.concurrent.ExecutorService aExecutorService)Constructs theAbstractEventBuswith the givenDispatchStrategywhen publishing events and the given handle generator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcascadeDispatch(E aEvent, java.lang.Object aMonitor)Hook implementing the cascaded dispatch method as ofDispatchStrategy.CASCADEDispatchStrategygetDispatchStrategy()Retrieves theDispatchStrategyproperty from the property.booleanhasHandle(H aHandle)booleanisMatching(E aEvent)OlookupHandle(H aHandle)protected voidparallelDispatch(E aEvent)Hook implementing the parallel dispatch method as ofDispatchStrategy.PARALLELvoidpublishEvent(E aEvent, DispatchStrategy aDispatchStrategy)Publishes an event using the givenDispatchStrategy.OremoveHandle(H aHandle)protected voidsequentialDispatch(E aEvent)Hook implementing the sequential dispatch method as ofDispatchStrategy.SEQUENTIALHsubscribe(MATCH aEventMatcher, O aObserver)Subscribes a listener to the event bus.voidunsubscribeAll(O aObserver)Unsubscribes all registrations to a specific listener, even if that listener is involved in several subscriptions.-
Methods inherited from interface org.refcodes.eventbus.GenericBusObservable
subscribe, subscribe
-
Methods inherited from interface org.refcodes.eventbus.GenericEventBus
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 Detail
-
AbstractEventBus
public AbstractEventBus(int aCorePoolSize, org.refcodes.component.HandleGenerator<H> aHandleGenerator)Constructs theAbstractEventBuswith theDispatchStrategybeingDispatchStrategy.CASCADEwhen publishing events and the given handle generator.- Parameters:
aCorePoolSize- The number of threads to keep in the pool, even if they are idle.aHandleGenerator- The handle generator to be used.
-
AbstractEventBus
public AbstractEventBus(DispatchStrategy aDispatchStrategy, int aCorePoolSize, org.refcodes.component.HandleGenerator<H> aHandleGenerator)
Constructs theAbstractEventBuswith the givenDispatchStrategywhen publishing events and the given handle generator.- Parameters:
aDispatchStrategy- TheDispatchStrategyto be used when publishing events.aCorePoolSize- The number of threads to keep in the pool, even if they are idle.aHandleGenerator- The handle generator to be used.
-
AbstractEventBus
public AbstractEventBus(org.refcodes.component.HandleGenerator<H> aHandleGenerator)
Constructs theAbstractEventBuswith theDispatchStrategybeingDispatchStrategy.CASCADEwhen publishing events and the given handle generator.- Parameters:
aHandleGenerator- The handle generator to be used.
-
AbstractEventBus
public AbstractEventBus(org.refcodes.component.HandleGenerator<H> aHandleGenerator, java.util.concurrent.ExecutorService aExecutorService)
Constructs theAbstractEventBuswith theDispatchStrategybeingDispatchStrategy.CASCADEwhen publishing events and the given handle generator.- Parameters:
aHandleGenerator- The handle generator to be used.aExecutorService- TheExecutorServiceto be used when creating threads.
-
AbstractEventBus
public AbstractEventBus(DispatchStrategy aDispatchStrategy, org.refcodes.component.HandleGenerator<H> aHandleGenerator)
Constructs theAbstractEventBuswith the givenDispatchStrategywhen publishing events and the given handle generator.- Parameters:
aDispatchStrategy- TheDispatchStrategyto be used when publishing events.aHandleGenerator- The handle generator to be used.
-
AbstractEventBus
public AbstractEventBus(DispatchStrategy aDispatchStrategy, org.refcodes.component.HandleGenerator<H> aHandleGenerator, java.util.concurrent.ExecutorService aExecutorService)
Constructs theAbstractEventBuswith the givenDispatchStrategywhen publishing events and the given handle generator.- Parameters:
aDispatchStrategy- TheDispatchStrategyto be used when publishing events.aHandleGenerator- The handle generator to be used.aExecutorService- TheExecutorServiceto be used when creating threads.
-
-
Method Detail
-
isMatching
public boolean isMatching(E aEvent)
-
subscribe
public H subscribe(MATCH aEventMatcher, O aObserver)
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:
subscribein interfaceGenericBusObservable<E extends org.refcodes.observer.GenericEvent<?>,O extends org.refcodes.observer.Observer<E>,MATCH extends org.refcodes.observer.EventMatcher<E>,META extends org.refcodes.observer.EventMetaData>- Parameters:
aEventMatcher- TheEventMatcherto guard theObserver.aObserver- TheObserverto subscribe.- Returns:
- A handle to unsubscribe this combination.
-
unsubscribeAll
public void unsubscribeAll(O aObserver)
Unsubscribes all registrations to a specific listener, even if that listener is involved in several subscriptions.- Specified by:
unsubscribeAllin interfaceGenericBusObservable<E extends org.refcodes.observer.GenericEvent<?>,O extends org.refcodes.observer.Observer<E>,MATCH extends org.refcodes.observer.EventMatcher<E>,META extends org.refcodes.observer.EventMetaData>- Parameters:
aObserver- the observer
-
hasHandle
public boolean hasHandle(H aHandle)
-
lookupHandle
public O lookupHandle(H aHandle) throws org.refcodes.component.UnknownHandleRuntimeException
-
removeHandle
public O removeHandle(H aHandle) throws org.refcodes.component.UnknownHandleRuntimeException
-
getDispatchStrategy
public DispatchStrategy getDispatchStrategy()
Retrieves theDispatchStrategyproperty from the property. Determines in whichDispatchStrategystatus a component is in.- Specified by:
getDispatchStrategyin interfaceDispatchStrategyAccessor- Returns:
- Returns the
DispatchStrategyproperty stored by the property.
-
publishEvent
public void publishEvent(E aEvent, DispatchStrategy aDispatchStrategy)
Publishes an event using the givenDispatchStrategy.- Specified by:
publishEventin interfaceGenericEventBus<E extends org.refcodes.observer.GenericEvent<?>,O extends org.refcodes.observer.Observer<E>,MATCH extends org.refcodes.observer.EventMatcher<E>,META extends org.refcodes.observer.EventMetaData,H>- Parameters:
aEvent- aEvent The event to be published.aDispatchStrategy- TheDispatchStrategyto be used when publishing the event.
-
sequentialDispatch
protected void sequentialDispatch(E aEvent)
Hook implementing the sequential dispatch method as ofDispatchStrategy.SEQUENTIAL- Parameters:
aEvent- The event to be dispatched sequentially.
-
parallelDispatch
protected void parallelDispatch(E aEvent)
Hook implementing the parallel dispatch method as ofDispatchStrategy.PARALLEL- Parameters:
aEvent- The event to be dispatched sequentially.
-
cascadeDispatch
protected void cascadeDispatch(E aEvent, java.lang.Object aMonitor)
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.
-
-