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 theService
interface.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 boolean
hasStopped()
Call to check if the service has been stopped (and thus can no longer be used).boolean
isRunning()
Call to check if the service has been started, and not shutdown yet.void
start()
Starts the service, blocking until the service is running.boolean
startIfNotStarted()
Starts the service if it has not already been started.void
stop()
Stops the service, blocking until the service is shutdown.boolean
stopIfRunning()
Stops the service if it currently running.
-
-
-
Method Detail
-
start
public void start() throws java.lang.IllegalStateException
Description copied from interface:Service
Starts the service, blocking until the service is running.
-
startIfNotStarted
public boolean startIfNotStarted()
Description copied from interface:Service
Starts 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:
startIfNotStarted
in interfaceService
- Returns:
true
if the service has been started from this call
-
stop
public void stop()
Description copied from interface:Service
Stops the service, blocking until the service is shutdown.
-
stopIfRunning
public boolean stopIfRunning()
Description copied from interface:Service
Stops 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:
stopIfRunning
in interfaceService
- Returns:
true
if the service has been stopped from this call
-
isRunning
public boolean isRunning()
Description copied from interface:Service
Call 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:Service
Call to check if the service has been stopped (and thus can no longer be used). This is different fromService.isRunning()
in that it will returnfalse
untilService.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:
hasStopped
in interfaceService
- Returns:
true
if the server has been stopped
-
-