Package org.threadly.util
Interface Service
-
- All Known Implementing Classes:
AbstractService
,BlockingQueueConsumer
public interface Service
A service is defined as something which is constructed in a stopped state (unless the constructor starts the service automatically). It is then at some point started, and at some future point stopped. Once stopped it is expected that this "Service" can no longer be used.- Since:
- 4.3.0 (since 3.8.0 as ServiceInterface)
-
-
Method Summary
All Methods Instance Methods Abstract 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
void start() throws java.lang.IllegalStateException
Starts the service, blocking until the service is running.- Throws:
java.lang.IllegalStateException
- thrown if the service has already been started
-
startIfNotStarted
boolean startIfNotStarted()
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.- Returns:
true
if the service has been started from this call
-
stop
void stop()
Stops the service, blocking until the service is shutdown.- Throws:
java.lang.IllegalStateException
- thrown if the service has never been started, or is already shutdown
-
stopIfRunning
boolean stopIfRunning()
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.- Returns:
true
if the service has been stopped from this call
-
isRunning
boolean isRunning()
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 seehasStopped()
.- Returns:
true
if the service is currently running
-
hasStopped
boolean hasStopped()
Call to check if the service has been stopped (and thus can no longer be used). This is different fromisRunning()
in that it will returnfalse
untilstop()
orstopIfRunning()
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.- Returns:
true
if the server has been stopped
-
-