Class SingleThreadEventLoop
- All Implemented Interfaces:
EventLoop, EventLoopGroup, EventExecutor, EventExecutorGroup, OrderedEventExecutor, ThreadAwareExecutor, Iterable<EventExecutor>, Executor, ExecutorService, ScheduledExecutorService
- Direct Known Subclasses:
DefaultEventLoop, SingleThreadIoEventLoop, ThreadPerChannelEventLoop
Abstract base class for
EventLoops that execute all its submitted tasks in a single thread.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classNested classes/interfaces inherited from class SingleThreadEventExecutor
SingleThreadEventExecutor.NonWakeupRunnableModifier and TypeClassDescriptionprotected static interfaceDeprecated.Nested classes/interfaces inherited from class AbstractEventExecutor
AbstractEventExecutor.LazyRunnableModifier and TypeClassDescriptionstatic interfaceDeprecated.overrideSingleThreadEventExecutor.wakesUpForTask(Runnable)to re-create this behaviour -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSingleThreadEventLoop(EventLoopGroup parent, Executor executor, boolean addTaskWakesUp) protectedSingleThreadEventLoop(EventLoopGroup parent, Executor executor, boolean addTaskWakesUp, boolean supportSuspension) protectedSingleThreadEventLoop(EventLoopGroup parent, Executor executor, boolean addTaskWakesUp, boolean supportSuspension, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler) protectedSingleThreadEventLoop(EventLoopGroup parent, Executor executor, boolean addTaskWakesUp, boolean supportSuspension, Queue<Runnable> taskQueue, Queue<Runnable> tailTaskQueue, RejectedExecutionHandler rejectedExecutionHandler) protectedSingleThreadEventLoop(EventLoopGroup parent, Executor executor, boolean addTaskWakesUp, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler) protectedSingleThreadEventLoop(EventLoopGroup parent, Executor executor, boolean addTaskWakesUp, Queue<Runnable> taskQueue, Queue<Runnable> tailTaskQueue, RejectedExecutionHandler rejectedExecutionHandler) protectedSingleThreadEventLoop(EventLoopGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp) protectedSingleThreadEventLoop(EventLoopGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp, boolean supportSuspension) protectedSingleThreadEventLoop(EventLoopGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp, boolean supportSuspension, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler) protectedSingleThreadEventLoop(EventLoopGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidInvoked before returning fromSingleThreadEventExecutor.runAllTasks()andSingleThreadEventExecutor.runAllTasks(long).final voidAdds a task to be run once at the end of next (or current)eventloopiteration.protected booleanhasTasks()next()Returns one of theEventExecutors managed by thisEventExecutorGroup.parent()Return theEventExecutorGroupwhich is the parent of thisEventExecutor,intReturn the number of tasks that are pending for processing.register(ChannelPromise promise) register(Channel channel, ChannelPromise promise) Deprecated.intMethods inherited from class SingleThreadEventExecutor
addShutdownHook, addTask, awaitTermination, canSuspend, canSuspend, cleanup, confirmShutdown, deadlineNanos, delayNanos, execute, getAndIncrementBusyCycles, getAndIncrementIdleCycles, getAndResetAccumulatedActiveTimeNanos, getLastActivityTimeNanos, getNumOfRegisteredChannels, inEventLoop, interruptThread, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isShuttingDown, isSuspended, isSuspensionSupported, isTerminated, lazyExecute, newTaskQueue, newTaskQueue, peekTask, pollTask, pollTaskFrom, reject, reject, removeShutdownHook, removeTask, reportActiveIoTime, resetBusyCycles, resetIdleCycles, run, runAllTasks, runAllTasks, runAllTasksFrom, runScheduledAndExecutorTasks, shutdown, shutdownGracefully, takeTask, terminationFuture, threadProperties, trySuspend, updateLastExecutionTime, wakesUpForTask, wakeupModifier and TypeMethodDescriptionvoidaddShutdownHook(Runnable task) Add aRunnablewhich will be executed on shutdown of this instanceprotected voidAdd a task to the task queue, or throws aRejectedExecutionExceptionif this instance was shutdown before.booleanawaitTermination(long timeout, TimeUnit unit) protected booleanprotected booleancanSuspend(int state) protected voidcleanup()Do nothing, sub-classes may overrideprotected booleanConfirm that the shutdown if the instance should be done now!protected longReturns the absolute point in time (relative toAbstractScheduledEventExecutor.getCurrentTimeNanos()) at which the next closest scheduled task should run.protected longdelayNanos(long currentTimeNanos) Returns the amount of time left until the scheduled task with the closest dead line is executed.voidprotected intAtomically increments the counter for consecutive monitor cycles where utilization was above the scale-up threshold.protected intAtomically increments the counter for consecutive monitor cycles where utilization was below the scale-down threshold.protected longReturns the accumulated active time since the last call and resets the counter.protected longReturns the timestamp of the last known activity (tasks + I/O).protected intReturns the number of registered channels for auto-scaling related decisions.booleaninEventLoop(Thread thread) protected voidInterrupt the current runningThread.invokeAll(Collection<? extends Callable<T>> tasks) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) <T> TinvokeAny(Collection<? extends Callable<T>> tasks) <T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) booleanbooleanReturnstrueif and only if allEventExecutors managed by thisEventExecutorGroupare being shut down gracefully or was shut down.booleanReturnstrueif theEventExecutoris considered suspended.protected booleanReturnstrueif thisSingleThreadEventExecutorsupports suspension.booleanvoidlazyExecute(Runnable task) LikeExecutor.execute(Runnable)but does not guarantee the task will be run until either a non-lazy task is executed or the executor is shut down.Deprecated.Please use and overrideSingleThreadEventExecutor.newTaskQueue(int).newTaskQueue(int maxPendingTasks) Create a newQueuewhich will holds the tasks to execute.protected RunnablepeekTask()protected RunnablepollTask()protected static RunnablepollTaskFrom(Queue<Runnable> taskQueue) protected static voidreject()protected final voidOffers the task to the associatedRejectedExecutionHandler.voidremoveShutdownHook(Runnable task) Remove a previous addedRunnableas a shutdown hookprotected booleanremoveTask(Runnable task) protected voidreportActiveIoTime(long nanos) Adds the given duration to the total active time for the current measurement window.protected voidResets the counter for consecutive busy cycles to zero.protected voidResets the counter for consecutive idle cycles to zero.protected abstract voidrun()Runs the task-processing loop untilSingleThreadEventExecutor.confirmShutdown()returnstrue.protected booleanPoll all tasks from the task queue and run them viaRunnable.run()method.protected booleanrunAllTasks(long timeoutNanos) Poll all tasks from the task queue and run them viaRunnable.run()method.protected final booleanrunAllTasksFrom(Queue<Runnable> taskQueue) Runs all tasks from the passedtaskQueue.protected final booleanrunScheduledAndExecutorTasks(int maxDrainAttempts) Execute all expired scheduled tasks and all current tasks in the executor queue until both queues are empty, ormaxDrainAttemptshas been exceeded.voidshutdown()Deprecated.Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit) Signals this executor that the caller wants the executor to be shut down.protected RunnabletakeTask()Take the nextRunnablefrom the task queue and so will block if no task is currently present.Future<?> Returns theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave been terminated.final ThreadPropertiesbooleanTry to suspend thisEventExecutorand returntrueif suspension was successful.protected voidUpdates the internal timestamp that tells when a submitted task was executed most recently.protected booleanwakesUpForTask(Runnable task) Can be overridden to control which tasks require waking theEventExecutorthread if it is waiting so that they can be run immediately.protected voidwakeup(boolean inEventLoop) Methods inherited from class AbstractScheduledEventExecutor
afterScheduledTaskSubmitted, beforeScheduledTaskSubmitted, cancelScheduledTasks, deadlineToDelayNanos, delayNanos, fetchFromScheduledTaskQueue, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, ticker, validateScheduledModifier and TypeMethodDescriptionprotected booleanafterScheduledTaskSubmitted(long deadlineNanos) protected booleanbeforeScheduledTaskSubmitted(long deadlineNanos) Called from arbitrary non-EventExecutorthreads prior to scheduled task submission.protected voidCancel all scheduled tasks.protected static longdeadlineToDelayNanos(long deadlineNanos) Deprecated.UseAbstractScheduledEventExecutor.ticker()insteadprotected longdelayNanos(long currentTimeNanos, long scheduledPurgeInterval) Returns the amount of time left until the scheduled task with the closest dead line is executed.protected booleanfetchFromScheduledTaskQueue(Queue<Runnable> taskQueue) Fetch scheduled tasks from the internal queue and add these to the givenQueue.protected longDeprecated.Please use (or override)AbstractScheduledEventExecutor.ticker()instead.protected final booleanReturnstrueif a scheduled task is ready for processing.protected static longDeprecated.UseAbstractScheduledEventExecutor.ticker()insteadprotected static longnanoTime()Deprecated.Use the non-staticAbstractScheduledEventExecutor.ticker()instead.protected final longReturn the deadline (in nanoseconds) when the next scheduled task is ready to be run or-1if no task is scheduled.protected final longReturn the nanoseconds until the next scheduled task is ready to be run or-1if no task is scheduled.protected final Runnableprotected final RunnablepollScheduledTask(long nanoTime) Return theRunnablewhich is ready to be executed with the givennanoTime.<V> ScheduledFuture<V> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) ticker()The ticker for this executor.protected voidvalidateScheduled(long amount, TimeUnit unit) Deprecated.will be removed in the future.Methods inherited from class AbstractEventExecutor
iterator, newTaskFor, newTaskFor, runTask, safeExecute, shutdownGracefully, shutdownNow, submit, submit, submitModifier and TypeMethodDescriptioniterator()protected final <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) protected final <T> RunnableFuture<T> newTaskFor(Callable<T> callable) protected static voidprotected static voidsafeExecute(Runnable task) Future<?> Shortcut method forEventExecutorGroup.shutdownGracefully(long, long, TimeUnit)with sensible default values.Future<?> <T> Future<T> <T> Future<T> Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EventExecutor
inEventLoop, isExecutorThread, newFailedFuture, newProgressivePromise, newPromise, newSucceededFutureModifier and TypeMethodDescriptiondefault booleanCallsEventExecutor.inEventLoop(Thread)withThread.currentThread()as argumentdefault booleanisExecutorThread(Thread thread) default <V> Future<V> newFailedFuture(Throwable cause) Create a newFuturewhich is marked as failed already.default <V> ProgressivePromise<V> Create a newProgressivePromise.default <V> Promise<V> Return a newPromise.default <V> Future<V> newSucceededFuture(V result) Create a newFuturewhich is marked as succeeded already.Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_MAX_PENDING_TASKS
protected static final int DEFAULT_MAX_PENDING_TASKS
-
-
Constructor Details
-
SingleThreadEventLoop
protected SingleThreadEventLoop(EventLoopGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp) -
SingleThreadEventLoop
protected SingleThreadEventLoop(EventLoopGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp, boolean supportSuspension) -
SingleThreadEventLoop
-
SingleThreadEventLoop
protected SingleThreadEventLoop(EventLoopGroup parent, Executor executor, boolean addTaskWakesUp, boolean supportSuspension) -
SingleThreadEventLoop
protected SingleThreadEventLoop(EventLoopGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler) -
SingleThreadEventLoop
protected SingleThreadEventLoop(EventLoopGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp, boolean supportSuspension, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler) -
SingleThreadEventLoop
protected SingleThreadEventLoop(EventLoopGroup parent, Executor executor, boolean addTaskWakesUp, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler) -
SingleThreadEventLoop
protected SingleThreadEventLoop(EventLoopGroup parent, Executor executor, boolean addTaskWakesUp, boolean supportSuspension, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler) -
SingleThreadEventLoop
protected SingleThreadEventLoop(EventLoopGroup parent, Executor executor, boolean addTaskWakesUp, Queue<Runnable> taskQueue, Queue<Runnable> tailTaskQueue, RejectedExecutionHandler rejectedExecutionHandler) -
SingleThreadEventLoop
protected SingleThreadEventLoop(EventLoopGroup parent, Executor executor, boolean addTaskWakesUp, boolean supportSuspension, Queue<Runnable> taskQueue, Queue<Runnable> tailTaskQueue, RejectedExecutionHandler rejectedExecutionHandler)
-
-
Method Details
-
parent
Description copied from interface:EventExecutorReturn theEventExecutorGroupwhich is the parent of thisEventExecutor,- Specified by:
parentin interfaceEventExecutor- Specified by:
parentin interfaceEventLoop- Overrides:
parentin classAbstractEventExecutor
-
next
Description copied from interface:EventExecutorGroupReturns one of theEventExecutors managed by thisEventExecutorGroup.- Specified by:
nextin interfaceEventExecutorGroup- Specified by:
nextin interfaceEventLoopGroup- Overrides:
nextin classAbstractEventExecutor
-
register
Description copied from interface:EventLoopGroupRegister aChannelwith thisEventLoop. The returnedChannelFuturewill get notified once the registration was complete.- Specified by:
registerin interfaceEventLoopGroup
-
register
Description copied from interface:EventLoopGroupRegister aChannelwith thisEventLoopusing aChannelFuture. The passedChannelFuturewill get notified once the registration was complete and also will get returned.- Specified by:
registerin interfaceEventLoopGroup
-
register
Deprecated.Description copied from interface:EventLoopGroupRegister aChannelwith thisEventLoop. The passedChannelFuturewill get notified once the registration was complete and also will get returned.- Specified by:
registerin interfaceEventLoopGroup
-
executeAfterEventLoopIteration
Adds a task to be run once at the end of next (or current)eventloopiteration.- Parameters:
task- to be added.
-
afterRunningAllTasks
protected void afterRunningAllTasks()Description copied from class:SingleThreadEventExecutorInvoked before returning fromSingleThreadEventExecutor.runAllTasks()andSingleThreadEventExecutor.runAllTasks(long).- Overrides:
afterRunningAllTasksin classSingleThreadEventExecutor
-
hasTasks
protected boolean hasTasks()- Overrides:
hasTasksin classSingleThreadEventExecutor- See Also:
-
pendingTasks
public int pendingTasks()Description copied from class:SingleThreadEventExecutorReturn the number of tasks that are pending for processing.- Overrides:
pendingTasksin classSingleThreadEventExecutor
-
registeredChannels
-
registeredChannelsIterator
- Returns:
- read-only iterator of active
Channels registered with thisEventLoop. The returned value is not guaranteed to be exact accurate and should be viewed as a best effort. This method is expected to be called from within event loop. - Throws:
UnsupportedOperationException- if operation is not supported by implementation.
-
SingleThreadEventExecutor.wakesUpForTask(Runnable)to re-create this behaviour