Class BaseService
java.lang.Object
org.apache.camel.support.service.BaseService
- Direct Known Subclasses:
ServiceSupport
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 implement
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.- Since:
- 3.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final byteprotected static final byteprotected static final byteprotected static final byteprotected final Lockprotected static final byteprotected static final byteprotected static final byteprotected static final byteprotected static final byteprotected byteprotected static final byteprotected static final byteprotected static final byteprotected static final byte -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbuild()Builds the service.protected voiddoBuild()Optional build phase of the service.protected voidImplementations override this method to perform any action upon failure.protected voiddoInit()Initialize the service.protected @Nullable AutoCloseableImplementations 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 voidImplementations 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 voidImplementations override this method to support customized suspend/resume.protected voidprotected LockReturns the current status of the service.voidinit()Initializes the service.booleanisBuild()Returns true if the service is in the BUILT state.booleanisInit()Returns true if the service is in the INITIALIZED state.booleanisNew()Returns true if the service is in the NEW state (not yet built).booleanReturns true if the service is allowed to process exchanges (started, starting, or suspended).booleanReturns true if the service is in the SHUTDOWN state.booleanReturns true if the service is in the STARTED state.booleanReturns true if the service is in the STARTING state.booleanIs the service in progress of being suspended or already suspendedbooleanReturns true if the service is stopped (not yet started or already stopped).booleanReturns true if the service is in the STOPPING state.booleanIs the service in progress of being stopped or already stoppedbooleanReturns true if the service is in the SUSPENDED state.booleanReturns true if the service is in the SUSPENDING state.booleanIs the service in progress of being suspended or already suspendedvoidresume()voidshutdown()voidstart()voidstop()voidsuspend()
-
Field Details
-
NEW
protected static final byte NEW- See Also:
-
BUILT
protected static final byte BUILT- See Also:
-
INITIALIZING
protected static final byte INITIALIZING- See Also:
-
INITIALIZED
protected static final byte INITIALIZED- See Also:
-
STARTING
protected static final byte STARTING- See Also:
-
STARTED
protected static final byte STARTED- See Also:
-
SUSPENDING
protected static final byte SUSPENDING- See Also:
-
SUSPENDED
protected static final byte SUSPENDED- See Also:
-
STOPPING
protected static final byte STOPPING- See Also:
-
STOPPED
protected static final byte STOPPED- See Also:
-
SHUTTING_DOWN
protected static final byte SHUTTING_DOWN- See Also:
-
SHUTDOWN
protected static final byte SHUTDOWN- See Also:
-
FAILED
protected static final byte FAILED- See Also:
-
lock
-
status
protected volatile byte status
-
-
Constructor Details
-
BaseService
public BaseService()
-
-
Method Details
-
build
public void build()Builds the service. This method will only be called once and transitions the service from NEW to BUILT state. -
init
public void init()Initializes the service. This method will only be called once before starting. -
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
Returns the current status of the service. -
isNew
public boolean isNew()Returns true if the service is in the NEW state (not yet built). -
isBuild
public boolean isBuild()Returns true if the service is in the BUILT state. -
isInit
public boolean isInit()Returns true if the service is in the INITIALIZED state. -
isStarted
public boolean isStarted()Returns true if the service is in the STARTED state. -
isStarting
public boolean isStarting()Returns true if the service is in the STARTING state. -
isStopping
public boolean isStopping()Returns true if the service is in the STOPPING state. -
isStopped
public boolean isStopped()Returns true if the service is stopped (not yet started or already stopped). -
isSuspending
public boolean isSuspending()Returns true if the service is in the SUSPENDING state. -
isSuspended
public boolean isSuspended()Returns true if the service is in the SUSPENDED state. -
isRunAllowed
public boolean isRunAllowed()Returns true if the service is allowed to process exchanges (started, starting, or suspended). -
isShutdown
public boolean isShutdown()Returns true if the service is in the SHUTDOWN state. -
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
-
doBuild
-
doInit
-
doStart
-
doStop
Implementations 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.- Throws:
Exception- See Also:
-
doSuspend
-
doResume
-
doShutdown
-
doFail
Implementations override this method to perform any action upon failure. -
doLifecycleChange
Implementations may return an object that will be closed when the lifecycle action is completed. -
getInternalLock
-