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 type
O - the generic type
MATCH - the generic type
META - the generic type
H - 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.
  • Constructor Details

    • AbstractEventBus

      public AbstractEventBus(boolean isDaemon, org.refcodes.component.HandleGenerator<H> aHandleGenerator)
      Constructs the AbstractEventBus with the DispatchStrategy being DispatchStrategy.CASCADE when publishing events and the given handle generator.
      Parameters:
      isDaemon - True when to create daemon dispatch Thread instances (shutdown upon last application Thread shutdown), else application Thread instances are created for dispatch.
      aHandleGenerator - The handle generator to be used.
    • AbstractEventBus

      public AbstractEventBus(org.refcodes.component.HandleGenerator<H> aHandleGenerator)
      Constructs the AbstractEventBus with the DispatchStrategy being DispatchStrategy.CASCADE when publishing events and the given handle generator, any Thread 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 the AbstractEventBus with the DispatchStrategy being DispatchStrategy.CASCADE when publishing events and the given handle generator.
      Parameters:
      aHandleGenerator - The handle generator to be used.
      aExecutorService - The ExecutorService to be used when creating threads.
    • AbstractEventBus

      public AbstractEventBus(DispatchStrategy aDispatchStrategy, org.refcodes.component.HandleGenerator<H> aHandleGenerator)
      Constructs the AbstractEventBus with the given DispatchStrategy when publishing events and the given handle generator, any Thread instances created are created as daemon threads.
      Parameters:
      aDispatchStrategy - The DispatchStrategy 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 the AbstractEventBus with the given DispatchStrategy when publishing events and the given handle generator.
      Parameters:
      aDispatchStrategy - The DispatchStrategy to be used when publishing events.
      isDaemon - True when to create daemon dispatch Thread instances (shutdown upon last application Thread shutdown), else application Thread 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 the AbstractEventBus with the given DispatchStrategy when publishing events and the given handle generator.
      Parameters:
      aDispatchStrategy - The DispatchStrategy to be used when publishing events.
      aHandleGenerator - The handle generator to be used.
      aExecutorService - The ExecutorService to be used when creating threads.
  • Method Details

    • isMatching

      public boolean isMatching(EVT aEvent)
      Specified by:
      isMatching in interface org.refcodes.matcher.Matchable<EVT extends EventBrokerEvent<?>>
    • 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:
      subscribe in interface EventBusObservable<EVT extends EventBrokerEvent<?>,O extends org.refcodes.observer.Observer<EVT>,MATCH extends EventBrokerEventMatcher<EVT>,META extends org.refcodes.observer.EventMetaData>
      Parameters:
      aEventMatcher - The EventMatcher to guard the Observer.
      aObserver - The Observer to 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:
      unsubscribeAll in interface EventBusObservable<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

      public boolean hasHandle(H aHandle)
      Specified by:
      hasHandle in interface org.refcodes.component.HandleLookup<EVT extends EventBrokerEvent<?>,O extends org.refcodes.observer.Observer<EVT>>
    • lookupHandle

      public O lookupHandle(H aHandle)
      Specified by:
      lookupHandle in interface org.refcodes.component.HandleLookup<EVT extends EventBrokerEvent<?>,O extends org.refcodes.observer.Observer<EVT>>
    • removeHandle

      public O removeHandle(H aHandle)
      Specified by:
      removeHandle in interface org.refcodes.component.HandleLookup<EVT extends EventBrokerEvent<?>,O extends org.refcodes.observer.Observer<EVT>>
    • getDispatchStrategy

      public DispatchStrategy getDispatchStrategy()
      Retrieves the DispatchStrategy property from the property. Determines in which DispatchStrategy status a component is in.
      Specified by:
      getDispatchStrategy in interface DispatchStrategyAccessor
      Returns:
      Returns the DispatchStrategy property stored by the property.
    • publishEvent

      public void publishEvent(EVT aEvent, DispatchStrategy aDispatchStrategy)
      Publishes an event using the given DispatchStrategy.
      Specified by:
      publishEvent in interface EventDispatcher<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 - The DispatchStrategy to be used when publishing the event.
    • destroy

      public void destroy()
      Shuts down any ExecutorService by calling ExecutorService.shutdown() causing the EventDispatcher to be disposed.
      Specified by:
      destroy in interface Destroyable
    • sequentialDispatch

      protected void sequentialDispatch(EVT aEvent)
      Hook implementing the sequential dispatch method as of DispatchStrategy.SEQUENTIAL.
      Parameters:
      aEvent - The event to be dispatched sequentially.
    • parallelDispatch

      protected void parallelDispatch(EVT aEvent)
      Hook implementing the parallel dispatch method as of DispatchStrategy.PARALLEL.
      Parameters:
      aEvent - The event to be dispatched sequentially.
    • cascadeDispatch

      protected void cascadeDispatch(EVT aEvent, Object aMonitor)
      Hook implementing the cascaded dispatch method as of DispatchStrategy.CASCADE.
      Parameters:
      aEvent - The event to be dispatched cascading.
      aMonitor - The monitor used for synchronizing this cascade.