Package org.threadly.util
Class AbstractService
- java.lang.Object
-
- org.threadly.util.AbstractService
-
- All Implemented Interfaces:
Service
- Direct Known Subclasses:
BlockingQueueConsumer
public abstract class AbstractService extends java.lang.Object implements Service
An abstract implementation of theServiceinterface.This implementation is flexible, weather the internal service is scheduled on a thread pool runs on a unique thread, or has other means of running.
- Since:
- 2.6.0
-
-
Constructor Summary
Constructors Constructor Description AbstractService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasStopped()Call to check if the service has been stopped (and thus can no longer be used).booleanisRunning()Call to check if the service has been started, and not shutdown yet.voidstart()Starts the service, blocking until the service is running.booleanstartIfNotStarted()Starts the service if it has not already been started.voidstop()Stops the service, blocking until the service is shutdown.booleanstopIfRunning()Stops the service if it currently running.
-
-
-
Method Detail
-
start
public void start() throws java.lang.IllegalStateExceptionDescription copied from interface:ServiceStarts the service, blocking until the service is running.
-
startIfNotStarted
public boolean startIfNotStarted()
Description copied from interface:ServiceStarts the service if it has not already been started. If the service has been started this invocation will do nothing (except returnfalse). If this call starts the service the thread will block until the service is running.- Specified by:
startIfNotStartedin interfaceService- Returns:
trueif the service has been started from this call
-
stop
public void stop()
Description copied from interface:ServiceStops the service, blocking until the service is shutdown.
-
stopIfRunning
public boolean stopIfRunning()
Description copied from interface:ServiceStops the service if it currently running. If the service has been stopped already, or never started this invocation will do nothing (except returnfalse). If this call stops the service the thread will block until the service is shutdown.- Specified by:
stopIfRunningin interfaceService- Returns:
trueif the service has been stopped from this call
-
isRunning
public boolean isRunning()
Description copied from interface:ServiceCall to check if the service has been started, and not shutdown yet. If you need a check that will be consistent while both new and while running please seeService.hasStopped().
-
hasStopped
public boolean hasStopped()
Description copied from interface:ServiceCall to check if the service has been stopped (and thus can no longer be used). This is different fromService.isRunning()in that it will returnfalseuntilService.stop()orService.stopIfRunning()has been invoked. Thus allowing you to make a check that's state will be consistent when it is new and while it is running.- Specified by:
hasStoppedin interfaceService- Returns:
trueif the server has been stopped
-
-