Class SingleThreadEventLoop

  • All Implemented Interfaces:
    EventLoop, EventLoopGroup, io.netty5.util.concurrent.EventExecutor, io.netty5.util.concurrent.EventExecutorGroup, io.netty5.util.concurrent.FuturePromiseFactory, io.netty5.util.concurrent.OrderedEventExecutor, Iterable<io.netty5.util.concurrent.EventExecutor>, Executor

    public class SingleThreadEventLoop
    extends io.netty5.util.concurrent.SingleThreadEventExecutor
    implements EventLoop
    EventLoop that execute all its submitted tasks in a single thread and uses an IoHandler for IO processing.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static int DEFAULT_MAX_PENDING_TASKS  
      protected static int DEFAULT_MAX_TASKS_PER_RUN  
      • Fields inherited from class io.netty5.util.concurrent.SingleThreadEventExecutor

        DEFAULT_MAX_PENDING_EXECUTOR_TASKS
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void cleanup()  
      io.netty5.util.concurrent.Future<Void> deregisterForIo​(IoHandle handle)
      Deregister the Channel from the EventLoop for I/O processing.
      boolean isCompatible​(Class<? extends IoHandle> handleType)
      Returns true if the given type is compatible with this EventLoopGroup and so can be registered to the contained EventLoops, false otherwise.
      protected Queue<Runnable> newTaskQueue​(int maxPendingTasks)  
      io.netty5.util.concurrent.Future<Void> registerForIo​(IoHandle handle)
      Register the IoHandle to the EventLoop for I/O processing.
      protected void run()  
      protected int runIO()
      Called when IO will be processed for all the Channels on this SingleThreadEventLoop.
      protected boolean wakesUpForTask​(Runnable task)  
      protected void wakeup​(boolean inEventLoop)  
      • Methods inherited from class io.netty5.util.concurrent.SingleThreadEventExecutor

        addShutdownHook, awaitTermination, confirmShutdown, deadlineNanos, delayNanos, execute, hasTasks, inEventLoop, interruptThread, isShutdown, isShuttingDown, isTerminated, offerTask, pendingTasks, pollTask, reject, removeShutdownHook, removeTask, runAllTasks, shutdownGracefully, takeTask, terminationFuture, threadProperties, updateLastExecutionTime
      • Methods inherited from class io.netty5.util.concurrent.AbstractScheduledEventExecutor

        cancelScheduledTasks, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, newRunnableScheduledFuture, newScheduledTaskFor, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay
      • Methods inherited from class io.netty5.util.concurrent.AbstractEventExecutor

        newSucceededFuture, newTaskFor, newTaskFor, submit, submit, submit
      • Methods inherited from interface io.netty5.util.concurrent.EventExecutor

        execute, inEventLoop, inEventLoop, iterator, newFailedFuture, newPromise, newSucceededFuture, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submit, submit, submit
      • Methods inherited from interface io.netty5.util.concurrent.EventExecutorGroup

        awaitTermination, isShutdown, isShuttingDown, isTerminated, shutdownGracefully, shutdownGracefully, terminationFuture
      • Methods inherited from interface io.netty5.util.concurrent.FuturePromiseFactory

        newSucceededFuture
    • Field Detail

      • DEFAULT_MAX_PENDING_TASKS

        protected static final int DEFAULT_MAX_PENDING_TASKS
      • DEFAULT_MAX_TASKS_PER_RUN

        protected static final int DEFAULT_MAX_TASKS_PER_RUN
    • Constructor Detail

      • SingleThreadEventLoop

        public SingleThreadEventLoop​(Executor executor,
                                     IoHandler ioHandler)
        Create a new instance
        Parameters:
        executor - the Executor which will be used to run this EventLoop.
        ioHandler - the IoHandler to use.
      • SingleThreadEventLoop

        public SingleThreadEventLoop​(ThreadFactory threadFactory,
                                     IoHandler ioHandler,
                                     int maxPendingTasks,
                                     io.netty5.util.concurrent.RejectedExecutionHandler rejectedHandler)
        Create a new instance
        Parameters:
        threadFactory - the ThreadFactory which will be used for the used Thread
        ioHandler - the IoHandler to use.
        maxPendingTasks - the maximum number of pending tasks before new tasks will be rejected.
        rejectedHandler - the RejectedExecutionHandler to use.
      • SingleThreadEventLoop

        public SingleThreadEventLoop​(Executor executor,
                                     IoHandler ioHandler,
                                     int maxPendingTasks,
                                     io.netty5.util.concurrent.RejectedExecutionHandler rejectedHandler)
        Create a new instance
        Parameters:
        executor - the Executor which will be used to run this EventLoop.
        ioHandler - the IoHandler to use.
        maxPendingTasks - the maximum number of pending tasks before new tasks will be rejected.
        rejectedHandler - the RejectedExecutionHandler to use.
      • SingleThreadEventLoop

        public SingleThreadEventLoop​(ThreadFactory threadFactory,
                                     IoHandler ioHandler,
                                     int maxPendingTasks,
                                     io.netty5.util.concurrent.RejectedExecutionHandler rejectedHandler,
                                     int maxTasksPerRun)
        Create a new instance
        Parameters:
        threadFactory - the ThreadFactory which will be used for the used Thread
        ioHandler - the IoHandler to use.
        maxPendingTasks - the maximum number of pending tasks before new tasks will be rejected.
        rejectedHandler - the RejectedExecutionHandler to use.
        maxTasksPerRun - the maximum number of tasks per EventLoop run that will be processed before trying to handle IO again.
      • SingleThreadEventLoop

        public SingleThreadEventLoop​(Executor executor,
                                     IoHandler ioHandler,
                                     int maxPendingTasks,
                                     io.netty5.util.concurrent.RejectedExecutionHandler rejectedHandler,
                                     int maxTasksPerRun)
        Create a new instance
        Parameters:
        executor - the Executor which will be used to run this EventLoop.
        ioHandler - the IoHandler to use.
        maxPendingTasks - the maximum number of pending tasks before new tasks will be rejected.
        rejectedHandler - the RejectedExecutionHandler to use.
        maxTasksPerRun - the maximum number of tasks per EventLoop run that will be processed before trying to handle IO again.
    • Method Detail

      • newTaskQueue

        protected Queue<Runnable> newTaskQueue​(int maxPendingTasks)
        Overrides:
        newTaskQueue in class io.netty5.util.concurrent.SingleThreadEventExecutor
      • wakesUpForTask

        protected final boolean wakesUpForTask​(Runnable task)
        Overrides:
        wakesUpForTask in class io.netty5.util.concurrent.SingleThreadEventExecutor
      • run

        protected void run()
        Overrides:
        run in class io.netty5.util.concurrent.SingleThreadEventExecutor
      • runIO

        protected int runIO()
        Called when IO will be processed for all the Channels on this SingleThreadEventLoop. This method returns the number of Channels for which IO was processed. This method must be called from the EventLoop thread.
      • registerForIo

        public final io.netty5.util.concurrent.Future<Void> registerForIo​(IoHandle handle)
        Description copied from interface: EventLoop
        Register the IoHandle to the EventLoop for I/O processing.
        Specified by:
        registerForIo in interface EventLoop
        Parameters:
        handle - the IoHandle to register.
        Returns:
        the Future that is notified once the operations completes.
      • deregisterForIo

        public final io.netty5.util.concurrent.Future<Void> deregisterForIo​(IoHandle handle)
        Description copied from interface: EventLoop
        Deregister the Channel from the EventLoop for I/O processing.
        Specified by:
        deregisterForIo in interface EventLoop
        Returns:
        the Future that is notified once the operations completes.
      • wakeup

        protected final void wakeup​(boolean inEventLoop)
        Overrides:
        wakeup in class io.netty5.util.concurrent.SingleThreadEventExecutor
      • cleanup

        protected final void cleanup()
        Overrides:
        cleanup in class io.netty5.util.concurrent.SingleThreadEventExecutor