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 for EventExecutorGroup implementations that handles their tasks with multiple threads at the same time.
  • Field Details

  • Constructor Details

    • 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, or null if the default should be used.
      args - arguments which will passed to each newChild(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, or null if the default should be used.
      args - arguments which will passed to each newChild(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, or null if the default should be used.
      chooserFactory - the EventExecutorChooserFactory to use.
      args - arguments which will passed to each newChild(Executor, Object...) call
  • Method Details

    • newDefaultThreadFactory

      protected java.util.concurrent.ThreadFactory newDefaultThreadFactory()
    • next

      public EventExecutor next()
      Description copied from interface: EventExecutorGroup
      Returns one of the EventExecutors managed by this EventExecutorGroup.
    • iterator

      public java.util.Iterator<EventExecutor> iterator()
    • executorCount

      public final int executorCount()
      Return the number of EventExecutor this 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 an EventExecutorChooserFactory.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 compatible EventExecutorChooserFactory, otherwise an empty list.
      Returns:
      A list of AutoScalingEventExecutorChooserFactory.AutoScalingUtilizationMetric objects.
    • 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 the next() method. This method will be called for each thread that will serve this MultithreadEventExecutorGroup.
      Throws:
      java.lang.Exception
    • shutdownGracefully

      public Future<?> shutdownGracefully(long quietPeriod, long timeout, java.util.concurrent.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 return true, and the executor prepares to shut itself down. Unlike EventExecutorGroup.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 documentation
      timeout - the maximum amount of time to wait until the executor is EventExecutorGroup.shutdown() regardless if a task was submitted during the quiet period
      unit - the unit of quietPeriod and timeout
      Returns:
      the EventExecutorGroup.terminationFuture()
    • terminationFuture

      public Future<?> terminationFuture()
      Description copied from interface: EventExecutorGroup
      Returns the Future which is notified when all EventExecutors managed by this EventExecutorGroup have been terminated.
    • shutdown

      @Deprecated public void shutdown()
      Deprecated.
      Specified by:
      shutdown in interface EventExecutorGroup
      Specified by:
      shutdown in interface java.util.concurrent.ExecutorService
      Specified by:
      shutdown in class AbstractEventExecutorGroup
    • isShuttingDown

      public boolean isShuttingDown()
      Description copied from interface: EventExecutorGroup
      Returns true if and only if all EventExecutors managed by this EventExecutorGroup are 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