- java.lang.Object
-
- io.netty5.util.concurrent.AbstractEventExecutor
-
- io.netty5.util.concurrent.AbstractScheduledEventExecutor
-
- io.netty5.util.concurrent.SingleThreadEventExecutor
-
- io.netty5.channel.SingleThreadEventLoop
-
- All Implemented Interfaces:
EventLoop,EventLoopGroup,EventExecutor,EventExecutorGroup,FuturePromiseFactory,OrderedEventExecutor,Iterable<EventExecutor>,Executor
public class SingleThreadEventLoop extends SingleThreadEventExecutor implements EventLoop
-
-
Field Summary
Fields Modifier and Type Field Description protected static intDEFAULT_MAX_PENDING_TASKSprotected static intDEFAULT_MAX_TASKS_PER_RUN-
Fields inherited from class io.netty5.util.concurrent.SingleThreadEventExecutor
DEFAULT_MAX_PENDING_EXECUTOR_TASKS
-
-
Constructor Summary
Constructors Constructor Description SingleThreadEventLoop(Executor executor, IoHandler ioHandler)Create a new instanceSingleThreadEventLoop(Executor executor, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)Create a new instanceSingleThreadEventLoop(Executor executor, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, int maxTasksPerRun)Create a new instanceSingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler)Create a new instanceSingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)Create a new instanceSingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, int maxTasksPerRun)Create a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcleanup()Do nothing, sub-classes may override.Future<Void>deregisterForIo(IoHandle handle)booleanisCompatible(Class<? extends IoHandle> handleType)Returnstrueif the given type is compatible with thisEventLoopGroupand so can be registered to the containedEventLoops,falseotherwise.protected Queue<Runnable>newTaskQueue(int maxPendingTasks)Create a newQueuewhich will holds the tasks to execute.Future<Void>registerForIo(IoHandle handle)protected voidrun()Run tasks that are submitted to thisSingleThreadEventExecutor.protected intrunIO()Called when IO will be processed for all theChannels on thisSingleThreadEventLoop.protected booleanwakesUpForTask(Runnable task)ReturnstrueifSingleThreadEventExecutor.wakeup(boolean)should be called for thisRunnable,falseotherwise.protected voidwakeup(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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
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
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
SingleThreadEventLoop
public SingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler)
Create a new instance- Parameters:
threadFactory- theThreadFactorywhich will be used for the usedThreadioHandler- theIoHandlerto use.
-
SingleThreadEventLoop
public SingleThreadEventLoop(Executor executor, IoHandler ioHandler)
Create a new instance
-
SingleThreadEventLoop
public SingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
Create a new instance- Parameters:
threadFactory- theThreadFactorywhich will be used for the usedThreadioHandler- theIoHandlerto use.maxPendingTasks- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler- theRejectedExecutionHandlerto use.
-
SingleThreadEventLoop
public SingleThreadEventLoop(Executor executor, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
Create a new instance- Parameters:
executor- theExecutorwhich will be used to run thisEventLoop.ioHandler- theIoHandlerto use.maxPendingTasks- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler- theRejectedExecutionHandlerto use.
-
SingleThreadEventLoop
public SingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, int maxTasksPerRun)
Create a new instance- Parameters:
threadFactory- theThreadFactorywhich will be used for the usedThreadioHandler- theIoHandlerto use.maxPendingTasks- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler- theRejectedExecutionHandlerto use.maxTasksPerRun- the maximum number of tasks perEventLooprun that will be processed before trying to handle IO again.
-
SingleThreadEventLoop
public SingleThreadEventLoop(Executor executor, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, int maxTasksPerRun)
Create a new instance- Parameters:
executor- theExecutorwhich will be used to run thisEventLoop.ioHandler- theIoHandlerto use.maxPendingTasks- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler- theRejectedExecutionHandlerto use.maxTasksPerRun- the maximum number of tasks perEventLooprun that will be processed before trying to handle IO again.
-
-
Method Detail
-
newTaskQueue
protected Queue<Runnable> newTaskQueue(int maxPendingTasks)
Description copied from class:SingleThreadEventExecutorCreate a newQueuewhich will holds the tasks to execute. This default implementation will return aLinkedBlockingQueuebut if your sub-class ofSingleThreadEventExecutorwill not do any blocking calls on the thisQueueit may make sense to@Overridethis and return some more performant implementation that does not support blocking operations at all. Be aware that the implementation ofSingleThreadEventExecutor.run()depends on aBlockingQueueso you will need to overrideSingleThreadEventExecutor.run()as well if you return a nonBlockingQueuefrom this method. As this method is called from within the constructor you can only use the parameters passed into the method when overriding this method.- Overrides:
newTaskQueuein classSingleThreadEventExecutor
-
wakesUpForTask
protected final boolean wakesUpForTask(Runnable task)
Description copied from class:SingleThreadEventExecutorReturnstrueifSingleThreadEventExecutor.wakeup(boolean)should be called for thisRunnable,falseotherwise.- Overrides:
wakesUpForTaskin classSingleThreadEventExecutor
-
run
protected void run()
Description copied from class:SingleThreadEventExecutorRun tasks that are submitted to thisSingleThreadEventExecutor. The implementation depends on the fact thatSingleThreadEventExecutor.newTaskQueue(int)returns aBlockingQueue. If you change this by overridingSingleThreadEventExecutor.newTaskQueue(int)be aware that you also need to overrideSingleThreadEventExecutor.run(). This method must be called from theEventExecutorthread.- Overrides:
runin classSingleThreadEventExecutor
-
runIO
protected int runIO()
Called when IO will be processed for all theChannels on thisSingleThreadEventLoop. This method returns the number ofChannels for which IO was processed. This method must be called from theEventLoopthread.
-
registerForIo
public final Future<Void> registerForIo(IoHandle handle)
Description copied from interface:EventLoop- Specified by:
registerForIoin interfaceEventLoop- Parameters:
handle- theIoHandleto register.- Returns:
- the
Futurethat is notified once the operations completes.
-
deregisterForIo
public final Future<Void> deregisterForIo(IoHandle handle)
Description copied from interface:EventLoop- Specified by:
deregisterForIoin interfaceEventLoop- Returns:
- the
Futurethat is notified once the operations completes.
-
wakeup
protected final void wakeup(boolean inEventLoop)
- Overrides:
wakeupin classSingleThreadEventExecutor
-
cleanup
protected final void cleanup()
Description copied from class:SingleThreadEventExecutorDo nothing, sub-classes may override.- Overrides:
cleanupin classSingleThreadEventExecutor
-
isCompatible
public boolean isCompatible(Class<? extends IoHandle> handleType)
Description copied from interface:EventLoopGroupReturnstrueif the given type is compatible with thisEventLoopGroupand so can be registered to the containedEventLoops,falseotherwise.- Specified by:
isCompatiblein interfaceEventLoop- Specified by:
isCompatiblein interfaceEventLoopGroup- Parameters:
handleType- the type of theIoHandle.- Returns:
- if compatible of not.
-
-