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.mixin.EventMetaData,H>

  • Type Parameters:
    E - the element type
    O - the generic type
    MATCH - the generic type
    META - the generic type
    H - 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.mixin.EventMetaData,H>
    extends Object
    implements GenericEventBus<E,O,MATCH,META,H>
    The Class AbstractEventBus.
    • Constructor Detail

      • AbstractEventBus

        public AbstractEventBus​(int aCorePoolSize,
                                org.refcodes.component.HandleGenerator<H> aHandleGenerator)
        Constructs the AbstractEventBus with the DispatchStrategy being DispatchStrategy.CASCADE when 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 the AbstractEventBus with the given DispatchStrategy when publishing events and the given handle generator.
        Parameters:
        aDispatchStrategy - The DispatchStrategy to 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 the AbstractEventBus with the DispatchStrategy being DispatchStrategy.CASCADE when publishing events and the given handle generator.
        Parameters:
        aHandleGenerator - The handle generator to be used.
      • 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.
        Parameters:
        aDispatchStrategy - The DispatchStrategy to be used when publishing events.
        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 Detail

      • isMatching

        public boolean isMatching​(E aEvent)
        Specified by:
        isMatching in interface org.refcodes.observer.EventMatcher<E extends org.refcodes.observer.GenericEvent<?>>
        Specified by:
        isMatching in interface org.refcodes.matcher.Matcher<E extends org.refcodes.observer.GenericEvent<?>>
      • 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 GenericBusObservable<E extends org.refcodes.observer.GenericEvent<?>,O extends org.refcodes.observer.Observer<E>,MATCH extends org.refcodes.observer.EventMatcher<E>,META extends org.refcodes.mixin.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 GenericBusObservable<E extends org.refcodes.observer.GenericEvent<?>,O extends org.refcodes.observer.Observer<E>,MATCH extends org.refcodes.observer.EventMatcher<E>,META extends org.refcodes.mixin.EventMetaData>
        Parameters:
        aObserver - the observer
      • hasHandle

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

        public O lookupHandle​(H aHandle)
                       throws org.refcodes.component.UnknownHandleRuntimeException
        Specified by:
        lookupHandle in interface org.refcodes.component.HandleLookup<E extends org.refcodes.observer.GenericEvent<?>,O extends org.refcodes.observer.Observer<E>>
        Throws:
        org.refcodes.component.UnknownHandleRuntimeException
      • removeHandle

        public O removeHandle​(H aHandle)
                       throws org.refcodes.component.UnknownHandleRuntimeException
        Specified by:
        removeHandle in interface org.refcodes.component.HandleLookup<E extends org.refcodes.observer.GenericEvent<?>,O extends org.refcodes.observer.Observer<E>>
        Throws:
        org.refcodes.component.UnknownHandleRuntimeException
      • publishEvent

        public void publishEvent​(E aEvent,
                                 DispatchStrategy aDispatchStrategy)
        Publishes an event using the given DispatchStrategy.
        Specified by:
        publishEvent in interface GenericEventBus<E extends org.refcodes.observer.GenericEvent<?>,O extends org.refcodes.observer.Observer<E>,MATCH extends org.refcodes.observer.EventMatcher<E>,META extends org.refcodes.mixin.EventMetaData,H>
        Parameters:
        aEvent - aEvent The event to be published.
        aDispatchStrategy - The DispatchStrategy to be used when publishing the event.
      • sequentialDispatch

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

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

        protected void cascadeDispatch​(E 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.