|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectca.uhn.hl7v2.concurrent.Service
public abstract class Service
Base class for a unified management of threads with a defined lifecycle. It
uses a keepRunning flag to regularly terminate a thread. Classes
implementing this class must implement handle() to do the main
processing. afterStartup() and afterTermination() can be
overridden to acquire and release resources required for processing.
| Constructor Summary | |
|---|---|
Service(String name,
ExecutorService executorService)
|
|
| Method Summary | |
|---|---|
protected void |
afterStartup()
Prepare any resources before entering the main thread. |
protected void |
afterTermination()
Clean up any resources initialized in afterStartup(). |
ExecutorService |
getExecutorService()
|
Throwable |
getServiceExitedWithException()
If this service exited with an exception, ths method returns that exception. |
protected abstract void |
handle()
The main task of the thread, called in a loop as long as isRunning() returns true. |
boolean |
isRunning()
|
protected void |
prepareTermination()
Prepare thread to leave its main loop. |
void |
run()
Runs the thread. |
protected void |
setServiceExitedWithException(Throwable theThreadExitedWithException)
Provide the exception which caused this service to fail |
void |
setShutdownTimeout(long shutdownTimeout)
Sets the time in milliseconds how long stopAndWait() should wait
for the thread to terminate. |
void |
start()
Starts the server listening for connections in a new thread. |
void |
stop()
Advises the thread to leave its main loop. |
void |
stopAndWait()
Stops the thread by leaving its main loop. |
void |
waitForTermination()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Service(String name,
ExecutorService executorService)
| Method Detail |
|---|
public boolean isRunning()
true if the server has been started, and has
not yet been stopped.public ExecutorService getExecutorService()
public void setShutdownTimeout(long shutdownTimeout)
stopAndWait() should wait
for the thread to terminate. Defaults to 3000ms.
shutdownTimeout - public void start()
stop() is called.
protected void afterStartup()
RuntimeException - if resources could not acquired. In this case, the thread
will shutdown. Note that afterTermination() is
called before.protected abstract void handle()
isRunning() returns true. Overridden methods are responsible for
yielding or pausing the thread when it's idle. The method must also not
block indefinitely so that a call to stop() is able to
gracefully terminate the thread.
Throwable - any exception thrown will terminate the thread.public void stop()
#beforeTermination() is
called before this method returns. afterTermination() is
called after the thread has left its main loop.
public void waitForTermination()
public final void stopAndWait()
afterTermination() is
called before the thread is terminated. The method waits until the thread
has stopped.
Exception - if the thread has not finished within shutdownTimeoutprotected void afterTermination()
afterStartup().
protected void prepareTermination()
keepRunning
to false, but some implementations may need to do additional stuff.
public final void run()
run in interface RunnableRunnable.run()protected void setServiceExitedWithException(Throwable theThreadExitedWithException)
public Throwable getServiceExitedWithException()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||