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

public final Class GlobalEventExecutor

extends AbstractScheduledEventExecutor
implements OrderedEventExecutor
Class Inheritance
All Implemented Interfaces
io.netty5.util.concurrent.OrderedEventExecutor, io.netty5.util.concurrent.EventExecutor, io.netty5.util.concurrent.FuturePromiseFactory, io.netty5.util.concurrent.EventExecutorGroup, java.util.concurrent.Executor, java.lang.Iterable
Imports
io.netty5.util.internal.ThreadExecutorMap, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, org.jetbrains.annotations.Async.Execute, .Async.Schedule, java.security.AccessController, .PrivilegedAction, java.util.Queue, java.util.concurrent.BlockingQueue, .Executors, .LinkedBlockingQueue, .RejectedExecutionException, .ThreadFactory, .TimeUnit, java.util.concurrent.atomic.AtomicBoolean

Single-thread singleton EventExecutor. It starts the thread automatically and stops it when there is no task pending in the task queue for 1 second. Please note it is not scalable to schedule large number of tasks to this executor; use a dedicated executor.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
public static final GlobalEventExecutor
private static final InternalLogger
private final RunnableScheduledFutureAdapter<Void>
private static final long
private final AtomicBoolean
private final BlockingQueue<Runnable>
private final GlobalEventExecutor.TaskRunner
private final Future<Void>
pack-priv volatile Thread
pack-priv final ThreadFactory
Inherited from io.netty5.util.concurrent.AbstractScheduledEventExecutor:
START_TIME

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
addTask(Runnable task)

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

public boolean

Returns:

true if and only if the worker thread has been terminated
awaitInactivity
(long timeout, TimeUnit unit)

Waits until the worker thread of this executor has no tasks left in its task queue and terminates itself.

public boolean
awaitTermination(long
The non-negative maximum amount of time to wait for the executor group to terminate.
timeout
,
TimeUnit
The non-null time unit of the timeout.
unit
)

Overrides default io.netty5.util.concurrent.EventExecutorGroup.awaitTermination.

Wait for this EventExecutorGroup to terminate, up to the given timeout.
public void
execute(Runnable
the runnable task
task
)

Implements io.netty5.util.concurrent.EventExecutor.execute.

Executes the given command at some time in the future.
private void
public boolean
inEventLoop(Thread thread)

Implements io.netty5.util.concurrent.EventExecutor.inEventLoop.

Return true if the given Thread is executed in the event loop, false otherwise.
public boolean
isShutdown()

Implements io.netty5.util.concurrent.EventExecutorGroup.isShutdown.

Returns true if all EventExecutors managed by this EventExecutorGroup have been shut down gracefully and moved past the grace period so that they are no longer accepting any new tasks.
public boolean
public boolean
isTerminated()

Overrides default io.netty5.util.concurrent.EventExecutorGroup.isTerminated.

Returns true if all EventExecutors managed by this EventExecutorGroup are shut down, and all of their tasks have completed.
public int
pendingTasks()

Return the number of tasks that are pending for processing.

public Future<Void>
shutdownGracefully(long
the quiet period as described in the documentation
quietPeriod
,
long
the maximum amount of time to wait until the executor is shutting down regardless if a task was submitted during the quiet period.
timeout
,
TimeUnit
the unit of quietPeriod and timeout
unit
)

Implements io.netty5.util.concurrent.EventExecutorGroup.shutdownGracefully.

Signals this executor that the caller wants the executor to be shut down.
private void
private 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<Void>
terminationFuture()

Implements io.netty5.util.concurrent.EventExecutorGroup.terminationFuture.

Returns the Future which is notified when all EventExecutors managed by this EventExecutorGroup have been terminated.
Inherited from io.netty5.util.concurrent.AbstractScheduledEventExecutor:
cancelScheduledTasksdeadlineNanosdefaultCurrentTimeNanosgetCurrentTimeNanoshasScheduledTasksinitialNanoTimenanoTimenewRunnableScheduledFuturenewScheduledTaskFornextScheduledTaskNanopeekScheduledTaskpollScheduledTaskpollScheduledTaskremoveScheduledschedulescheduleschedulescheduleAtFixedRatescheduledTaskQueuescheduleWithFixedDelay

Field Detail

INSTANCEback to summary
public static final GlobalEventExecutor INSTANCE
loggerback to summary
private static final InternalLogger logger

Hides io.netty5.util.concurrent.AbstractEventExecutor.logger.

quietPeriodTaskback to summary
private final RunnableScheduledFutureAdapter<Void> quietPeriodTask
SCHEDULE_QUIET_PERIOD_INTERVALback to summary
private static final long SCHEDULE_QUIET_PERIOD_INTERVAL
startedback to summary
private final AtomicBoolean started
taskQueueback to summary
private final BlockingQueue<Runnable> taskQueue
taskRunnerback to summary
private final GlobalEventExecutor.TaskRunner taskRunner
terminationFutureback to summary
private final Future<Void> terminationFuture
threadback to summary
pack-priv volatile Thread thread
threadFactoryback to summary
pack-priv final ThreadFactory threadFactory

Constructor Detail

GlobalEventExecutorback to summary
private GlobalEventExecutor()

Method Detail

addTaskback to summary
private void addTask(Runnable task)

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

awaitInactivityback to summary
public boolean awaitInactivity(long timeout, TimeUnit unit) throws InterruptedException

Waits until the worker thread of this executor has no tasks left in its task queue and terminates itself. Because a new worker thread will be started again when a new task is submitted, this operation is only useful when you want to ensure that the worker thread is terminated after your application is shut down and there's no chance of submitting a new task afterwards.

Returns:boolean

true if and only if the worker thread has been terminated

awaitTerminationback to summary
public boolean awaitTermination(long timeout, TimeUnit unit)

Overrides default io.netty5.util.concurrent.EventExecutorGroup.awaitTermination.

Doc from io.netty5.util.concurrent.EventExecutorGroup.awaitTermination.

Wait for this EventExecutorGroup to terminate, up to the given timeout.

Parameters
timeout:long

The non-negative maximum amount of time to wait for the executor group to terminate.

unit:TimeUnit

The non-null time unit of the timeout.

Returns:boolean

true if the executor group terminated within the specific timeout.

Annotations
@Override
executeback to summary
public void execute(Runnable task)

Implements io.netty5.util.concurrent.EventExecutor.execute.

Doc from java.util.concurrent.Executor.execute.

Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.

Parameters
task:Runnable

the runnable task

Annotations
@Override
fetchFromScheduledTaskQueueback to summary
private void fetchFromScheduledTaskQueue()
inEventLoopback to summary
public boolean inEventLoop(Thread thread)

Implements io.netty5.util.concurrent.EventExecutor.inEventLoop.

Doc from io.netty5.util.concurrent.EventExecutor.inEventLoop.

Return true if the given Thread is executed in the event loop, false otherwise.

Annotations
@Override
isShutdownback to summary
public boolean isShutdown()

Implements io.netty5.util.concurrent.EventExecutorGroup.isShutdown.

Doc from io.netty5.util.concurrent.EventExecutorGroup.isShutdown.

Returns true if all EventExecutors managed by this EventExecutorGroup have been shut down gracefully and moved past the grace period so that they are no longer accepting any new tasks.

An executor group that "is shut down" might still be executing tasks that it has queued up, but it will no longer be accepting any new tasks. Once all running and queued tasks have completed, the executor group will be terminated.

Returns:boolean

true if all executors in this group have shut down and are no longer accepting any new tasks.

Annotations
@Override
isShuttingDownback to summary
public boolean isShuttingDown()

Implements io.netty5.util.concurrent.EventExecutorGroup.isShuttingDown.

Doc from io.netty5.util.concurrent.EventExecutorGroup.isShuttingDown.

Returns true if and only if all EventExecutors managed by this EventExecutorGroup are being shut down gracefully or was shut down.

An executor group that "is shutting down" can still accept new tasks for a little while (the grace period), but will eventually start rejecting new tasks. At that point, the executor group will be shut down.

Returns:boolean

true if all executors in this group have at least started shutting down, otherwise false.

Annotations
@Override
isTerminatedback to summary
public boolean isTerminated()

Overrides default io.netty5.util.concurrent.EventExecutorGroup.isTerminated.

Doc from io.netty5.util.concurrent.EventExecutorGroup.isTerminated.

Returns true if all EventExecutors managed by this EventExecutorGroup are shut down, and all of their tasks have completed.

Returns:boolean

true if all executors in this group have terminated.

Annotations
@Override
pendingTasksback to summary
public int pendingTasks()

Return the number of tasks that are pending for processing.

shutdownGracefullyback to summary
public Future<Void> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)

Implements io.netty5.util.concurrent.EventExecutorGroup.shutdownGracefully.

Doc from io.netty5.util.concurrent.EventExecutorGroup.shutdownGracefully.

Signals this executor that the caller wants the executor to be shut down. Once this method is called, isShuttingDown() starts to return true, and the executor prepares to shut itself down. This method 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.

Parameters
quietPeriod:long

the quiet period as described in the documentation

timeout:long

the maximum amount of time to wait until the executor is shutting down regardless if a task was submitted during the quiet period.

unit:TimeUnit

the unit of quietPeriod and timeout

Returns:Future<Void>

the terminationFuture()

Annotations
@Override
startThreadback to summary
private void startThread()
takeTaskback to summary
private Runnable takeTask()

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

Returns:Runnable

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

terminationFutureback to summary
public Future<Void> terminationFuture()

Implements io.netty5.util.concurrent.EventExecutorGroup.terminationFuture.

Doc from io.netty5.util.concurrent.EventExecutorGroup.terminationFuture.

Returns the Future which is notified when all EventExecutors managed by this EventExecutorGroup have been terminated.

Returns:Future<Void>

The Future representing the termination of this EventExecutorGroup.

Annotations
@Override
io.netty5.util.concurrent back to summary

pack-priv final Class GlobalEventExecutor.TaskRunner

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

TaskRunnerback to summary
pack-priv TaskRunner()

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
runTaskback to summary
private void runTask(Runnable task)