public class SingleThreadContext extends Object implements ThreadContext
This is a basic ThreadContext implementation that uses a
ScheduledExecutorService to schedule events on the context thread.
| Constructor and Description |
|---|
SingleThreadContext(CatalystThreadFactory factory,
Serializer serializer)
Creates a new single thread context.
|
SingleThreadContext(ScheduledExecutorService executor,
Serializer serializer)
Creates a new single thread context.
|
SingleThreadContext(String nameFormat,
Serializer serializer)
Creates a new single thread context.
|
SingleThreadContext(Thread thread,
ScheduledExecutorService executor,
Serializer serializer) |
| Modifier and Type | Method and Description |
|---|---|
void |
block()
Sets the context state to blocked.
|
void |
close()
Closes the context.
|
Executor |
executor()
Returns the underlying executor.
|
boolean |
isBlocked()
Returns a boolean indicating whether the context state is blocked.
|
org.slf4j.Logger |
logger()
Returns the context logger.
|
Scheduled |
schedule(Duration delay,
Duration interval,
Runnable runnable)
Schedules a runnable at a fixed rate on the context.
|
Scheduled |
schedule(Duration delay,
Runnable runnable)
Schedules a runnable on the context.
|
Serializer |
serializer()
Returns the context serializer.
|
void |
unblock()
Sets the context state to unblocked.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcheckThread, currentContext, currentContextOrThrow, execute, execute, isCurrentContextpublic SingleThreadContext(String nameFormat, Serializer serializer)
The provided context name will be passed to CatalystThreadFactory and used
when instantiating the context thread.
nameFormat - The context nameFormat which will be formatted with a thread number.serializer - The context serializer.public SingleThreadContext(CatalystThreadFactory factory, Serializer serializer)
factory - The thread factory.serializer - The context serializer.public SingleThreadContext(ScheduledExecutorService executor, Serializer serializer)
executor - The executor on which to schedule events. This must be a single thread scheduled executor.serializer - The context serializer.public SingleThreadContext(Thread thread, ScheduledExecutorService executor, Serializer serializer)
public void block()
ThreadContextblock in interface ThreadContextpublic void unblock()
ThreadContextunblock in interface ThreadContextpublic boolean isBlocked()
ThreadContextisBlocked in interface ThreadContextpublic org.slf4j.Logger logger()
ThreadContextlogger in interface ThreadContextpublic Serializer serializer()
ThreadContextserializer in interface ThreadContextpublic Executor executor()
ThreadContextexecutor in interface ThreadContextpublic Scheduled schedule(Duration delay, Runnable runnable)
ThreadContextschedule in interface ThreadContextdelay - The delay at which to schedule the runnable.runnable - The callback to schedule.public Scheduled schedule(Duration delay, Duration interval, Runnable runnable)
ThreadContextschedule in interface ThreadContextrunnable - The callback to schedule.public void close()
ThreadContextclose in interface ThreadContextclose in interface AutoCloseableCopyright © 2013–2016. All rights reserved.