@InterfaceAudience.Public @InterfaceStability.Evolving public abstract class AbstractService extends Object implements Service
| Constructor and Description |
|---|
AbstractService(String name)
Construct the service.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Relay to
stop() |
Map<String,String> |
getBlockers()
Get the blockers on a service -remote dependencies
that are stopping the service from being live.
|
Configuration |
getConfig()
Get the configuration of this service.
|
Throwable |
getFailureCause()
Get the first exception raised during the service failure.
|
org.apache.hadoop.service.Service.STATE |
getFailureState()
Get the state in which the failure in
Service.getFailureCause() occurred. |
List<LifecycleEvent> |
getLifecycleHistory()
Get a snapshot of the lifecycle history; it is a static list
|
String |
getName()
Get the name of this service.
|
org.apache.hadoop.service.Service.STATE |
getServiceState()
Get the current service state
|
long |
getStartTime()
Get the service start time
|
void |
init(Configuration conf)
Initialize the service.
|
boolean |
isInState(org.apache.hadoop.service.Service.STATE expected)
Query to see if the service is in a specific state.
|
protected void |
noteFailure(Exception exception)
Failure handling: record the exception
that triggered it -if there was not one already.
|
protected void |
putBlocker(String name,
String details)
Put a blocker to the blocker map -replacing any
with the same name.
|
static void |
registerGlobalListener(ServiceStateChangeListener l)
Register a global listener, which receives notifications
from the state change events of all services in the JVM
|
void |
registerServiceListener(ServiceStateChangeListener l)
Register a listener to the service state change events.
|
void |
removeBlocker(String name)
Remove a blocker from the blocker map -
this is a no-op if the blocker is not present
|
protected void |
serviceInit(Configuration conf)
All initialization code needed by a service.
|
protected void |
serviceStart()
Actions called during the INITED to STARTED transition.
|
protected void |
serviceStop()
Actions called during the transition to the STOPPED state.
|
protected void |
setConfig(Configuration conf)
Set the configuration for this service.
|
void |
start()
Start the service.
|
void |
stop()
Stop the service.
|
String |
toString() |
static boolean |
unregisterGlobalListener(ServiceStateChangeListener l)
unregister a global listener.
|
void |
unregisterServiceListener(ServiceStateChangeListener l)
Unregister a previously registered listener of the service state
change events.
|
boolean |
waitForServiceToStop(long timeout)
Block waiting for the service to stop; uses the termination notification
object to do so.
|
public AbstractService(String name)
name - service namepublic final org.apache.hadoop.service.Service.STATE getServiceState()
ServicegetServiceState in interface Servicepublic final Throwable getFailureCause()
ServicegetFailureCause in interface Servicepublic org.apache.hadoop.service.Service.STATE getFailureState()
ServiceService.getFailureCause() occurred.getFailureState in interface Serviceprotected void setConfig(Configuration conf)
init(Configuration)
and should only be needed if for some reason a service implementation
needs to override that initial setting -for example replacing
it with a new subclass of Configurationconf - new configuration.public void init(Configuration conf)
Service.STATE.NOTINITED to Service.STATE.INITED
unless the operation failed and an exception was raised, in which case
Service.stop() MUST be invoked and the service enter the state
Service.STATE.STOPPED.
This invokes serviceInit(org.apache.hadoop.conf.Configuration)init in interface Serviceconf - the configuration of the service. This must not be nullServiceStateException - if the configuration was null,
the state change not permitted, or something else went wrongpublic void start()
Service.STATE.INITED to Service.STATE.STARTED
unless the operation failed and an exception was raised, in which case
Service.stop() MUST be invoked and the service enter the state
Service.STATE.STOPPED.start in interface ServiceServiceStateException - if the current service state does not permit
this actionpublic void stop()
Service.STATE.STOPPED state. It SHOULD be a best-effort attempt
to stop all parts of the service.
The implementation must be designed to complete regardless of the service
state, including the initialized/uninitialized state of all its internal
fields.public final void close() throws IOException
stop()close in interface Closeableclose in interface AutoCloseableclose in interface ServiceIOExceptionprotected final void noteFailure(Exception exception)
exception - the exceptionpublic final boolean waitForServiceToStop(long timeout)
ServicewaitForServiceToStop in interface Servicetimeout - timeout in milliseconds. A value of zero means "forever"protected void serviceInit(Configuration conf) throws Exception
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 valueconf - configurationException - on a failure -these will be caught,
possibly wrapped, and wil; trigger a service stopprotected void serviceStart() throws Exception
start() prevents re-entrancy.Exception - if needed -these will be caught,
wrapped, and trigger a service stopprotected void serviceStop() throws Exception
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.Exception - if needed -these will be caught and logged.public void registerServiceListener(ServiceStateChangeListener l)
ServiceregisterServiceListener in interface Servicel - a new listenerpublic void unregisterServiceListener(ServiceStateChangeListener l)
ServiceunregisterServiceListener in interface Servicel - the listener to unregister.public static void registerGlobalListener(ServiceStateChangeListener l)
l - listenerpublic static boolean unregisterGlobalListener(ServiceStateChangeListener l)
l - listener to unregisterpublic String getName()
Servicepublic Configuration getConfig()
Servicepublic long getStartTime()
ServicegetStartTime in interface Servicepublic List<LifecycleEvent> getLifecycleHistory()
ServicegetLifecycleHistory in interface Servicepublic final boolean isInState(org.apache.hadoop.service.Service.STATE expected)
Serviceprotected void putBlocker(String name, String details)
name - blocker namedetails - any specifics on the block. This must be non-null.public void removeBlocker(String name)
name - the name of the blockerpublic Map<String,String> getBlockers()
ServicegetBlockers in interface ServiceCopyright © 2018 Apache Software Foundation. All rights reserved.