@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()
Service
getServiceState
in interface Service
public final Throwable getFailureCause()
Service
getFailureCause
in interface Service
public org.apache.hadoop.service.Service.STATE getFailureState()
Service
Service.getFailureCause()
occurred.getFailureState
in interface Service
protected 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 Service
conf
- 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 Service
ServiceStateException
- 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 Closeable
close
in interface AutoCloseable
close
in interface Service
IOException
protected final void noteFailure(Exception exception)
exception
- the exceptionpublic final boolean waitForServiceToStop(long timeout)
Service
waitForServiceToStop
in interface Service
timeout
- 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)
Service
registerServiceListener
in interface Service
l
- a new listenerpublic void unregisterServiceListener(ServiceStateChangeListener l)
Service
unregisterServiceListener
in interface Service
l
- the listener to unregister.public static void registerGlobalListener(ServiceStateChangeListener l)
l
- listenerpublic static boolean unregisterGlobalListener(ServiceStateChangeListener l)
l
- listener to unregisterpublic String getName()
Service
public Configuration getConfig()
Service
public long getStartTime()
Service
getStartTime
in interface Service
public List<LifecycleEvent> getLifecycleHistory()
Service
getLifecycleHistory
in interface Service
public final boolean isInState(org.apache.hadoop.service.Service.STATE expected)
Service
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
Copyright © 2017 Apache Software Foundation. All rights reserved.