Package io.netty.util.concurrent
Class MultithreadEventExecutorGroup
- java.lang.Object
-
- io.netty.util.concurrent.AbstractEventExecutorGroup
-
- io.netty.util.concurrent.MultithreadEventExecutorGroup
-
- All Implemented Interfaces:
EventExecutorGroup,java.lang.Iterable<EventExecutor>,java.util.concurrent.Executor,java.util.concurrent.ExecutorService,java.util.concurrent.ScheduledExecutorService
- Direct Known Subclasses:
DefaultEventExecutorGroup,MultithreadEventLoopGroup
public abstract class MultithreadEventExecutorGroup extends AbstractEventExecutorGroup
Abstract base class forEventExecutorGroupimplementations that handles their tasks with multiple threads at the same time.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMultithreadEventExecutorGroup(int nThreads, java.util.concurrent.Executor executor, EventExecutorChooserFactory chooserFactory, java.lang.Object... args)Create a new instance.protectedMultithreadEventExecutorGroup(int nThreads, java.util.concurrent.Executor executor, java.lang.Object... args)Create a new instance.protectedMultithreadEventExecutorGroup(int nThreads, java.util.concurrent.ThreadFactory threadFactory, java.lang.Object... args)Create a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intactiveExecutorCount()Returns the number of currently active threads if the group is using anEventExecutorChooserFactory.ObservableEventExecutorChooser.booleanawaitTermination(long timeout, java.util.concurrent.TimeUnit unit)intexecutorCount()Return the number ofEventExecutorthis implementation uses.java.util.List<AutoScalingEventExecutorChooserFactory.AutoScalingUtilizationMetric>executorUtilizations()Returns a list of real-time utilization metrics if the group was configured with a compatibleEventExecutorChooserFactory, otherwise an empty list.booleanisShutdown()booleanisShuttingDown()Returnstrueif and only if allEventExecutors managed by thisEventExecutorGroupare being shut down gracefully or was shut down.booleanisTerminated()java.util.Iterator<EventExecutor>iterator()protected abstract EventExecutornewChild(java.util.concurrent.Executor executor, java.lang.Object... args)Create a new EventExecutor which will later then accessible via thenext()method.protected java.util.concurrent.ThreadFactorynewDefaultThreadFactory()EventExecutornext()Returns one of theEventExecutors managed by thisEventExecutorGroup.voidshutdown()Deprecated.Future<?>shutdownGracefully(long quietPeriod, long timeout, java.util.concurrent.TimeUnit unit)Signals this executor that the caller wants the executor to be shut down.Future<?>terminationFuture()Returns theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave been terminated.-
Methods inherited from class io.netty.util.concurrent.AbstractEventExecutorGroup
execute, invokeAll, invokeAll, invokeAny, invokeAny, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, shutdownGracefully, shutdownNow, submit, submit, submit
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.util.concurrent.EventExecutorGroup
ticker
-
-
-
-
Constructor Detail
-
MultithreadEventExecutorGroup
protected MultithreadEventExecutorGroup(int nThreads, java.util.concurrent.ThreadFactory threadFactory, java.lang.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.args- arguments which will passed to eachnewChild(Executor, Object...)call
-
MultithreadEventExecutorGroup
protected MultithreadEventExecutorGroup(int nThreads, java.util.concurrent.Executor executor, java.lang.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.args- arguments which will passed to eachnewChild(Executor, Object...)call
-
MultithreadEventExecutorGroup
protected MultithreadEventExecutorGroup(int nThreads, java.util.concurrent.Executor executor, EventExecutorChooserFactory chooserFactory, java.lang.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.chooserFactory- theEventExecutorChooserFactoryto use.args- arguments which will passed to eachnewChild(Executor, Object...)call
-
-
Method Detail
-
newDefaultThreadFactory
protected java.util.concurrent.ThreadFactory newDefaultThreadFactory()
-
next
public EventExecutor next()
Description copied from interface:EventExecutorGroupReturns one of theEventExecutors managed by thisEventExecutorGroup.
-
iterator
public java.util.Iterator<EventExecutor> iterator()
-
executorCount
public final int executorCount()
Return the number ofEventExecutorthis implementation uses. This number is the maps 1:1 to the threads it use.
-
activeExecutorCount
public int activeExecutorCount()
Returns the number of currently active threads if the group is using anEventExecutorChooserFactory.ObservableEventExecutorChooser. Otherwise, for a non-scaling group, this method returns the total number of threads, as all are considered active.- Returns:
- the count of active threads.
-
executorUtilizations
public java.util.List<AutoScalingEventExecutorChooserFactory.AutoScalingUtilizationMetric> executorUtilizations()
Returns a list of real-time utilization metrics if the group was configured with a compatibleEventExecutorChooserFactory, otherwise an empty list.- Returns:
- A list of
AutoScalingEventExecutorChooserFactory.AutoScalingUtilizationMetricobjects.
-
newChild
protected abstract EventExecutor newChild(java.util.concurrent.Executor executor, java.lang.Object... args) throws java.lang.Exception
Create a new EventExecutor which will later then accessible via thenext()method. This method will be called for each thread that will serve thisMultithreadEventExecutorGroup.- Throws:
java.lang.Exception
-
shutdownGracefully
public Future<?> shutdownGracefully(long quietPeriod, long timeout, java.util.concurrent.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. UnlikeEventExecutorGroup.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.- Parameters:
quietPeriod- the quiet period as described in the documentationtimeout- the maximum amount of time to wait until the executor is EventExecutorGroup.shutdown() regardless if a task was submitted during the quiet periodunit- the unit ofquietPeriodandtimeout- Returns:
- the
EventExecutorGroup.terminationFuture()
-
terminationFuture
public Future<?> terminationFuture()
Description copied from interface:EventExecutorGroupReturns theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave been terminated.
-
shutdown
@Deprecated public void shutdown()
Deprecated.- Specified by:
shutdownin interfaceEventExecutorGroup- Specified by:
shutdownin interfacejava.util.concurrent.ExecutorService- Specified by:
shutdownin classAbstractEventExecutorGroup
-
isShuttingDown
public boolean isShuttingDown()
Description copied from interface:EventExecutorGroupReturnstrueif and only if allEventExecutors managed by thisEventExecutorGroupare being shut down gracefully or was shut down.
-
isShutdown
public boolean isShutdown()
-
isTerminated
public boolean isTerminated()
-
awaitTermination
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
-