- java.lang.Object
-
- io.netty5.util.concurrent.MultithreadEventExecutorGroup
-
- All Implemented Interfaces:
EventExecutorGroup
,Iterable<EventExecutor>
,Executor
- Direct Known Subclasses:
DefaultEventExecutorGroup
,MultithreadEventLoopGroup
public class MultithreadEventExecutorGroup extends Object implements EventExecutorGroup
EventExecutorGroup
implementation that handles their tasks with multiple threads at the same time.
-
-
Constructor Summary
Constructors Modifier Constructor Description MultithreadEventExecutorGroup(int nThreads, Executor executor)
Create a new instance.MultithreadEventExecutorGroup(int nThreads, Executor executor, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
Create a new instance.protected
MultithreadEventExecutorGroup(int nThreads, Executor executor, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, Object... args)
Create a new instance.MultithreadEventExecutorGroup(int nThreads, ThreadFactory threadFactory)
Create a new instance.MultithreadEventExecutorGroup(int nThreads, ThreadFactory threadFactory, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
Create a new instance.protected
MultithreadEventExecutorGroup(int nThreads, ThreadFactory threadFactory, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, Object... args)
Create a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, TimeUnit unit)
Wait for thisEventExecutorGroup
to terminate, up to the given timeout.int
executorCount()
Return the number ofEventExecutor
this implementation uses.protected List<EventExecutor>
executors()
TheEventExecutor
s that are used by thisMultithreadEventExecutorGroup
.boolean
isShutdown()
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
have been shut down gracefully and moved past the grace period so that they are no longer accepting any new tasks.boolean
isShuttingDown()
Returnstrue
if and only if allEventExecutor
s managed by thisEventExecutorGroup
are being shut down gracefully or was shut down.boolean
isTerminated()
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
are shut down, and all of their tasks have completed.Iterator<EventExecutor>
iterator()
protected EventExecutor
newChild(Executor executor, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, Object... args)
Create a new EventExecutor which will later then accessible via thenext()
method.EventExecutor
next()
Returns the nextEventExecutor
to use.Future<Void>
shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)
Signals this executor that the caller wants the executor to be shut down.Future<Void>
terminationFuture()
Returns theFuture
which is notified when allEventExecutor
s managed by thisEventExecutorGroup
have been terminated.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.util.concurrent.EventExecutorGroup
execute, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, shutdownGracefully, submit, submit, submit
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
MultithreadEventExecutorGroup
public MultithreadEventExecutorGroup(int nThreads, ThreadFactory threadFactory)
Create a new instance.- Parameters:
nThreads
- the number of threads that will be used by this instance.threadFactory
- the ThreadFactory to use, ornull
if the default should be used.
-
MultithreadEventExecutorGroup
public MultithreadEventExecutorGroup(int nThreads, Executor executor)
Create a new instance.- Parameters:
nThreads
- the number of threads that will be used by this instance.executor
- theExecutor
to use, ornull
if the default should be used.
-
MultithreadEventExecutorGroup
public MultithreadEventExecutorGroup(int nThreads, ThreadFactory threadFactory, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
Create a new instance.- Parameters:
nThreads
- the number of threads that will be used by this instance.threadFactory
- theThreadFactory
to use, ornull
if the default should be used.maxPendingTasks
- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler
- theRejectedExecutionHandler
to use.
-
MultithreadEventExecutorGroup
public MultithreadEventExecutorGroup(int nThreads, Executor executor, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
Create a new instance.- Parameters:
nThreads
- the number of threads that will be used by this instance.executor
- the Executor to use, ornull
if the default should be used.maxPendingTasks
- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler
- theRejectedExecutionHandler
to use.
-
MultithreadEventExecutorGroup
protected MultithreadEventExecutorGroup(int nThreads, ThreadFactory threadFactory, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, Object... args)
Create a new instance.- Parameters:
nThreads
- the number of threads that will be used by this instance.threadFactory
- the ThreadFactory to use, ornull
if the default should be used.maxPendingTasks
- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler
- theRejectedExecutionHandler
to use.args
- arguments which will passed to eachnewChild(Executor, int, RejectedExecutionHandler, Object...)
call
-
MultithreadEventExecutorGroup
protected MultithreadEventExecutorGroup(int nThreads, Executor executor, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, Object... args)
Create a new instance.- Parameters:
nThreads
- the number of threads that will be used by this instance.executor
- the Executor to use, ornull
if the default should be used.maxPendingTasks
- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler
- theRejectedExecutionHandler
to use.args
- arguments which will passed to eachnewChild(Executor, int, RejectedExecutionHandler, Object...)
call
-
-
Method Detail
-
executors
protected final List<EventExecutor> executors()
TheEventExecutor
s that are used by thisMultithreadEventExecutorGroup
.
-
next
public EventExecutor next()
Returns the nextEventExecutor
to use. The default implementation will use round-robin, but you may override this to change the selection algorithm.- Specified by:
next
in interfaceEventExecutorGroup
-
iterator
public Iterator<EventExecutor> iterator()
- Specified by:
iterator
in interfaceEventExecutorGroup
- Specified by:
iterator
in interfaceIterable<EventExecutor>
-
executorCount
public final int executorCount()
Return the number ofEventExecutor
this implementation uses. This number is the maps 1:1 to the threads it use.
-
newChild
protected EventExecutor newChild(Executor executor, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, Object... args)
Create a new EventExecutor which will later then accessible via thenext()
method. This method will be called for each thread that will serve thisMultithreadEventExecutorGroup
. As this method is called from within the constructor you can only use the parameters passed into the method when overriding this method.
-
shutdownGracefully
public final Future<Void> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)
Description copied from interface:EventExecutorGroup
Signals this executor that the caller wants the executor to be shut down. Once this method is called,EventExecutorGroup.isShuttingDown()
starts to returntrue
, 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.- Specified by:
shutdownGracefully
in interfaceEventExecutorGroup
- Parameters:
quietPeriod
- the quiet period as described in the documentationtimeout
- the maximum amount of time to wait until the executor is shutting down regardless if a task was submitted during the quiet period.unit
- the unit ofquietPeriod
andtimeout
- Returns:
- the
EventExecutorGroup.terminationFuture()
-
terminationFuture
public final Future<Void> terminationFuture()
Description copied from interface:EventExecutorGroup
Returns theFuture
which is notified when allEventExecutor
s managed by thisEventExecutorGroup
have been terminated.- Specified by:
terminationFuture
in interfaceEventExecutorGroup
- Returns:
- The
Future
representing the termination of thisEventExecutorGroup
.
-
isShuttingDown
public final boolean isShuttingDown()
Description copied from interface:EventExecutorGroup
Returnstrue
if and only if allEventExecutor
s managed by thisEventExecutorGroup
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.
- Specified by:
isShuttingDown
in interfaceEventExecutorGroup
- Returns:
true
if all executors in this group have at least started shutting down, otherwisefalse
.
-
isShutdown
public final boolean isShutdown()
Description copied from interface:EventExecutorGroup
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
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.
- Specified by:
isShutdown
in interfaceEventExecutorGroup
- Returns:
true
if all executors in this group have shut down and are no longer accepting any new tasks.
-
isTerminated
public final boolean isTerminated()
Description copied from interface:EventExecutorGroup
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
are shut down, and all of their tasks have completed.- Specified by:
isTerminated
in interfaceEventExecutorGroup
- Returns:
true
if all executors in this group have terminated.
-
awaitTermination
public final boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
Description copied from interface:EventExecutorGroup
Wait for thisEventExecutorGroup
to terminate, up to the given timeout.- Specified by:
awaitTermination
in interfaceEventExecutorGroup
- Parameters:
timeout
- The non-negative maximum amount of time to wait for the executor group to terminate.unit
- The non-null time unit of the timeout.- Returns:
true
if the executor group terminated within the specific timeout.- Throws:
InterruptedException
- If this thread was interrupted while waiting for executor group to terminate.
-
-