Class SimpleServiceBus<S extends Service<?>,CTX extends ServiceContext<S>>

java.lang.Object
org.refcodes.servicebus.SimpleServiceBus<S,CTX>
Type Parameters:
S - the generic type of the services to be served.
CTX - the generic service's context type
All Implemented Interfaces:
org.refcodes.mixin.Loggable, ServiceBus<S>

public class SimpleServiceBus<S extends Service<?>,CTX extends ServiceContext<S>> extends Object implements ServiceBus<S>, org.refcodes.mixin.Loggable
The SimpleServiceBus is a basic implementation of the ServiceBus interface.
  • Field Summary

    Fields inherited from interface org.refcodes.mixin.Loggable

    RUNTIME_LOGGER_CLASS, RUNTIME_LOGGER_FACTORY_CLASS, RUNTIME_LOGGER_FACTORY_METHOD
  • Constructor Summary

    Constructors
    Constructor
    Description
    SimpleServiceBus(ServiceLookup<S,CTX> aServiceLookup, org.refcodes.component.ext.observer.ObservableLifecycleStatusAutomaton aObservableLifecycleAutomaton)
    Constructs the subscriber part of the event bus.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Destroy services.
    boolean
    hasService(ServiceMatcher<S> aServiceMatcher)
    Determines whether the given ServiceMatcher will result in a single Service to be looked up.
    protected void
    Initialize services.
    lookupService(ServiceMatcher<S> aServiceMatcher)
    Looks for a service matching the given service descriptor and returns it if found.
    protected void
    onLifecycleEvent(org.refcodes.component.ext.observer.LifecycleRequestEvent aEvent)
    This method is used to handle life-cycle events and inform the according services of any life-cycle state changes.
    protected void
    Pause services.
    protected void
    registerLifecycleEventDispatcher(org.refcodes.component.ext.observer.ObservableLifecycleStatusAutomaton aObservableLifecycleAutomaton)
    This method registers a life-cycle event listener which dispatches any incoming life-cycle events to the according dispatcher method below.
    protected void
    Resume services.
    protected void
    Start services.
    protected void
    Stop services.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.refcodes.mixin.Loggable

    alert, alert, critical, critical, debug, error, info, notice, panic, trace, warn, warn
  • Constructor Details

    • SimpleServiceBus

      public SimpleServiceBus(ServiceLookup<S,CTX> aServiceLookup, org.refcodes.component.ext.observer.ObservableLifecycleStatusAutomaton aObservableLifecycleAutomaton)
      Constructs the subscriber part of the event bus. For doing its job, it needs the list of services which is accessible via the provided service lookup part of the service bus.
      Parameters:
      aServiceLookup - the service lookup
      aObservableLifecycleAutomaton - the observable lifecycle automaton
  • Method Details

    • lookupService

      public S lookupService(ServiceMatcher<S> aServiceMatcher) throws NoMatchingServiceRuntimeException, AmbiguousServiceRuntimeException
      Looks for a service matching the given service descriptor and returns it if found.
      Specified by:
      lookupService in interface ServiceBus<S extends Service<?>>
      Parameters:
      aServiceMatcher - The ServiceMatcher describing the service for which to look for.
      Returns:
      The desired ServiceConfigurationError.
      Throws:
      AmbiguousServiceRuntimeException - in case more than one Service matched the ServiceMatcher.
      NoMatchingServiceRuntimeException
    • hasService

      public boolean hasService(ServiceMatcher<S> aServiceMatcher)
      Determines whether the given ServiceMatcher will result in a single Service to be looked up. I.e. the ServiceMatcher must result in an unambiguous Service to be identified.
      Specified by:
      hasService in interface ServiceBus<S extends Service<?>>
      Parameters:
      aServiceMatcher - The ServiceMatcher describing the Service for which to look for.
      Returns:
      True in case if exactly one Service is matching the matcher. Else false is returned (either more than one service was identified or none service was identified).
    • registerLifecycleEventDispatcher

      protected void registerLifecycleEventDispatcher(org.refcodes.component.ext.observer.ObservableLifecycleStatusAutomaton aObservableLifecycleAutomaton)
      This method registers a life-cycle event listener which dispatches any incoming life-cycle events to the according dispatcher method below.
      Parameters:
      aObservableLifecycleAutomaton - the observable lifecycle automaton
    • onLifecycleEvent

      protected void onLifecycleEvent(org.refcodes.component.ext.observer.LifecycleRequestEvent aEvent)
      This method is used to handle life-cycle events and inform the according services of any life-cycle state changes. Use the registerLifecycleEventDispatcher(ObservableLifecycleStatusAutomaton) method to register a dispatcher for any life-cycle events from a provided observable life-cycle instance.
      Parameters:
      aEvent - the event
    • initializeServices

      protected void initializeServices()
      Initialize services.
    • startServices

      protected void startServices()
      Start services.
    • pauseServices

      protected void pauseServices()
      Pause services.
    • resumeServices

      protected void resumeServices()
      Resume services.
    • stopServices

      protected void stopServices()
      Stop services.
    • destroyServices

      protected void destroyServices()
      Destroy services.