Package org.apache.hadoop.service
Class CompositeService
java.lang.Object
org.apache.hadoop.service.AbstractService
org.apache.hadoop.service.CompositeService
- All Implemented Interfaces:
Closeable,AutoCloseable,Service
- Direct Known Subclasses:
AddingCompositeService,AppAdminClient,org.apache.hadoop.registry.client.impl.zk.CuratorService,TimelineClient,TimelineReaderClient
Composition of services.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classorg.apache.hadoop.service.CompositeService.CompositeServiceShutdownHookJVM Shutdown hook for CompositeService which will stop the give CompositeService gracefully in case of JVM shutdown.Nested classes/interfaces inherited from interface org.apache.hadoop.service.Service
Service.STATE -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final booleanPolicy on shutdown: attempt to close everything (purest) or only try to close started services (which assumes that the service implementations may not handle the stop() operation except when started. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanaddIfService(Object object) If the passed object is an instance ofService, add it to the list of services managed by thisCompositeServiceprotected voidaddService(Service service) Add the passedServiceto the list of services managed by thisCompositeServiceGet a cloned list of servicesprotected booleanremoveService(Service service) protected voidserviceInit(Configuration conf) All initialization code needed by a service.protected voidActions called during the INITED to STARTED transition.protected voidActions called during the transition to the STOPPED state.Methods inherited from class org.apache.hadoop.service.AbstractService
close, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, noteFailure, putBlocker, registerGlobalListener, registerServiceListener, removeBlocker, setConfig, start, stop, toString, unregisterGlobalListener, unregisterServiceListener, waitForServiceToStop
-
Field Details
-
STOP_ONLY_STARTED_SERVICES
protected static final boolean STOP_ONLY_STARTED_SERVICESPolicy on shutdown: attempt to close everything (purest) or only try to close started services (which assumes that the service implementations may not handle the stop() operation except when started. Irrespective of this policy, if a child service fails during its init() or start() operations, it will have stop() called on it.- See Also:
-
-
Constructor Details
-
CompositeService
-
-
Method Details
-
getServices
Get a cloned list of services- Returns:
- a list of child services at the time of invocation - added services will not be picked up.
-
addService
Add the passedServiceto the list of services managed by thisCompositeService- Parameters:
service- theServiceto be added
-
addIfService
If the passed object is an instance ofService, add it to the list of services managed by thisCompositeService- Parameters:
object- object.- Returns:
- true if a service is added, false otherwise.
-
removeService
-
serviceInit
Description copied from class:AbstractServiceAll initialization code needed by a service. This method will only ever be called once during the lifecycle of a specific service instance. Implementations do not need to be synchronized as the logic inAbstractService.init(Configuration)prevents re-entrancy. The base implementation checks to see if the subclass has created a new configuration instance, and if so, updates the base class value- Overrides:
serviceInitin classAbstractService- Parameters:
conf- configuration- Throws:
Exception- on a failure -these will be caught, possibly wrapped, and will trigger a service stop
-
serviceStart
Description copied from class:AbstractServiceActions called during the INITED to STARTED transition. This method will only ever be called once during the lifecycle of a specific service instance. Implementations do not need to be synchronized as the logic inAbstractService.start()prevents re-entrancy.- Overrides:
serviceStartin classAbstractService- Throws:
Exception- if needed -these will be caught, wrapped, and trigger a service stop
-
serviceStop
Description copied from class:AbstractServiceActions called during the transition to the STOPPED state. This method will only ever be called once during the lifecycle of a specific service instance. Implementations do not need to be synchronized as the logic inAbstractService.stop()prevents re-entrancy. Implementations MUST write this to be robust against failures, including checks for null references -and for the first failure to not stop other attempts to shut down parts of the service.- Overrides:
serviceStopin classAbstractService- Throws:
Exception- if needed -these will be caught and logged.
-