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

public Class MultithreadEventExecutorGroup

extends Object
implements EventExecutorGroup
Class Inheritance
All Implemented Interfaces
io.netty5.util.concurrent.EventExecutorGroup, java.util.concurrent.Executor, java.lang.Iterable
Known Direct Subclasses
io.netty5.util.concurrent.DefaultEventExecutorGroup
Imports
io.netty5.util.internal.EmptyArrays, java.util.Arrays, .Collections, .Iterator, .List, java.util.concurrent.Executor, .ThreadFactory, .TimeUnit, java.util.concurrent.atomic.AtomicInteger, .AtomicLong

EventExecutorGroup implementation that handles their tasks with multiple threads at the same time.

Field Summary

Modifier and TypeField and Description
private final EventExecutor[]
private final AtomicLong
private final boolean
private final List<EventExecutor>
private final AtomicInteger
private final Promise<Void>

Constructor Summary

AccessConstructor and Description
public
MultithreadEventExecutorGroup(int
the number of threads that will be used by this instance.
nThreads
,
ThreadFactory
the ThreadFactory to use, or null if the default should be used.
threadFactory
)

Create a new instance.

public
MultithreadEventExecutorGroup(int
the number of threads that will be used by this instance.
nThreads
,
Executor
the Executor to use, or null if the default should be used.
executor
)

Create a new instance.

public
MultithreadEventExecutorGroup(int
the number of threads that will be used by this instance.
nThreads
,
ThreadFactory
the ThreadFactory to use, or null if the default should be used.
threadFactory
,
int
the maximum number of pending tasks before new tasks will be rejected.
maxPendingTasks
,
RejectedExecutionHandler rejectedHandler)

Create a new instance.

public
MultithreadEventExecutorGroup(int
the number of threads that will be used by this instance.
nThreads
,
Executor
the Executor to use, or null if the default should be used.
executor
,
int
the maximum number of pending tasks before new tasks will be rejected.
maxPendingTasks
,
RejectedExecutionHandler rejectedHandler)

Create a new instance.

protected
MultithreadEventExecutorGroup(int
the number of threads that will be used by this instance.
nThreads
,
ThreadFactory
the ThreadFactory to use, or null if the default should be used.
threadFactory
,
int
the maximum number of pending tasks before new tasks will be rejected.
maxPendingTasks
,
RejectedExecutionHandler rejectedHandler, Object...
arguments which will passed to each newChild(Executor, int, RejectedExecutionHandler, Object...) call
args
)

Create a new instance.

protected
MultithreadEventExecutorGroup(int
the number of threads that will be used by this instance.
nThreads
,
Executor
the Executor to use, or null if the default should be used.
executor
,
int
the maximum number of pending tasks before new tasks will be rejected.
maxPendingTasks
,
RejectedExecutionHandler rejectedHandler, Object...
arguments which will passed to each newChild(Executor, int, RejectedExecutionHandler, Object...) call
args
)

Create a new instance.

Method Summary

Modifier and TypeMethod and Description
public final 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 final int
executorCount()

Return the number of EventExecutor this implementation uses.

protected final List<EventExecutor>
private static boolean
isPowerOfTwo(int val)

public final 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 final boolean
public final 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 Iterator<EventExecutor>
iterator()

Implements io.netty5.util.concurrent.EventExecutorGroup.iterator.

Returns an iterator over elements of type T.
protected EventExecutor
newChild(Executor executor, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, Object... args)

Create a new EventExecutor which will later then accessible via the next() method.

public EventExecutor
public final 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.
public final 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 java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

childrenback to summary
private final EventExecutor[] children
idxback to summary
private final AtomicLong idx
powerOfTwoback to summary
private final boolean powerOfTwo
readonlyChildrenback to summary
private final List<EventExecutor> readonlyChildren
terminatedChildrenback to summary
private final AtomicInteger terminatedChildren
terminationFutureback to summary
private final Promise<Void> terminationFuture

Constructor Detail

MultithreadEventExecutorGroupback to summary
public MultithreadEventExecutorGroup(int nThreads, ThreadFactory threadFactory)

Create a new instance.

Parameters
nThreads:int

the number of threads that will be used by this instance.

threadFactory:ThreadFactory

the ThreadFactory to use, or null if the default should be used.

MultithreadEventExecutorGroupback to summary
public MultithreadEventExecutorGroup(int nThreads, Executor executor)

Create a new instance.

Parameters
nThreads:int

the number of threads that will be used by this instance.

executor:Executor

the Executor to use, or null if the default should be used.

MultithreadEventExecutorGroupback to summary
public MultithreadEventExecutorGroup(int nThreads, ThreadFactory threadFactory, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)

Create a new instance.

Parameters
nThreads:int

the number of threads that will be used by this instance.

threadFactory:ThreadFactory

the ThreadFactory to use, or null if the default should be used.

maxPendingTasks:int

the maximum number of pending tasks before new tasks will be rejected.

rejectedHandler:RejectedExecutionHandler

the RejectedExecutionHandler to use.

MultithreadEventExecutorGroupback to summary
public MultithreadEventExecutorGroup(int nThreads, Executor executor, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)

Create a new instance.

Parameters
nThreads:int

the number of threads that will be used by this instance.

executor:Executor

the Executor to use, or null if the default should be used.

maxPendingTasks:int

the maximum number of pending tasks before new tasks will be rejected.

rejectedHandler:RejectedExecutionHandler

the RejectedExecutionHandler to use.

MultithreadEventExecutorGroupback to summary
protected MultithreadEventExecutorGroup(int nThreads, ThreadFactory threadFactory, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, Object... args)

Create a new instance.

Parameters
nThreads:int

the number of threads that will be used by this instance.

threadFactory:ThreadFactory

the ThreadFactory to use, or null if the default should be used.

maxPendingTasks:int

the maximum number of pending tasks before new tasks will be rejected.

rejectedHandler:RejectedExecutionHandler

the RejectedExecutionHandler to use.

args:Object[]

arguments which will passed to each newChild(Executor, int, RejectedExecutionHandler, Object...) call

MultithreadEventExecutorGroupback to summary
protected MultithreadEventExecutorGroup(int nThreads, Executor executor, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, Object... args)

Create a new instance.

Parameters
nThreads:int

the number of threads that will be used by this instance.

executor:Executor

the Executor to use, or null if the default should be used.

maxPendingTasks:int

the maximum number of pending tasks before new tasks will be rejected.

rejectedHandler:RejectedExecutionHandler

the RejectedExecutionHandler to use.

args:Object[]

arguments which will passed to each newChild(Executor, int, RejectedExecutionHandler, Object...) call

Method Detail

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

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
Exceptions
InterruptedException:
If this thread was interrupted while waiting for executor group to terminate.
executorCountback to summary
public final int executorCount()

Return the number of EventExecutor this implementation uses. This number is the maps 1:1 to the threads it use.

executorsback to summary
protected final List<EventExecutor> executors()

The EventExecutors that are used by this MultithreadEventExecutorGroup.

isPowerOfTwoback to summary
private static boolean isPowerOfTwo(int val)
isShutdownback to summary
public final 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 final 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 final 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
iteratorback to summary
public Iterator<EventExecutor> iterator()

Implements io.netty5.util.concurrent.EventExecutorGroup.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<EventExecutor>

an Iterator.

Annotations
@Override
newChildback to summary
protected EventExecutor newChild(Executor executor, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, Object... args)

Create a new EventExecutor which will later then accessible via the next() method. This method will be called for each thread that will serve this MultithreadEventExecutorGroup. As this method is called from within the constructor you can only use the parameters passed into the method when overriding this method.

nextback to summary
public EventExecutor next()

Implements io.netty5.util.concurrent.EventExecutorGroup.next.

Returns the next EventExecutor to use. The default implementation will use round-robin, but you may override this to change the selection algorithm.

Annotations
@Override
shutdownGracefullyback to summary
public final 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
terminationFutureback to summary
public final 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