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>Nested classes/interfaces inherited from class SingleThreadEventExecutor
SingleThreadEventExecutor.NonWakeupRunnableNested classes/interfaces inherited from class AbstractEventExecutor
AbstractEventExecutor.LazyRunnable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanprivate static final longprivate final IntObjectMap<AbstractEpollChannel> private NativeDatagramPacketArrayprivate static final longprivate FileDescriptorprivate FileDescriptorprivate final EpollEventArrayprivate intprivate IovArrayprivate static final InternalLoggerprivate static final longprivate final AtomicLongprivate static final longprivate booleanprivate final IntSupplierprivate final SelectStrategyprivate FileDescriptorFields inherited from class SingleThreadEventLoop
DEFAULT_MAX_PENDING_TASKS -
Constructor Summary
ConstructorsConstructorDescriptionEpollEventLoop(EventLoopGroup parent, Executor executor, int maxEvents, SelectStrategy strategy, RejectedExecutionHandler rejectedExecutionHandler, EventLoopTaskQueueFactory taskQueueFactory, EventLoopTaskQueueFactory tailTaskQueueFactory) -
Method Summary
Modifier and TypeMethodDescription(package private) voidRegister the given epoll with thisEventLoop.protected booleanafterScheduledTaskSubmitted(long deadlineNanos) protected booleanbeforeScheduledTaskSubmitted(long deadlineNanos) Called from arbitrary non-EventExecutorthreads prior to scheduled task submission.(package private) NativeDatagramPacketArrayReturn a clearedNativeDatagramPacketArraythat can be used for writes in thisEventLoop.(package private) IovArrayprotected voidcleanup()Do nothing, sub-classes may overrideprivate voidcloseAll()private static voidvoidThis method is intended for use by process checkpoint/restore integration, such as OpenJDK CRaC.private intprivate longepollWait(long deadlineNanos) private intprivate intprivate intintReturns the percentage of the desired amount of time spent for I/O in the event loop.(package private) voidVisible only for testing!(package private) voidThe flags of the given epoll was modified so update the registrationnewTaskQueue(int maxPendingTasks) Create a newQueuewhich will holds the tasks to execute.newTaskQueue(EventLoopTaskQueueFactory queueFactory) newTaskQueue0(int maxPendingTasks) voidThis method is intended for use by a process checkpoint/restore integration, such as OpenJDK CRaC.private booleanprocessReady(EpollEventArray events, int ready) int(package private) voidDeregister the given epoll from thisEventLoop.protected voidrun()Run the tasks in theSingleThreadEventExecutor.taskQueuevoidsetIoRatio(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, registerMethods 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, wakesUpForTaskMethods inherited from class AbstractScheduledEventExecutor
cancelScheduledTasks, deadlineToDelayNanos, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, validateScheduledMethods inherited from class AbstractEventExecutor
inEventLoop, iterator, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, 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, newFailedFuture, newProgressivePromise, newPromise, newSucceededFutureMethods inherited from interface EventExecutorGroup
isShuttingDown, iterator, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, shutdown, shutdownGracefully, shutdownGracefully, shutdownNow, submit, submit, submit, terminationFutureMethods inherited from interface ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminatedMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
logger
-
EPOLL_WAIT_MILLIS_THRESHOLD
private static final long EPOLL_WAIT_MILLIS_THRESHOLD -
epollFd
-
eventFd
-
timerFd
-
channels
-
allowGrowing
private final boolean allowGrowing -
events
-
iovArray
-
datagramPacketArray
-
selectStrategy
-
selectNowSupplier
-
AWAKE
private static final long AWAKE- See Also:
-
NONE
private static final long NONE- See Also:
-
nextWakeupNanos
-
pendingWakeup
private boolean pendingWakeup -
ioRatio
private volatile int ioRatio -
MAX_SCHEDULED_TIMERFD_NS
private static final long MAX_SCHEDULED_TIMERFD_NS- See Also:
-
-
Constructor Details
-
EpollEventLoop
EpollEventLoop(EventLoopGroup parent, Executor executor, int maxEvents, SelectStrategy strategy, RejectedExecutionHandler rejectedExecutionHandler, EventLoopTaskQueueFactory taskQueueFactory, EventLoopTaskQueueFactory tailTaskQueueFactory)
-
-
Method Details
-
openFileDescriptors
This method is intended for use by a process checkpoint/restore integration, such as OpenJDK CRaC. -
closeFileDescriptor
-
newTaskQueue
-
cleanIovArray
-
cleanDatagramPacketArray
NativeDatagramPacketArray cleanDatagramPacketArray()Return a clearedNativeDatagramPacketArraythat can be used for writes in thisEventLoop. -
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
-
add
Register the given epoll with thisEventLoop.- Throws:
IOException
-
modify
The flags of the given epoll was modified so update the registration- Throws:
IOException
-
remove
Deregister the given epoll from thisEventLoop.- Throws:
IOException
-
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
-
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.
-
epollWait
- Throws:
IOException
-
epollWaitNoTimerChange
- Throws:
IOException
-
epollWaitNow
- Throws:
IOException
-
epollBusyWait
- Throws:
IOException
-
epollWaitTimeboxed
- Throws:
IOException
-
run
protected void run()Description copied from class:SingleThreadEventExecutorRun the tasks in theSingleThreadEventExecutor.taskQueue- Specified by:
runin classSingleThreadEventExecutor
-
handleLoopException
Visible only for testing! -
closeAll
private void closeAll() -
processReady
-
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.
-