Package io.netty.channel.epoll
Class EpollEventLoop
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- All Implemented Interfaces:
EventLoop
,EventLoopGroup
,EventExecutor
,EventExecutorGroup
,OrderedEventExecutor
,java.lang.Iterable<EventExecutor>
,java.util.concurrent.Executor
,java.util.concurrent.ExecutorService
,java.util.concurrent.ScheduledExecutorService
public class EpollEventLoop extends SingleThreadEventLoop
EventLoop
which uses epoll under the covers. Only works on Linux!
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty.channel.SingleThreadEventLoop
SingleThreadEventLoop.ChannelsReadOnlyIterator<T extends Channel>
-
Nested classes/interfaces inherited from class io.netty.util.concurrent.SingleThreadEventExecutor
SingleThreadEventExecutor.NonWakeupRunnable
-
Nested classes/interfaces inherited from class io.netty.util.concurrent.AbstractEventExecutor
AbstractEventExecutor.LazyRunnable
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
allowGrowing
private static long
AWAKE
private IntObjectMap<AbstractEpollChannel>
channels
private NativeDatagramPacketArray
datagramPacketArray
private static long
EPOLL_WAIT_MILLIS_THRESHOLD
private FileDescriptor
epollFd
private FileDescriptor
eventFd
private EpollEventArray
events
private int
ioRatio
private IovArray
iovArray
private static InternalLogger
logger
private static long
MAX_SCHEDULED_TIMERFD_NS
private java.util.concurrent.atomic.AtomicLong
nextWakeupNanos
private static long
NONE
private boolean
pendingWakeup
private IntSupplier
selectNowSupplier
private SelectStrategy
selectStrategy
private FileDescriptor
timerFd
-
Fields inherited from class io.netty.channel.SingleThreadEventLoop
DEFAULT_MAX_PENDING_TASKS
-
-
Constructor Summary
Constructors Constructor Description EpollEventLoop(EventLoopGroup parent, java.util.concurrent.Executor executor, int maxEvents, SelectStrategy strategy, RejectedExecutionHandler rejectedExecutionHandler, EventLoopTaskQueueFactory taskQueueFactory, EventLoopTaskQueueFactory tailTaskQueueFactory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
add(AbstractEpollChannel ch)
Register the given epoll with thisEventLoop
.protected boolean
afterScheduledTaskSubmitted(long deadlineNanos)
protected boolean
beforeScheduledTaskSubmitted(long deadlineNanos)
Called from arbitrary non-EventExecutor
threads prior to scheduled task submission.(package private) NativeDatagramPacketArray
cleanDatagramPacketArray()
Return a clearedNativeDatagramPacketArray
that can be used for writes in thisEventLoop
.(package private) IovArray
cleanIovArray()
protected void
cleanup()
Do nothing, sub-classes may overrideprivate void
closeAll()
void
closeFileDescriptors()
This method is intended for use by process checkpoint/restore integration, such as OpenJDK CRaC.private int
epollBusyWait()
private long
epollWait(long deadlineNanos)
private int
epollWaitNoTimerChange()
private int
epollWaitNow()
private int
epollWaitTimeboxed()
int
getIoRatio()
Returns the percentage of the desired amount of time spent for I/O in the event loop.(package private) void
handleLoopException(java.lang.Throwable t)
Visible only for testing!(package private) void
modify(AbstractEpollChannel ch)
The flags of the given epoll was modified so update the registrationprotected java.util.Queue<java.lang.Runnable>
newTaskQueue(int maxPendingTasks)
Create a newQueue
which will holds the tasks to execute.private static java.util.Queue<java.lang.Runnable>
newTaskQueue(EventLoopTaskQueueFactory queueFactory)
private static java.util.Queue<java.lang.Runnable>
newTaskQueue0(int maxPendingTasks)
void
openFileDescriptors()
This method is intended for use by a process checkpoint/restore integration, such as OpenJDK CRaC.private boolean
processReady(EpollEventArray events, int ready)
int
registeredChannels()
java.util.Iterator<Channel>
registeredChannelsIterator()
(package private) void
remove(AbstractEpollChannel ch)
Deregister the given epoll from thisEventLoop
.protected void
run()
Run the tasks in theSingleThreadEventExecutor.taskQueue
void
setIoRatio(int ioRatio)
Sets the percentage of the desired amount of time spent for I/O in the event loop.protected void
wakeup(boolean inEventLoop)
-
Methods inherited from class io.netty.channel.SingleThreadEventLoop
afterRunningAllTasks, executeAfterEventLoopIteration, hasTasks, next, parent, pendingTasks, register, register, register
-
Methods inherited from class io.netty.util.concurrent.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, wakesUpForTask
-
Methods inherited from class io.netty.util.concurrent.AbstractScheduledEventExecutor
cancelScheduledTasks, deadlineToDelayNanos, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, validateScheduled
-
Methods inherited from class io.netty.util.concurrent.AbstractEventExecutor
inEventLoop, iterator, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, runTask, safeExecute, shutdownGracefully, shutdownNow, 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.netty.util.concurrent.EventExecutor
inEventLoop, inEventLoop, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture
-
Methods inherited from interface io.netty.util.concurrent.EventExecutorGroup
isShuttingDown, iterator, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, shutdown, shutdownGracefully, shutdownGracefully, shutdownNow, submit, submit, submit, terminationFuture
-
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
EPOLL_WAIT_MILLIS_THRESHOLD
private static final long EPOLL_WAIT_MILLIS_THRESHOLD
-
epollFd
private FileDescriptor epollFd
-
eventFd
private FileDescriptor eventFd
-
timerFd
private FileDescriptor timerFd
-
channels
private final IntObjectMap<AbstractEpollChannel> channels
-
allowGrowing
private final boolean allowGrowing
-
events
private final EpollEventArray events
-
iovArray
private IovArray iovArray
-
datagramPacketArray
private NativeDatagramPacketArray datagramPacketArray
-
selectStrategy
private final SelectStrategy selectStrategy
-
selectNowSupplier
private final IntSupplier selectNowSupplier
-
AWAKE
private static final long AWAKE
- See Also:
- Constant Field Values
-
NONE
private static final long NONE
- See Also:
- Constant Field Values
-
nextWakeupNanos
private final java.util.concurrent.atomic.AtomicLong nextWakeupNanos
-
pendingWakeup
private boolean pendingWakeup
-
ioRatio
private volatile int ioRatio
-
MAX_SCHEDULED_TIMERFD_NS
private static final long MAX_SCHEDULED_TIMERFD_NS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
EpollEventLoop
EpollEventLoop(EventLoopGroup parent, java.util.concurrent.Executor executor, int maxEvents, SelectStrategy strategy, RejectedExecutionHandler rejectedExecutionHandler, EventLoopTaskQueueFactory taskQueueFactory, EventLoopTaskQueueFactory tailTaskQueueFactory)
-
-
Method Detail
-
openFileDescriptors
@UnstableApi public void openFileDescriptors()
This method is intended for use by a process checkpoint/restore integration, such as OpenJDK CRaC.
-
newTaskQueue
private static java.util.Queue<java.lang.Runnable> newTaskQueue(EventLoopTaskQueueFactory queueFactory)
-
cleanIovArray
IovArray cleanIovArray()
-
cleanDatagramPacketArray
NativeDatagramPacketArray cleanDatagramPacketArray()
Return a clearedNativeDatagramPacketArray
that can be used for writes in thisEventLoop
.
-
wakeup
protected void wakeup(boolean inEventLoop)
- Overrides:
wakeup
in classSingleThreadEventExecutor
-
beforeScheduledTaskSubmitted
protected boolean beforeScheduledTaskSubmitted(long deadlineNanos)
Description copied from class:AbstractScheduledEventExecutor
Called from arbitrary non-EventExecutor
threads prior to scheduled task submission. Returnstrue
if theEventExecutor
thread should be woken immediately to process the scheduled task (if not already awake).If
false
is returned,AbstractScheduledEventExecutor.afterScheduledTaskSubmitted(long)
will be called with the same value after the scheduled task is enqueued, providing another opportunity to wake theEventExecutor
thread if required.- Overrides:
beforeScheduledTaskSubmitted
in classAbstractScheduledEventExecutor
- Parameters:
deadlineNanos
- deadline of the to-be-scheduled task relative toAbstractScheduledEventExecutor.getCurrentTimeNanos()
- Returns:
true
if theEventExecutor
thread should be woken,false
otherwise
-
afterScheduledTaskSubmitted
protected boolean afterScheduledTaskSubmitted(long deadlineNanos)
Description copied from class:AbstractScheduledEventExecutor
SeeAbstractScheduledEventExecutor.beforeScheduledTaskSubmitted(long)
. Called only after that method returns false.- Overrides:
afterScheduledTaskSubmitted
in classAbstractScheduledEventExecutor
- Parameters:
deadlineNanos
- relative toAbstractScheduledEventExecutor.getCurrentTimeNanos()
- Returns:
true
if theEventExecutor
thread should be woken,false
otherwise
-
add
void add(AbstractEpollChannel ch) throws java.io.IOException
Register the given epoll with thisEventLoop
.- Throws:
java.io.IOException
-
modify
void modify(AbstractEpollChannel ch) throws java.io.IOException
The flags of the given epoll was modified so update the registration- Throws:
java.io.IOException
-
remove
void remove(AbstractEpollChannel ch) throws java.io.IOException
Deregister the given epoll from thisEventLoop
.- Throws:
java.io.IOException
-
newTaskQueue
protected java.util.Queue<java.lang.Runnable> newTaskQueue(int maxPendingTasks)
Description copied from class:SingleThreadEventExecutor
Create a newQueue
which will holds the tasks to execute. This default implementation will return aLinkedBlockingQueue
but if your sub-class ofSingleThreadEventExecutor
will not do any blocking calls on the thisQueue
it may make sense to@Override
this and return some more performant implementation that does not support blocking operations at all.- Overrides:
newTaskQueue
in classSingleThreadEventExecutor
-
newTaskQueue0
private static java.util.Queue<java.lang.Runnable> newTaskQueue0(int maxPendingTasks)
-
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:SingleThreadEventLoop
Returns the number ofChannel
s registered with thisEventLoop
or-1
if operation is not supported. The returned value is not guaranteed to be exact accurate and should be viewed as a best effort.- Overrides:
registeredChannels
in classSingleThreadEventLoop
-
registeredChannelsIterator
public java.util.Iterator<Channel> registeredChannelsIterator()
- Overrides:
registeredChannelsIterator
in classSingleThreadEventLoop
- Returns:
- read-only iterator of active
Channel
s 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
private long epollWait(long deadlineNanos) throws java.io.IOException
- Throws:
java.io.IOException
-
epollWaitNoTimerChange
private int epollWaitNoTimerChange() throws java.io.IOException
- Throws:
java.io.IOException
-
epollWaitNow
private int epollWaitNow() throws java.io.IOException
- Throws:
java.io.IOException
-
epollBusyWait
private int epollBusyWait() throws java.io.IOException
- Throws:
java.io.IOException
-
epollWaitTimeboxed
private int epollWaitTimeboxed() throws java.io.IOException
- Throws:
java.io.IOException
-
run
protected void run()
Description copied from class:SingleThreadEventExecutor
Run the tasks in theSingleThreadEventExecutor.taskQueue
- Specified by:
run
in classSingleThreadEventExecutor
-
handleLoopException
void handleLoopException(java.lang.Throwable t)
Visible only for testing!
-
closeAll
private void closeAll()
-
processReady
private boolean processReady(EpollEventArray events, int ready)
-
cleanup
protected void cleanup()
Description copied from class:SingleThreadEventExecutor
Do nothing, sub-classes may override- Overrides:
cleanup
in classSingleThreadEventExecutor
-
closeFileDescriptors
@UnstableApi public void 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.
-
-