Package org.refcodes.servicebus
Class ServiceBusImpl<S extends Service<?>,SCTX extends ServiceContext<S>>
- java.lang.Object
-
- org.refcodes.servicebus.ServiceBusImpl<S,SCTX>
-
- Type Parameters:
S- the generic typeSCTX- the generic type
- All Implemented Interfaces:
org.refcodes.mixin.Loggable,ServiceBus<S>
public class ServiceBusImpl<S extends Service<?>,SCTX extends ServiceContext<S>> extends java.lang.Object implements ServiceBus<S>, org.refcodes.mixin.Loggable
The Class ServiceBusImpl.
-
-
Constructor Summary
Constructors Constructor Description ServiceBusImpl(ServiceLookup<S,SCTX> aServiceLookup, org.refcodes.component.ext.observer.ObservableLifeCycleStatusAutomaton aObservableLifecycleAutomaton)Constructs the subscriber part of the event bus.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddestroyServices()Destroy services.booleanhasService(ServiceMatcher<S> aServiceMatcher)Determines whether the givenServiceMatcherwill result in a singleServiceto be looked up.protected voidinitializeServices()Initialize services.SlookupService(ServiceMatcher<S> aServiceMatcher)Looks for a service matching the given service descriptor and returns it if found.protected voidonLifecycleEvent(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 voidpauseServices()Pause services.protected voidregisterLifecycleEventDispatcher(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 voidresumeServices()Resume services.protected voidstartServices()Start services.protected voidstopServices()Stop services.
-
-
-
Constructor Detail
-
ServiceBusImpl
public ServiceBusImpl(ServiceLookup<S,SCTX> 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 lookupaObservableLifecycleAutomaton- the observable lifecycle automaton
-
-
Method Detail
-
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:
lookupServicein interfaceServiceBus<S extends Service<?>>- Parameters:
aServiceMatcher- TheServiceMatcherdescribing the service for which to look for.- Returns:
- The desired
ServiceConfigurationError. - Throws:
AmbiguousServiceRuntimeException- in case more than oneServicematched theServiceMatcher.NoMatchingServiceRuntimeException
-
hasService
public boolean hasService(ServiceMatcher<S> aServiceMatcher)
Determines whether the givenServiceMatcherwill result in a singleServiceto be looked up. I.e. theServiceMatchermust result in an unambiguousServiceto be identified.- Specified by:
hasServicein interfaceServiceBus<S extends Service<?>>- Parameters:
aServiceMatcher- TheServiceMatcherdescribing theServicefor which to look for.- Returns:
- True in case if exactly one
Serviceis 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 theregisterLifecycleEventDispatcher(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.
-
-