Class EpollEventLoop
- All Implemented Interfaces:
EventLoop, EventLoopGroup, EventExecutor, EventExecutorGroup, OrderedEventExecutor, Iterable<EventExecutor>, Executor, ExecutorService, ScheduledExecutorService
EventLoop which uses epoll under the covers. Only works on Linux!-
Nested Class Summary
Nested classes/interfaces inherited from class SingleThreadEventLoop
SingleThreadEventLoop.ChannelsReadOnlyIterator<T>Modifier 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 inherited from class SingleThreadEventLoop
DEFAULT_MAX_PENDING_TASKS -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanafterScheduledTaskSubmitted(long deadlineNanos) protected booleanbeforeScheduledTaskSubmitted(long deadlineNanos) Called from arbitrary non-EventExecutorthreads prior to scheduled task submission.protected voidcleanup()Do nothing, sub-classes may overridevoidThis method is intended for use by process checkpoint/restore integration, such as OpenJDK CRaC.intReturns the percentage of the desired amount of time spent for I/O in the event loop.newTaskQueue(int maxPendingTasks) Create a newQueuewhich will holds the tasks to execute.voidThis method is intended for use by a process checkpoint/restore integration, such as OpenJDK CRaC.intprotected voidrun()Runs the task-processing loop untilSingleThreadEventExecutor.confirmShutdown()returnstrue.voidsetIoRatio(int ioRatio) Sets the percentage of the desired amount of time spent for I/O in the event loop.protected voidwakeup(boolean inEventLoop) Methods inherited from class SingleThreadEventLoop
afterRunningAllTasks, executeAfterEventLoopIteration, hasTasks, next, parent, pendingTasks, register, register, registerModifier 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 a reference to itself.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.Methods inherited from class SingleThreadEventExecutor
addShutdownHook, addTask, awaitTermination, confirmShutdown, deadlineNanos, delayNanos, execute, inEventLoop, interruptThread, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isShuttingDown, isTerminated, lazyExecute, newTaskQueue, peekTask, pollTask, pollTaskFrom, reject, reject, removeShutdownHook, removeTask, runAllTasks, runAllTasks, runAllTasksFrom, runScheduledAndExecutorTasks, shutdown, shutdownGracefully, takeTask, terminationFuture, threadProperties, updateLastExecutionTime, wakesUpForTaskModifier 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 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.voidbooleaninEventLoop(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.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).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 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 ThreadPropertiesprotected 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.Methods inherited from class AbstractScheduledEventExecutor
cancelScheduledTasks, deadlineToDelayNanos, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, validateScheduledModifier and TypeMethodDescriptionprotected voidCancel all scheduled tasks.protected static longdeadlineToDelayNanos(long deadlineNanos) Given an arbitrary deadlinedeadlineNanos, calculate the number of nano seconds from nowdeadlineNanoswould expire.protected longGet the current time in nanoseconds by this executor's clock.protected final booleanReturnstrueif a scheduled task is ready for processing.protected static longThe initial value used for delay and computations based upon a monatomic time source.protected static longnanoTime()Deprecated.Use the non-staticAbstractScheduledEventExecutor.getCurrentTimeNanos()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) protected voidvalidateScheduled(long amount, TimeUnit unit) Deprecated.will be removed in the future.Methods inherited from class AbstractEventExecutor
inEventLoop, iterator, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, runTask, safeExecute, shutdownGracefully, shutdownNow, submit, submit, submitModifier and TypeMethodDescriptionbooleanCallsEventExecutor.inEventLoop(Thread)withThread.currentThread()as argumentiterator()<V> Future<V> newFailedFuture(Throwable cause) Create a newFuturewhich is marked as failed already.<V> ProgressivePromise<V> Create a newProgressivePromise.<V> Promise<V> Return a newPromise.<V> Future<V> newSucceededFuture(V result) Create a newFuturewhich is marked as succeeded already.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 Iterable
forEach, spliterator
-
Method Details
-
openFileDescriptors
This method is intended for use by a process checkpoint/restore integration, such as OpenJDK CRaC. -
wakeup
protected void wakeup(boolean inEventLoop) - Overrides:
wakeupin classSingleThreadEventExecutor
-
beforeScheduledTaskSubmitted
protected boolean beforeScheduledTaskSubmitted(long deadlineNanos) Description copied from class:AbstractScheduledEventExecutorCalled from arbitrary non-EventExecutorthreads prior to scheduled task submission. Returnstrueif theEventExecutorthread should be woken immediately to process the scheduled task (if not already awake).If
falseis returned,AbstractScheduledEventExecutor.afterScheduledTaskSubmitted(long)will be called with the same value after the scheduled task is enqueued, providing another opportunity to wake theEventExecutorthread if required.- Overrides:
beforeScheduledTaskSubmittedin classAbstractScheduledEventExecutor- Parameters:
deadlineNanos- deadline of the to-be-scheduled task relative toAbstractScheduledEventExecutor.getCurrentTimeNanos()- Returns:
trueif theEventExecutorthread should be woken,falseotherwise
-
afterScheduledTaskSubmitted
protected boolean afterScheduledTaskSubmitted(long deadlineNanos) Description copied from class:AbstractScheduledEventExecutorSeeAbstractScheduledEventExecutor.beforeScheduledTaskSubmitted(long). Called only after that method returns false.- Overrides:
afterScheduledTaskSubmittedin classAbstractScheduledEventExecutor- Parameters:
deadlineNanos- relative toAbstractScheduledEventExecutor.getCurrentTimeNanos()- Returns:
trueif theEventExecutorthread should be woken,falseotherwise
-
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
-
getIoRatio
public int getIoRatio()Returns the percentage of the desired amount of time spent for I/O in the event loop. -
setIoRatio
public void setIoRatio(int ioRatio) Sets the percentage of the desired amount of time spent for I/O in the event loop. The default value is50, which means the event loop will try to spend the same amount of time for I/O as for non-I/O tasks. -
registeredChannels
public int registeredChannels()Description copied from class:SingleThreadEventLoopReturns the number ofChannels registered with thisEventLoopor-1if operation is not supported. The returned value is not guaranteed to be exact accurate and should be viewed as a best effort.- Overrides:
registeredChannelsin classSingleThreadEventLoop
-
registeredChannelsIterator
- Overrides:
registeredChannelsIteratorin classSingleThreadEventLoop- 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.
-
run
protected void run()Description copied from class:SingleThreadEventExecutorRuns the task-processing loop untilSingleThreadEventExecutor.confirmShutdown()returnstrue.Implementations must not let a
Throwablethrown by a task escape this method: any uncaughtThrowableterminates the executor (logged atWARNand surfaced viaSingleThreadEventExecutor.terminationFuture()), at which point everyChannelregistered with this executor stops processing I/O and new task submissions are rejected. The supplied helpers -SingleThreadEventExecutor.runAllTasks(),SingleThreadEventExecutor.runAllTasks(long), andAbstractEventExecutor.safeExecute(Runnable)- catchThrowablefor you; custom loops built onSingleThreadEventExecutor.pollTask()orSingleThreadEventExecutor.takeTask()are responsible for wrapping each task invocation accordingly.- Specified by:
runin classSingleThreadEventExecutor
-
cleanup
protected void cleanup()Description copied from class:SingleThreadEventExecutorDo nothing, sub-classes may override- Overrides:
cleanupin classSingleThreadEventExecutor
-
closeFileDescriptors
This method is intended for use by process checkpoint/restore integration, such as OpenJDK CRaC. It's up to the caller to ensure that there is no concurrent use of the FDs while these are closed, e.g. by blocking the executor.
-
SingleThreadEventExecutor.wakesUpForTask(Runnable)to re-create this behaviour