GeezerVison is showing netty.io — SingleThreadEventExecutor (Netty API Reference (4.1.141.Final))
Class SingleThreadEventExecutor
-
Nested Class Summary
Nested Classes
Modifier and Type
Class
Description
protected static interface
-
Constructor Summary
Constructors
Modifier
Constructor
Description
protected
protected
protected
protected
protected
-
Method Summary
Modifier and Type
Method
Description
void
Add a Runnable which will be executed on shutdown of this instance
protected void
protected void
boolean
protected void
Do nothing, sub-classes may override
protected boolean
Confirm that the shutdown if the instance should be done now!
protected long
protected long
Returns the amount of time left until the scheduled task with the closest dead line is executed.
void
protected boolean
boolean
Return true if the given Thread is executed in the event loop,
false otherwise.
protected void
Interrupt the current running Thread.
<T> T
<T> T
boolean
boolean
boolean
void
Like Executor.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.
Create a new Queue which will holds the tasks to execute.
int
Return the number of tasks that are pending for processing.
protected static void
protected final void
void
Remove a previous added Runnable as a shutdown hook
protected boolean
protected abstract void
protected boolean
Poll all tasks from the task queue and run them via Runnable.run() method.
protected boolean
Poll all tasks from the task queue and run them via Runnable.run() method.
protected final boolean
Runs all tasks from the passed taskQueue.
protected final boolean
Execute all expired scheduled tasks and all current tasks in the executor queue until both queues are empty,
or maxDrainAttempts has been exceeded.
void
Signals this executor that the caller wants the executor to be shut down.
Take the next Runnable from the task queue and so will block if no task is currently present.
protected void
Updates the internal timestamp that tells when a submitted task was executed most recently.
protected boolean
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
afterScheduledTaskSubmitted, beforeScheduledTaskSubmitted, cancelScheduledTasks, deadlineToDelayNanos, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, validateScheduled
Modifier and Type
Method
Description
protected boolean
protected boolean
Called from arbitrary non- EventExecutor threads prior to scheduled task submission.
protected void
Cancel all scheduled tasks.
protected static long
Given an arbitrary deadline deadlineNanos, calculate the number of nano seconds from now
deadlineNanos would expire.
protected long
Get the current time in nanoseconds by this executor's clock.
protected final boolean
Returns true if a scheduled task is ready for processing.
protected static long
The initial value used for delay and computations based upon a monatomic time source.
protected static long
protected final long
Return the deadline (in nanoseconds) when the next scheduled task is ready to be run or -1
if no task is scheduled.
protected final long
Return the nanoseconds until the next scheduled task is ready to be run or -1 if no task is scheduled.
Return the Runnable which is ready to be executed with the given nanoTime.
protected void
Deprecated.
will be removed in the future.
inEventLoop, iterator, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, next, parent, runTask, safeExecute, shutdownGracefully, shutdownNow, submit, submit, submit
Modifier and Type
Method
Description
boolean
Create a new Future which is marked as failed already.
Create a new Future which is marked as succeeded already.
Returns a reference to itself.
protected static void
protected static void
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
SingleThreadEventExecutor
Create a new instance
- Parameters:
parent - the EventExecutorGroup which is the parent of this instance and belongs to it
threadFactory - the ThreadFactory which will be used for the used Thread
addTaskWakesUp - true if and only if invocation of addTask(Runnable) will wake up the
executor thread
-
SingleThreadEventExecutor
Create a new instance
- Parameters:
parent - the EventExecutorGroup which is the parent of this instance and belongs to it
threadFactory - the ThreadFactory which will be used for the used Thread
addTaskWakesUp - true if and only if invocation of addTask(Runnable) will wake up the
executor thread
maxPendingTasks - the maximum number of pending tasks before new tasks will be rejected.
rejectedHandler - the RejectedExecutionHandler to use.
-
SingleThreadEventExecutor
Create a new instance
- Parameters:
parent - the EventExecutorGroup which is the parent of this instance and belongs to it
executor - the Executor which will be used for executing
addTaskWakesUp - true if and only if invocation of addTask(Runnable) will wake up the
executor thread
-
SingleThreadEventExecutor
Create a new instance
- Parameters:
parent - the EventExecutorGroup which is the parent of this instance and belongs to it
executor - the Executor which will be used for executing
addTaskWakesUp - true if and only if invocation of addTask(Runnable) will wake up the
executor thread
maxPendingTasks - the maximum number of pending tasks before new tasks will be rejected.
rejectedHandler - the RejectedExecutionHandler to use.
-
SingleThreadEventExecutor
-
Method Details
-
-
newTaskQueue
Create a new Queue which will holds the tasks to execute. This default implementation will return a
LinkedBlockingQueue but if your sub-class of SingleThreadEventExecutor will not do any blocking
calls on the this Queue it may make sense to @Override this and return some more performant
implementation that does not support blocking operations at all.
-
interruptThread
protected void interruptThread()
Interrupt the current running Thread.
-
-
-
takeTask
- Returns:
null if the executor thread has been interrupted or waken up.
-
-
hasTasks
protected boolean hasTasks()
- See Also:
-
-
pendingTasks
public int pendingTasks()
Return the number of tasks that are pending for processing.
-
-
removeTask
protected boolean removeTask(Runnable task)
- See Also:
-
-
runAllTasks
protected boolean runAllTasks()
Poll all tasks from the task queue and run them via Runnable.run() method.
- Returns:
true if and only if at least one task was run
-
runScheduledAndExecutorTasks
protected final boolean runScheduledAndExecutorTasks(int maxDrainAttempts)
Execute all expired scheduled tasks and all current tasks in the executor queue until both queues are empty,
or maxDrainAttempts has been exceeded.
- Parameters:
maxDrainAttempts - 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.
- Returns:
true if at least one task was run.
-
runAllTasksFrom
protected final boolean runAllTasksFrom(Queue<Runnable> taskQueue)
Runs all tasks from the passed taskQueue.
- Parameters:
taskQueue - To poll and execute all tasks.
- Returns:
true if at least one task was executed.
-
runAllTasks
protected boolean runAllTasks(long timeoutNanos)
Poll all tasks from the task queue and run them via Runnable.run() method. This method stops running
the tasks in the task queue and returns if it ran longer than timeoutNanos.
-
afterRunningAllTasks
protected void afterRunningAllTasks()
-
delayNanos
protected long delayNanos(long currentTimeNanos)
Returns the amount of time left until the scheduled task with the closest dead line is executed.
-
deadlineNanos
protected long deadlineNanos()
-
updateLastExecutionTime
protected void updateLastExecutionTime()
Updates the internal timestamp that tells when a submitted task was executed most recently.
runAllTasks() and runAllTasks(long) updates this timestamp automatically, and thus there's
usually no need to call this method. However, if you take the tasks manually using takeTask() or
pollTask(), you have to call this method at the end of task execution loop for accurate quiet period
checks.
-
run
protected abstract void run()
-
cleanup
protected void cleanup()
Do nothing, sub-classes may override
-
wakeup
protected void wakeup(boolean inEventLoop)
-
-
addShutdownHook
public void addShutdownHook(Runnable task)
Add a Runnable which will be executed on shutdown of this instance
-
removeShutdownHook
public void removeShutdownHook(Runnable task)
Remove a previous added Runnable as a shutdown hook
-
shutdownGracefully
public Future<?> shutdownGracefully(long quietPeriod,
long timeout,
TimeUnit unit)
Signals this executor that the caller wants the executor to be shut down. Once this method is called,
EventExecutorGroup.isShuttingDown() starts to return true, and the executor prepares to shut itself down.
Unlike EventExecutorGroup.shutdown(), graceful shutdown ensures that no tasks are submitted for 'the quiet period'
(usually a couple seconds) before it shuts itself down. If a task is submitted during the quiet period,
it is guaranteed to be accepted and the quiet period will start over.
- Specified by:
shutdownGracefully in interface EventExecutorGroup
- Parameters:
quietPeriod - the quiet period as described in the documentation
timeout - the maximum amount of time to wait until the executor is EventExecutorGroup.shutdown()
regardless if a task was submitted during the quiet period
unit - the unit of quietPeriod and timeout
- Returns:
- the
EventExecutorGroup.terminationFuture()
-
-
-
-
-
-
confirmShutdown
protected boolean confirmShutdown()
Confirm that the shutdown if the instance should be done now!
-
-
-
-
-
-
-
-
-
wakesUpForTask
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.
-
reject
protected static void reject()
-
reject
protected final void reject(Runnable task)
- Parameters:
task - to reject.
|