Top Description Inners Fields Constructors Methods
io.netty.util.concurrent

public abstract Class SingleThreadEventExecutor

extends AbstractScheduledEventExecutor
implements OrderedEventExecutor
Class Inheritance
All Implemented Interfaces
io.netty.util.concurrent.OrderedEventExecutor, io.netty.util.concurrent.EventExecutor, io.netty.util.concurrent.EventExecutorGroup, java.lang.Iterable, java.util.concurrent.ScheduledExecutorService, java.util.concurrent.ExecutorService, java.lang.AutoCloseable, java.util.concurrent.Executor
Known Direct Subclasses
io.netty.util.concurrent.DefaultEventExecutor
Imports
io.netty.util.internal.ObjectUtil, .PlatformDependent, .SystemPropertyUtil, .ThreadExecutorMap, .UnstableApi, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, org.jetbrains.annotations.Async.Schedule, java.lang.Thread.State, java.util.ArrayList, .Collection, .LinkedHashSet, .List, .Queue, .Set, java.util.concurrent.BlockingQueue, .Callable, .CountDownLatch, .ExecutionException, .Executor, .LinkedBlockingQueue, .RejectedExecutionException, .ThreadFactory, .TimeUnit, .TimeoutException, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, .AtomicReferenceFieldUpdater

Abstract base class for OrderedEventExecutor's that execute all its submitted tasks in a single thread.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
protected static interface

Field Summary

Modifier and TypeField and Description
private final boolean
pack-priv static final int
private final Executor
private volatile long
private long
private volatile long
private volatile boolean
private long
private static final InternalLogger
private final int
private static final Runnable
private static final AtomicReferenceFieldUpdater<SingleThreadEventExecutor, ThreadProperties>
private final RejectedExecutionHandler
private static final long
private final Set<Runnable>
private static final int
private static final int
private static final int
private static final int
private static final int
private volatile int
private static final AtomicIntegerFieldUpdater<SingleThreadEventExecutor>
private final Queue<Runnable>
private final Promise<?>
private volatile Thread
private final CountDownLatch
private volatile ThreadProperties
Inherited from io.netty.util.concurrent.AbstractScheduledEventExecutor:
nextTaskIdscheduledTaskQueueWAKEUP_TASK

Constructor Summary

AccessConstructor and Description
protected
SingleThreadEventExecutor(EventExecutorGroup
the EventExecutorGroup which is the parent of this instance and belongs to it
parent
,
ThreadFactory
the ThreadFactory which will be used for the used Thread
threadFactory
,
boolean
true if and only if invocation of addTask(Runnable) will wake up the executor thread
addTaskWakesUp
)

Create a new instance

protected
SingleThreadEventExecutor(EventExecutorGroup
the EventExecutorGroup which is the parent of this instance and belongs to it
parent
,
ThreadFactory
the ThreadFactory which will be used for the used Thread
threadFactory
,
boolean
true if and only if invocation of addTask(Runnable) will wake up the executor thread
addTaskWakesUp
,
int
the maximum number of pending tasks before new tasks will be rejected.
maxPendingTasks
,
RejectedExecutionHandler rejectedHandler)

Create a new instance

protected
SingleThreadEventExecutor(EventExecutorGroup
the EventExecutorGroup which is the parent of this instance and belongs to it
parent
,
Executor
the Executor which will be used for executing
executor
,
boolean
true if and only if invocation of addTask(Runnable) will wake up the executor thread
addTaskWakesUp
)

Create a new instance

protected
SingleThreadEventExecutor(EventExecutorGroup
the EventExecutorGroup which is the parent of this instance and belongs to it
parent
,
Executor
the Executor which will be used for executing
executor
,
boolean
true if and only if invocation of addTask(Runnable) will wake up the executor thread
addTaskWakesUp
,
int
the maximum number of pending tasks before new tasks will be rejected.
maxPendingTasks
,
RejectedExecutionHandler rejectedHandler)

Create a new instance

protected
SingleThreadEventExecutor(EventExecutorGroup parent, Executor executor, boolean addTaskWakesUp, Queue<Runnable> taskQueue, RejectedExecutionHandler rejectedHandler)

Method Summary

Modifier and TypeMethod and Description
public void
addShutdownHook(final Runnable task)

Add a Runnable which will be executed on shutdown of this instance

protected void
addTask(Runnable task)

Add a task to the task queue, or throws a RejectedExecutionException if this instance was shutdown before.

protected void
afterRunningAllTasks()

Invoked before returning from runAllTasks() and runAllTasks(long).

public boolean
awaitTermination(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.ExecutorService.awaitTermination.

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
protected void
cleanup()

Do nothing, sub-classes may override

protected boolean
confirmShutdown()

Confirm that the shutdown if the instance should be done now!

protected long
deadlineNanos()

Returns the absolute point in time (relative to getCurrentTimeNanos()) at which the next closest scheduled task should run.

protected long
delayNanos(long currentTimeNanos)

Returns the amount of time left until the scheduled task with the closest dead line is executed.

private void
pack-priv final int
private boolean
ensureThreadStarted(int oldState)

public void
execute(Runnable
the runnable task
task
)

Implements java.util.concurrent.Executor.execute.

Executes the given command at some time in the future.
private void
execute(Runnable task, boolean immediate)

private void
private boolean

Returns:

true if at least one scheduled task was executed.
executeExpiredScheduledTasks
()

private boolean
protected boolean
public boolean
inEventLoop(Thread thread)

Implements io.netty.util.concurrent.EventExecutor.inEventLoop.

Return true if the given Thread is executed in the event loop, false otherwise.
protected void
interruptThread()

Interrupt the current running Thread.

public <T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>>
the collection of tasks
tasks
)

Overrides java.util.concurrent.AbstractExecutorService.invokeAll.

Implements java.util.concurrent.ExecutorService.invokeAll.

Executes the given tasks, returning a list of Futures holding their status and results when all complete.
public <T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>>
the collection of tasks
tasks
,
long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Overrides java.util.concurrent.AbstractExecutorService.invokeAll.

Implements java.util.concurrent.ExecutorService.invokeAll.

Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first.
public <T> T
invokeAny(Collection<? extends Callable<T>>
the collection of tasks
tasks
)

Overrides java.util.concurrent.AbstractExecutorService.invokeAny.

Implements java.util.concurrent.ExecutorService.invokeAny.

Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do.
public <T> T
invokeAny(Collection<? extends Callable<T>>
the collection of tasks
tasks
,
long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Overrides java.util.concurrent.AbstractExecutorService.invokeAny.

Implements java.util.concurrent.ExecutorService.invokeAny.

Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do before the given timeout elapses.
public boolean
isShutdown()

Implements java.util.concurrent.ExecutorService.isShutdown.

Returns true if this executor has been shut down.
public boolean
public boolean
isTerminated()

Implements java.util.concurrent.ExecutorService.isTerminated.

Returns true if all tasks have completed following shut down.
public void
lazyExecute(Runnable task)

Overrides io.netty.util.concurrent.AbstractEventExecutor.lazyExecute.

Like execute(Runnable) but does not guarantee the task will be run until either a non-lazy task is executed or the executor is shut down.
private void
protected Queue<Runnable>
newTaskQueue()

Deprecated Please use and override newTaskQueue(int).
protected Queue<Runnable>
newTaskQueue(int maxPendingTasks)

Create a new Queue which will holds the tasks to execute.

pack-priv final boolean
protected Runnable
public int
pendingTasks()

Return the number of tasks that are pending for processing.

protected Runnable
protected static Runnable
protected static void
protected final void
reject(Runnable
to reject.
task
)

Offers the task to the associated RejectedExecutionHandler.

public void
removeShutdownHook(final Runnable task)

Remove a previous added Runnable as a shutdown hook

protected boolean
protected abstract void
run()

Run the tasks in the taskQueue

protected boolean

Returns:

true if and only if at least one task was run
runAllTasks
()

Poll all tasks from the task queue and run them via Runnable#run() method.

protected boolean
runAllTasks(long timeoutNanos)

Poll all tasks from the task queue and run them via Runnable#run() method.

protected final boolean

Returns:

true if at least one task was executed.
runAllTasksFrom
(Queue<Runnable>
To poll and execute all tasks.
taskQueue
)

Runs all tasks from the passed taskQueue.

private boolean

Returns:

true if at least Runnable#run() was called.
runExistingTasksFrom
(Queue<Runnable>
the task queue to drain.
taskQueue
)

What ever tasks are present in taskQueue when this method is invoked will be Runnable#run().

protected final boolean

Returns:

true if at least one task was run.
runScheduledAndExecutorTasks
(final int
The maximum amount of times this method attempts to drain from queues. This is to prevent continuous task execution and scheduling from preventing the EventExecutor thread to make progress and return to the selector mechanism to process inbound I/O events.
maxDrainAttempts
)

Execute all expired scheduled tasks and all current tasks in the executor queue until both queues are empty, or maxDrainAttempts has been exceeded.

private boolean
public void
shutdown()

Implements abstract io.netty.util.concurrent.AbstractEventExecutor.shutdown.

Implements io.netty.util.concurrent.EventExecutorGroup.shutdown, java.util.concurrent.ExecutorService.shutdown.

Deprecated
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
public Future<?>
shutdownGracefully(long
the quiet period as described in the documentation
quietPeriod
,
long
the maximum amount of time to wait until the executor is shutdown() regardless if a task was submitted during the quiet period
timeout
,
TimeUnit
the unit of quietPeriod and timeout
unit
)

Implements io.netty.util.concurrent.EventExecutorGroup.shutdownGracefully.

Signals this executor that the caller wants the executor to be shut down.
private void
protected Runnable

Returns:

null if the executor thread has been interrupted or waken up.
takeTask
()

Take the next Runnable from the task queue and so will block if no task is currently present.

public Future<?>
terminationFuture()

Implements io.netty.util.concurrent.EventExecutorGroup.terminationFuture.

Returns the Future which is notified when all EventExecutors managed by this EventExecutorGroup have been terminated.
public final ThreadProperties
private void
protected void
updateLastExecutionTime()

Updates the internal timestamp that tells when a submitted task was executed most recently.

protected boolean
wakesUpForTask(Runnable task)

Can be overridden to control which tasks require waking the EventExecutor thread if it is waiting so that they can be run immediately.

protected void
wakeup(boolean inEventLoop)

Inherited from io.netty.util.concurrent.AbstractScheduledEventExecutor:
afterScheduledTaskSubmittedbeforeScheduledTaskSubmittedcancelScheduledTasksdeadlineNanosdeadlineToDelayNanosdefaultCurrentTimeNanosgetCurrentTimeNanoshasScheduledTasksinitialNanoTimenanoTimenextScheduledTaskDeadlineNanosnextScheduledTaskNanopeekScheduledTaskpollScheduledTaskpollScheduledTaskremoveScheduledscheduleschedulescheduleAtFixedRatescheduledTaskQueuescheduleFromEventLoopscheduleWithFixedDelayvalidateScheduled