public interface Context extends AutoCloseable
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 CatalystThread. Once
a thread has been created, the context is stored in the thread object via
CatalystThread.setContext(Context). 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.
In addition to serving as an Executor, the context also provides thread-local storage
for Serializer serializer instances. All serialization that takes place within a
CatalystThread should use the context serializer().
Components of the framework that provide custom threads should use CatalystThreadFactory
to allocate new threads and provide a custom Context implementation.
| Modifier and Type | Method and Description |
|---|---|
default void |
checkThread()
Checks that the current thread is the correct context thread.
|
void |
close()
Closes the context.
|
static Context |
currentContext()
Returns the current thread context.
|
default CompletableFuture<Void> |
execute(Runnable callback)
Executes a callback on the context.
|
default <T> CompletableFuture<T> |
execute(Supplier<T> callback)
Executes a callback on the context.
|
Executor |
executor()
Returns the underlying executor.
|
org.slf4j.Logger |
logger()
Returns the context logger.
|
Scheduled |
schedule(Runnable callback,
Duration delay)
Schedules a runnable on the context.
|
Scheduled |
schedule(Runnable callback,
Duration initialDelay,
Duration interval)
Schedules a runnable at a fixed rate on the context.
|
Serializer |
serializer()
Returns the context serializer.
|
static Context currentContext()
null if no context exists.default void checkThread()
org.slf4j.Logger logger()
Serializer serializer()
Executor executor()
default CompletableFuture<Void> execute(Runnable callback)
callback - The callback to execute.default <T> CompletableFuture<T> execute(Supplier<T> callback)
T - The callback result type.callback - The callback to execute.Scheduled schedule(Runnable callback, Duration delay)
callback - The callback to schedule.delay - The delay at which to schedule the runnable.Scheduled schedule(Runnable callback, Duration initialDelay, Duration interval)
callback - The callback to schedule.initialDelay - The delay at which to schedule the runnable.interval - The interval at which to run the task.void close()
close in interface AutoCloseableCopyright © 2013–2015. All rights reserved.