Package io.atomix.utils.concurrent
Interface ThreadContext
- All Superinterfaces:
AutoCloseable,Executor,Scheduler
- All Known Implementing Classes:
AbstractThreadContext,NullThreadContext,SingleThreadContext
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 via
AtomixThread.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 AtomixThreadFactory
to allocate new threads and provide a custom ThreadContext implementation.
- Author:
- Jordan Halterman
-
Method Summary
Modifier and TypeMethodDescriptionvoidblock()Marks the thread context as blocked.default voidChecks that the current thread is the correct context thread.voidclose()Closes the context.static ThreadContextReturns the current thread context.booleanReturns whether the thread context is currently marked blocked.default booleanReturns a boolean indicating whether the current thread is in this context.voidunblock()Marks the thread context as unblocked.
-
Method Details
-
currentContext
Returns the current thread context.- Returns:
- The current thread context or
nullif no context exists.
-
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
-