Module com.github.akurilov.commons
Class AsyncRunnableBase
- java.lang.Object
-
- com.github.akurilov.commons.concurrent.AsyncRunnableBase
-
- All Implemented Interfaces:
AsyncRunnable,java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
DaemonBase
public abstract class AsyncRunnableBase extends java.lang.Object implements AsyncRunnable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.github.akurilov.commons.concurrent.AsyncRunnable
AsyncRunnable.State
-
-
Constructor Summary
Constructors Constructor Description AsyncRunnableBase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AsyncRunnableBaseawait()Wait while the state is STARTEDbooleanawait(long timeout, java.util.concurrent.TimeUnit timeUnit)voidclose()protected voiddoClose()protected voiddoShutdown()protected voiddoStart()protected voiddoStop()booleanisClosed()booleanisInitial()booleanisShutdown()booleanisStarted()booleanisStopped()AsyncRunnableBaseshutdown()Notify to stop to enqueue incoming requests.AsyncRunnableBasestart()Start/resume the executionAsyncRunnable.Statestate()AsyncRunnableBasestop()Stop (with further resumption capability)
-
-
-
Method Detail
-
state
public final AsyncRunnable.State state()
- Specified by:
statein interfaceAsyncRunnable- Returns:
- the current state, null if closed
-
isInitial
public boolean isInitial()
- Specified by:
isInitialin interfaceAsyncRunnable- Returns:
- true if the state is "initial", false otherwise
-
isStarted
public boolean isStarted()
- Specified by:
isStartedin interfaceAsyncRunnable- Returns:
- true if the state is "started", false otherwise
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdownin interfaceAsyncRunnable- Returns:
- true if the state is "shutdown", false otherwise
-
isStopped
public boolean isStopped()
- Specified by:
isStoppedin interfaceAsyncRunnable- Returns:
- true if the state is "stopped", false otherwise
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin interfaceAsyncRunnable- Returns:
- true if there's no state, false otherwise
-
start
public final AsyncRunnableBase start()
Description copied from interface:AsyncRunnableStart/resume the execution- Specified by:
startin interfaceAsyncRunnable- Returns:
- the same instance with state changed to STARTED if call was successful.
-
shutdown
public final AsyncRunnableBase shutdown()
Description copied from interface:AsyncRunnableNotify to stop to enqueue incoming requests. The await method should be used after this to make sure that everything accepted before the shutdown is done.- Specified by:
shutdownin interfaceAsyncRunnable
-
stop
public final AsyncRunnableBase stop()
Description copied from interface:AsyncRunnableStop (with further resumption capability)- Specified by:
stopin interfaceAsyncRunnable- Returns:
- the same instance with state changed to STOPPED if call was successful
-
await
public final AsyncRunnableBase await() throws java.lang.InterruptedException
Description copied from interface:AsyncRunnableWait while the state is STARTED- Specified by:
awaitin interfaceAsyncRunnable- Returns:
- the same instance
- Throws:
java.lang.InterruptedException
-
await
public boolean await(long timeout, java.util.concurrent.TimeUnit timeUnit) throws java.lang.InterruptedException- Specified by:
awaitin interfaceAsyncRunnable- Throws:
java.lang.InterruptedException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
doStart
protected void doStart()
-
doShutdown
protected void doShutdown()
-
doStop
protected void doStop()
-
doClose
protected void doClose() throws java.io.IOException- Throws:
java.io.IOException
-
-