Class SingleThreadIoEventLoop
- All Implemented Interfaces:
EventLoop, EventLoopGroup, IoEventLoop, IoEventLoopGroup, EventExecutor, EventExecutorGroup, OrderedEventExecutor, ThreadAwareExecutor, Iterable<EventExecutor>, Executor, ExecutorService, ScheduledExecutorService
- Direct Known Subclasses:
EpollEventLoop, NioEventLoop
IoEventLoop implementation that execute all its submitted tasks in a single thread using the provided
IoHandler.-
Nested Class Summary
Nested classes/interfaces inherited from class SingleThreadEventLoop
SingleThreadEventLoop.ChannelsReadOnlyIterator<T>Nested classes/interfaces inherited from class SingleThreadEventExecutor
SingleThreadEventExecutor.NonWakeupRunnableNested classes/interfaces inherited from class AbstractEventExecutor
AbstractEventExecutor.LazyRunnable -
Field Summary
Fields inherited from class SingleThreadEventLoop
DEFAULT_MAX_PENDING_TASKS -
Constructor Summary
ConstructorsModifierConstructorDescriptionSingleThreadIoEventLoop(IoEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory) Creates a new instanceSingleThreadIoEventLoop(IoEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs) Creates a new instanceprotectedSingleThreadIoEventLoop(IoEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory, Queue<Runnable> taskQueue, Queue<Runnable> tailTaskQueue, RejectedExecutionHandler rejectedExecutionHandler) Creates a new instanceSingleThreadIoEventLoop(IoEventLoopGroup parent, ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory) Creates a new instanceSingleThreadIoEventLoop(IoEventLoopGroup parent, ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs) Creates a new instance -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanSuspend(int state) protected final voidcleanup()Do nothing, sub-classes may overrideprotected intReturns the number of registered channels for auto-scaling related decisions.protected final IoHandlerbooleanisCompatible(Class<? extends IoHandle> handleType) Returnstrueif the given type is compatible with thisIoEventLoopGroupand so can be registered to the containedIoEventLoops,falseotherwise.booleannewTaskQueue(int maxPendingTasks) Create a newQueuewhich will holds the tasks to execute.newTaskQueue0(int maxPendingTasks) next()Returns one of theEventExecutors managed by thisEventExecutorGroup.final Future<IoRegistration> protected voidrun()Run the tasks in theSingleThreadEventExecutor.taskQueueprotected intrunIo()Called when IO will be processed for all theIoHandles on thisSingleThreadIoEventLoop.protected final voidwakeup(boolean inEventLoop) Methods inherited from class SingleThreadEventLoop
afterRunningAllTasks, executeAfterEventLoopIteration, hasTasks, parent, pendingTasks, register, register, register, registeredChannels, registeredChannelsIteratorMethods inherited from class SingleThreadEventExecutor
addShutdownHook, addTask, awaitTermination, canSuspend, confirmShutdown, deadlineNanos, delayNanos, execute, getAndIncrementBusyCycles, getAndIncrementIdleCycles, getAndResetAccumulatedActiveTimeNanos, getLastActivityTimeNanos, inEventLoop, interruptThread, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isShuttingDown, isSuspended, isSuspensionSupported, isTerminated, lazyExecute, newTaskQueue, peekTask, pollTask, pollTaskFrom, reject, reject, removeShutdownHook, removeTask, reportActiveIoTime, resetBusyCycles, resetIdleCycles, runAllTasks, runAllTasks, runAllTasksFrom, runScheduledAndExecutorTasks, shutdown, shutdownGracefully, takeTask, terminationFuture, threadProperties, trySuspend, updateLastExecutionTime, wakesUpForTaskMethods inherited from class AbstractScheduledEventExecutor
afterScheduledTaskSubmitted, beforeScheduledTaskSubmitted, cancelScheduledTasks, deadlineToDelayNanos, delayNanos, fetchFromScheduledTaskQueue, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, ticker, validateScheduledMethods inherited from class AbstractEventExecutor
iterator, newTaskFor, newTaskFor, runTask, safeExecute, shutdownGracefully, shutdownNow, submit, submit, submitMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EventExecutor
inEventLoop, inEventLoop, isExecutorThread, isSuspended, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, trySuspendMethods inherited from interface EventExecutorGroup
isShuttingDown, iterator, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, shutdown, shutdownGracefully, shutdownGracefully, shutdownNow, submit, submit, submit, terminationFuture, tickerMethods inherited from interface EventLoopGroup
registerMethods inherited from interface ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminatedMethods inherited from interface IoEventLoopGroup
register, registerMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
SingleThreadIoEventLoop
public SingleThreadIoEventLoop(IoEventLoopGroup parent, ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory) Creates a new instance- Parameters:
parent- the parent that holds thisIoEventLoop.threadFactory- theThreadFactorythat is used to create the underlyingThread.ioHandlerFactory- theIoHandlerFactorythat should be used to obtainIoHandlerto handle IO.
-
SingleThreadIoEventLoop
public SingleThreadIoEventLoop(IoEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory) Creates a new instance- Parameters:
parent- the parent that holds thisIoEventLoop.executor- theExecutorthat is used for dispatching the work.ioHandlerFactory- theIoHandlerFactorythat should be used to obtainIoHandlerto handle IO.
-
SingleThreadIoEventLoop
public SingleThreadIoEventLoop(IoEventLoopGroup parent, ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs) Creates a new instance- Parameters:
parent- the parent that holds thisIoEventLoop.threadFactory- theThreadFactorythat is used to create the underlyingThread.ioHandlerFactory- theIoHandlerFactorythat should be used to obtainIoHandlerto handle IO.maxPendingTasks- the maximum pending tasks that are allowed beforeRejectedExecutionHandler.rejected(Runnable, SingleThreadEventExecutor)is called to handle it.rejectedExecutionHandler- theRejectedExecutionHandlerthat handles when more tasks are added then allowed permaxPendingTasks.maxTaskProcessingQuantumMs- the maximum number of milliseconds that will be spent to run tasks before trying to run IO again.
-
SingleThreadIoEventLoop
public SingleThreadIoEventLoop(IoEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs) Creates a new instance- Parameters:
parent- the parent that holds thisIoEventLoop.ioHandlerFactory- theIoHandlerFactorythat should be used to obtainIoHandlerto handle IO.maxPendingTasks- the maximum pending tasks that are allowed beforeRejectedExecutionHandler.rejected(Runnable, SingleThreadEventExecutor)is called to handle it.rejectedExecutionHandler- theRejectedExecutionHandlerthat handles when more tasks are added then allowed permaxPendingTasks.maxTaskProcessingQuantumMs- the maximum number of milliseconds that will be spent to run tasks before trying to run IO again.
-
SingleThreadIoEventLoop
protected SingleThreadIoEventLoop(IoEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory, Queue<Runnable> taskQueue, Queue<Runnable> tailTaskQueue, RejectedExecutionHandler rejectedExecutionHandler) Creates a new instance- Parameters:
parent- the parent that holds thisIoEventLoop.executor- theExecutorthat is used for dispatching the work.ioHandlerFactory- theIoHandlerFactorythat should be used to obtainIoHandlerto handle IO.taskQueue- theQueueused for storing pending tasks.tailTaskQueue- theQueueused for storing tail pending tasks.rejectedExecutionHandler- theRejectedExecutionHandlerthat handles when more tasks are added then allowed.
-
-
Method Details
-
run
protected void run()Description copied from class:SingleThreadEventExecutorRun the tasks in theSingleThreadEventExecutor.taskQueue- Specified by:
runin classSingleThreadEventExecutor
-
ioHandler
-
canSuspend
protected boolean canSuspend(int state) Description copied from class:SingleThreadEventExecutorReturnstrueif thisSingleThreadEventExecutorcan be suspended at the moment,falseotherwise. Subclasses might override this method to add extra checks.- Overrides:
canSuspendin classSingleThreadEventExecutor- Parameters:
state- the current internal state of theSingleThreadEventExecutor.- Returns:
- if suspension is possible at the moment.
-
runIo
protected int runIo()Called when IO will be processed for all theIoHandles on thisSingleThreadIoEventLoop. This method returns the number ofIoHandles for which IO was processed. This method must be called from theEventLoopthread. -
next
Description copied from interface:EventExecutorGroupReturns one of theEventExecutors managed by thisEventExecutorGroup.- Specified by:
nextin interfaceEventExecutorGroup- Specified by:
nextin interfaceEventLoopGroup- Specified by:
nextin interfaceIoEventLoop- Specified by:
nextin interfaceIoEventLoopGroup- Overrides:
nextin classSingleThreadEventLoop
-
register
Description copied from interface:IoEventLoop- Specified by:
registerin interfaceIoEventLoop- Specified by:
registerin interfaceIoEventLoopGroup- Parameters:
handle- theIoHandleto register.- Returns:
- the
Futurethat is notified once the operations completes.
-
getNumOfRegisteredChannels
protected int getNumOfRegisteredChannels()Description copied from class:SingleThreadEventExecutorReturns the number of registered channels for auto-scaling related decisions. This is intended to be used byMultithreadEventExecutorGroupfor dynamic scaling.- Overrides:
getNumOfRegisteredChannelsin classSingleThreadEventExecutor- Returns:
- The number of registered channels, or
-1if not applicable.
-
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
Description copied from interface:IoEventLoopGroupReturnstrueif the given type is compatible with thisIoEventLoopGroupand so can be registered to the containedIoEventLoops,falseotherwise.- Specified by:
isCompatiblein interfaceIoEventLoop- Specified by:
isCompatiblein interfaceIoEventLoopGroup- Parameters:
handleType- the type of theIoHandle.- Returns:
- if compatible of not.
-
isIoType
Description copied from interface:IoEventLoopGroup- Specified by:
isIoTypein interfaceIoEventLoop- Specified by:
isIoTypein interfaceIoEventLoopGroup- Parameters:
handlerType- the type of theIoHandler.- Returns:
- if used or not.
-
newTaskQueue
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.- Overrides:
newTaskQueuein classSingleThreadEventExecutor
-
newTaskQueue0
-