Package io.atomix.utils.concurrent
Interface ThreadContext
-
- All Superinterfaces:
AutoCloseable,Executor,Scheduler
- All Known Implementing Classes:
AbstractThreadContext,BlockingAwareSingleThreadContext,BlockingAwareThreadPoolContext,NullThreadContext,SingleThreadContext,ThreadPoolContext
public interface ThreadContext extends AutoCloseable, Executor, Scheduler
Thread context.The thread context is used by Catalyst to determine the correct thread on which to execute asynchronous callbacks. All threads created within Catalyst must be instances of
AtomixThread. Once a thread has been created, the context is stored in the thread object viaAtomixThread.setContext(ThreadContext). This means there is a one-to-one relationship between a context and a thread. That is, a context is representative of a thread and provides an interface for firing events on that thread.Components of the framework that provide custom threads should use
AtomixThreadFactoryto allocate new threads and provide a customThreadContextimplementation.- Author:
- Jordan Halterman
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidblock()Marks the thread context as blocked.default voidcheckThread()Checks that the current thread is the correct context thread.voidclose()Closes the context.static ThreadContextcurrentContext()Returns the current thread context.static ThreadContextcurrentContextOrThrow()booleanisBlocked()Returns whether the thread context is currently marked blocked.default booleanisCurrentContext()Returns a boolean indicating whether the current thread is in this context.voidunblock()Marks the thread context as unblocked.
-
-
-
Method Detail
-
currentContext
static ThreadContext currentContext()
Returns the current thread context.- Returns:
- The current thread context or
nullif no context exists.
-
currentContextOrThrow
static ThreadContext currentContextOrThrow()
- Throws:
IllegalStateException- if the current thread is not a catalyst thread
-
isCurrentContext
default boolean isCurrentContext()
Returns a boolean indicating whether the current thread is in this context.- Returns:
- Indicates whether the current thread is in this context.
-
checkThread
default void checkThread()
Checks that the current thread is the correct context thread.
-
isBlocked
boolean isBlocked()
Returns whether the thread context is currently marked blocked.- Returns:
- whether the thread context is currently marked blocked
-
block
void block()
Marks the thread context as blocked.
-
unblock
void unblock()
Marks the thread context as unblocked.
-
close
void close()
Closes the context.- Specified by:
closein interfaceAutoCloseable
-
-