public abstract class BaseService extends Object
SuspendableService
in case they
support suspend/resume.
Important: You should override the lifecycle methods that start with do, eg doStart()
},
doStop()
, etc. where you implement your logic. The methods start()
, stop()
should
NOT be overridden as they are used internally to keep track of the state of this service and properly invoke
the operation in a safe manner.Modifier and Type | Field and Description |
---|---|
protected static byte |
BUILT |
protected static byte |
FAILED |
protected static byte |
INITIALIZED |
protected static byte |
INITIALIZING |
protected Object |
lock |
protected static byte |
NEW |
protected static byte |
SHUTDOWN |
protected static byte |
SHUTTING_DOWN |
protected static byte |
STARTED |
protected static byte |
STARTING |
protected byte |
status |
protected static byte |
STOPPED |
protected static byte |
STOPPING |
protected static byte |
SUSPENDED |
protected static byte |
SUSPENDING |
Constructor and Description |
---|
BaseService() |
Modifier and Type | Method and Description |
---|---|
void |
build() |
protected void |
doBuild()
Optional build phase of the service.
|
protected void |
doFail(Exception e)
Implementations override this method to perform any action upon failure.
|
protected void |
doInit()
Initialize the service.
|
protected AutoCloseable |
doLifecycleChange()
Implementations may return an object that will be closed when the lifecycle action is completed.
|
protected void |
doResume()
Implementations override this method to support customized suspend/resume.
|
protected void |
doShutdown()
Implementations override this method to perform customized shutdown.
|
protected void |
doStart()
Implementations override this method to support customized start/stop.
|
protected void |
doStop()
Implementations override this method to support customized start/stop.
|
protected void |
doSuspend()
Implementations override this method to support customized suspend/resume.
|
protected void |
fail(Exception e) |
ServiceStatus |
getStatus() |
void |
init() |
boolean |
isBuild() |
boolean |
isInit() |
boolean |
isNew() |
boolean |
isRunAllowed() |
boolean |
isShutdown() |
boolean |
isStarted() |
boolean |
isStarting() |
boolean |
isStartingOrStarted()
Is the service in progress of being suspended or already suspended
|
boolean |
isStopped() |
boolean |
isStopping() |
boolean |
isStoppingOrStopped()
Is the service in progress of being stopped or already stopped
|
boolean |
isSuspended() |
boolean |
isSuspending() |
boolean |
isSuspendingOrSuspended()
Is the service in progress of being suspended or already suspended
|
void |
resume()
|
void |
shutdown()
|
void |
start()
|
void |
stop()
|
void |
suspend()
|
protected static final byte NEW
protected static final byte BUILT
protected static final byte INITIALIZING
protected static final byte INITIALIZED
protected static final byte STARTING
protected static final byte STARTED
protected static final byte SUSPENDING
protected static final byte SUSPENDED
protected static final byte STOPPING
protected static final byte STOPPED
protected static final byte SHUTTING_DOWN
protected static final byte SHUTDOWN
protected static final byte FAILED
protected final Object lock
protected volatile byte status
public void build()
public void init()
public void start()
doStart()
,
doStop()
, etc. where you implement your logic. The methods start()
, stop()
should
NOT be overridden as they are used internally to keep track of the state of this service and properly
invoke the operation in a safe manner.public void stop()
doStart()
,
doStop()
, etc. where you implement your logic. The methods start()
, stop()
should
NOT be overridden as they are used internally to keep track of the state of this service and properly
invoke the operation in a safe manner.public void suspend()
doStart()
,
doStop()
, etc. where you implement your logic. The methods start()
, stop()
should
NOT be overridden as they are used internally to keep track of the state of this service and properly
invoke the operation in a safe manner.public void resume()
doStart()
,
doStop()
, etc. where you implement your logic. The methods start()
, stop()
should
NOT be overridden as they are used internally to keep track of the state of this service and properly
invoke the operation in a safe manner.public void shutdown()
doStart()
,
doStop()
, etc. where you implement your logic. The methods start()
, stop()
should
NOT be overridden as they are used internally to keep track of the state of this service and properly
invoke the operation in a safe manner.public ServiceStatus getStatus()
public boolean isNew()
public boolean isBuild()
public boolean isInit()
public boolean isStarted()
public boolean isStarting()
public boolean isStopping()
public boolean isStopped()
public boolean isSuspending()
public boolean isSuspended()
public boolean isRunAllowed()
public boolean isShutdown()
public boolean isStoppingOrStopped()
public boolean isSuspendingOrSuspended()
public boolean isStartingOrStarted()
protected void fail(Exception e)
protected void doBuild() throws Exception
Exception
protected void doInit() throws Exception
Exception
protected void doStart() throws Exception
doStop()
for more details.protected void doStop() throws Exception
doStop()
method when the service is being stopped. This method
will also be invoked if the service is still in uninitialized state (eg has not been started). The
method is always called to allow the service to do custom logic when the service is being stopped, such as
when CamelContext
is shutting down.protected void doSuspend() throws Exception
Exception
protected void doResume() throws Exception
Exception
protected void doShutdown() throws Exception
Exception
protected void doFail(Exception e)
protected AutoCloseable doLifecycleChange()
Apache Camel