|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.hadoop.service.AbstractService
@InterfaceAudience.Public @InterfaceStability.Evolving public abstract class AbstractService
This is the base implementation class for services.
| Constructor Summary | |
|---|---|
AbstractService(String name)
Construct the service. |
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public AbstractService(String name)
name - service name| Method Detail |
|---|
public final org.apache.hadoop.service.Service.STATE getServiceState()
Service
getServiceState in interface Servicepublic final Throwable getFailureCause()
Service
getFailureCause 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 Configuration
conf - 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 null
ServiceStateException - 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.
stop in interface Service
public final void close()
throws IOException
stop()
close in interface Closeableclose in interface ServiceIOExceptionprotected final void noteFailure(Exception exception)
exception - the exceptionpublic final boolean waitForServiceToStop(long timeout)
Service
waitForServiceToStop 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 value
conf - configuration
Exception - on a failure -these will be caught,
possibly wrapped, and wil; trigger a service stop
protected void serviceStart()
throws Exception
start() prevents re-entrancy.
Exception - if needed -these will be caught,
wrapped, and trigger a service stop
protected 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)
Service
registerServiceListener in interface Servicel - a new listenerpublic void unregisterServiceListener(ServiceStateChangeListener l)
Service
unregisterServiceListener in interface Servicel - the listener to unregister.public static void registerGlobalListener(ServiceStateChangeListener l)
l - listenerpublic static boolean unregisterGlobalListener(ServiceStateChangeListener l)
l - listener to unregister
public String getName()
Service
getName in interface Servicepublic Configuration getConfig()
Service
getConfig in interface Servicepublic long getStartTime()
Service
getStartTime in interface Servicepublic List<LifecycleEvent> getLifecycleHistory()
Service
getLifecycleHistory in interface Servicepublic final boolean isInState(org.apache.hadoop.service.Service.STATE expected)
Service
isInState in interface Serviceexpected - the expected state
public String toString()
toString in class Object
protected 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()
Service
getBlockers in interface Service
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||