- 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
EventExecutorGroupimplementation 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.protectedMultithreadEventExecutorGroup(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.protectedMultithreadEventExecutorGroup(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 booleanawaitTermination(long timeout, TimeUnit unit)Wait for thisEventExecutorGroupto terminate, up to the given timeout.intexecutorCount()Return the number ofEventExecutorthis implementation uses.protected List<EventExecutor>executors()TheEventExecutors that are used by thisMultithreadEventExecutorGroup.booleanisShutdown()Returnstrueif allEventExecutors managed by thisEventExecutorGrouphave been shut down gracefully and moved past the grace period so that they are no longer accepting any new tasks.booleanisShuttingDown()Returnstrueif and only if allEventExecutors managed by thisEventExecutorGroupare being shut down gracefully or was shut down.booleanisTerminated()Returnstrueif allEventExecutors managed by thisEventExecutorGroupare shut down, and all of their tasks have completed.Iterator<EventExecutor>iterator()protected EventExecutornewChild(Executor executor, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, Object... args)Create a new EventExecutor which will later then accessible via thenext()method.EventExecutornext()Returns the nextEventExecutorto 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 theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave 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, ornullif 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- theExecutorto use, ornullif 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- theThreadFactoryto use, ornullif the default should be used.maxPendingTasks- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler- theRejectedExecutionHandlerto 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, ornullif the default should be used.maxPendingTasks- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler- theRejectedExecutionHandlerto 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, ornullif the default should be used.maxPendingTasks- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler- theRejectedExecutionHandlerto 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, ornullif the default should be used.maxPendingTasks- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler- theRejectedExecutionHandlerto use.args- arguments which will passed to eachnewChild(Executor, int, RejectedExecutionHandler, Object...)call
-
-
Method Detail
-
executors
protected final List<EventExecutor> executors()
TheEventExecutors that are used by thisMultithreadEventExecutorGroup.
-
next
public EventExecutor next()
Returns the nextEventExecutorto use. The default implementation will use round-robin, but you may override this to change the selection algorithm.- Specified by:
nextin interfaceEventExecutorGroup
-
iterator
public Iterator<EventExecutor> iterator()
- Specified by:
iteratorin interfaceEventExecutorGroup- Specified by:
iteratorin interfaceIterable<EventExecutor>
-
executorCount
public final int executorCount()
Return the number ofEventExecutorthis 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:EventExecutorGroupSignals 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:
shutdownGracefullyin 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 ofquietPeriodandtimeout- Returns:
- the
EventExecutorGroup.terminationFuture()
-
terminationFuture
public final Future<Void> terminationFuture()
Description copied from interface:EventExecutorGroupReturns theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave been terminated.- Specified by:
terminationFuturein interfaceEventExecutorGroup- Returns:
- The
Futurerepresenting the termination of thisEventExecutorGroup.
-
isShuttingDown
public final boolean isShuttingDown()
Description copied from interface:EventExecutorGroupReturnstrueif and only if allEventExecutors managed by thisEventExecutorGroupare 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:
isShuttingDownin interfaceEventExecutorGroup- Returns:
trueif all executors in this group have at least started shutting down, otherwisefalse.
-
isShutdown
public final boolean isShutdown()
Description copied from interface:EventExecutorGroupReturnstrueif allEventExecutors managed by thisEventExecutorGrouphave 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:
isShutdownin interfaceEventExecutorGroup- Returns:
trueif 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:EventExecutorGroupReturnstrueif allEventExecutors managed by thisEventExecutorGroupare shut down, and all of their tasks have completed.- Specified by:
isTerminatedin interfaceEventExecutorGroup- Returns:
trueif all executors in this group have terminated.
-
awaitTermination
public final boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedExceptionDescription copied from interface:EventExecutorGroupWait for thisEventExecutorGroupto terminate, up to the given timeout.- Specified by:
awaitTerminationin 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:
trueif the executor group terminated within the specific timeout.- Throws:
InterruptedException- If this thread was interrupted while waiting for executor group to terminate.
-
-