Package org.apache.camel.support.service
Class BaseService
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- Direct Known Subclasses:
ServiceSupport
public abstract class BaseService extends Object
A useful base class which ensures that a service is only initialized once and provides some helper methods for enquiring of its status. Implementations can extend this base class and implementSuspendableServicein case they support suspend/resume. Important: You should override the lifecycle methods that start with do, egdoStart()},doStop(), etc. where you implement your logic. The methodsstart(),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.
-
-
Field Summary
Fields Modifier and Type Field Description protected static byteBUILTprotected static byteFAILEDprotected static byteINITIALIZEDprotected static byteINITIALIZINGprotected Objectlockprotected static byteNEWprotected static byteSHUTDOWNprotected static byteSHUTTING_DOWNprotected static byteSTARTEDprotected static byteSTARTINGprotected bytestatusprotected static byteSTOPPEDprotected static byteSTOPPINGprotected static byteSUSPENDEDprotected static byteSUSPENDING
-
Constructor Summary
Constructors Constructor Description BaseService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuild()protected voiddoBuild()Optional build phase of the service.protected voiddoFail(Exception e)Implementations override this method to perform any action upon failure.protected voiddoInit()Initialize the service.protected AutoCloseabledoLifecycleChange()Implementations may return an object that will be closed when the lifecycle action is completed.protected voiddoResume()Implementations override this method to support customized suspend/resume.protected voiddoShutdown()Implementations override this method to perform customized shutdown.protected voiddoStart()Implementations override this method to support customized start/stop.protected voiddoStop()Implementations override this method to support customized start/stop.protected voiddoSuspend()Implementations override this method to support customized suspend/resume.protected voidfail(Exception e)ServiceStatusgetStatus()voidinit()booleanisBuild()booleanisInit()booleanisNew()booleanisRunAllowed()booleanisShutdown()booleanisStarted()booleanisStarting()booleanisStartingOrStarted()Is the service in progress of being suspended or already suspendedbooleanisStopped()booleanisStopping()booleanisStoppingOrStopped()Is the service in progress of being stopped or already stoppedbooleanisSuspended()booleanisSuspending()booleanisSuspendingOrSuspended()Is the service in progress of being suspended or already suspendedvoidresume()voidshutdown()voidstart()voidstop()voidsuspend()
-
-
-
Field Detail
-
NEW
protected static final byte NEW
- See Also:
- Constant Field Values
-
BUILT
protected static final byte BUILT
- See Also:
- Constant Field Values
-
INITIALIZING
protected static final byte INITIALIZING
- See Also:
- Constant Field Values
-
INITIALIZED
protected static final byte INITIALIZED
- See Also:
- Constant Field Values
-
STARTING
protected static final byte STARTING
- See Also:
- Constant Field Values
-
STARTED
protected static final byte STARTED
- See Also:
- Constant Field Values
-
SUSPENDING
protected static final byte SUSPENDING
- See Also:
- Constant Field Values
-
SUSPENDED
protected static final byte SUSPENDED
- See Also:
- Constant Field Values
-
STOPPING
protected static final byte STOPPING
- See Also:
- Constant Field Values
-
STOPPED
protected static final byte STOPPED
- See Also:
- Constant Field Values
-
SHUTTING_DOWN
protected static final byte SHUTTING_DOWN
- See Also:
- Constant Field Values
-
SHUTDOWN
protected static final byte SHUTDOWN
- See Also:
- Constant Field Values
-
FAILED
protected static final byte FAILED
- See Also:
- Constant Field Values
-
lock
protected final Object lock
-
status
protected volatile byte status
-
-
Method Detail
-
build
public void build()
-
init
public void init()
-
start
public void start()
Important: You should override the lifecycle methods that start with do, egdoStart(),doStop(), etc. where you implement your logic. The methodsstart(),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.
-
stop
public void stop()
Important: You should override the lifecycle methods that start with do, egdoStart(),doStop(), etc. where you implement your logic. The methodsstart(),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.
-
suspend
public void suspend()
Important: You should override the lifecycle methods that start with do, egdoStart(),doStop(), etc. where you implement your logic. The methodsstart(),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.
-
resume
public void resume()
Important: You should override the lifecycle methods that start with do, egdoStart(),doStop(), etc. where you implement your logic. The methodsstart(),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.
-
shutdown
public void shutdown()
Important: You should override the lifecycle methods that start with do, egdoStart(),doStop(), etc. where you implement your logic. The methodsstart(),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.
-
getStatus
public ServiceStatus getStatus()
-
isNew
public boolean isNew()
-
isBuild
public boolean isBuild()
-
isInit
public boolean isInit()
-
isStarted
public boolean isStarted()
-
isStarting
public boolean isStarting()
-
isStopping
public boolean isStopping()
-
isStopped
public boolean isStopped()
-
isSuspending
public boolean isSuspending()
-
isSuspended
public boolean isSuspended()
-
isRunAllowed
public boolean isRunAllowed()
-
isShutdown
public boolean isShutdown()
-
isStoppingOrStopped
public boolean isStoppingOrStopped()
Is the service in progress of being stopped or already stopped
-
isSuspendingOrSuspended
public boolean isSuspendingOrSuspended()
Is the service in progress of being suspended or already suspended
-
isStartingOrStarted
public boolean isStartingOrStarted()
Is the service in progress of being suspended or already suspended
-
fail
protected void fail(Exception e)
-
doBuild
protected void doBuild() throws ExceptionOptional build phase of the service. This method will only be called by frameworks which supports pre-building projects such as camel-quarkus.- Throws:
Exception
-
doInit
protected void doInit() throws ExceptionInitialize the service. This method will only be called once before starting.- Throws:
Exception
-
doStart
protected void doStart() throws ExceptionImplementations override this method to support customized start/stop. Important: SeedoStop()for more details.
-
doStop
protected void doStop() throws ExceptionImplementations override this method to support customized start/stop. Important: Camel will invoke thisdoStop()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 whenCamelContextis shutting down.
-
doSuspend
protected void doSuspend() throws ExceptionImplementations override this method to support customized suspend/resume.- Throws:
Exception
-
doResume
protected void doResume() throws ExceptionImplementations override this method to support customized suspend/resume.- Throws:
Exception
-
doShutdown
protected void doShutdown() throws ExceptionImplementations override this method to perform customized shutdown.- Throws:
Exception
-
doFail
protected void doFail(Exception e)
Implementations override this method to perform any action upon failure.
-
doLifecycleChange
protected AutoCloseable doLifecycleChange()
Implementations may return an object that will be closed when the lifecycle action is completed.
-
-