Class KQueueEventLoop
- All Implemented Interfaces:
EventLoop, EventLoopGroup, EventExecutor, EventExecutorGroup, OrderedEventExecutor, Iterable<EventExecutor>, Executor, ExecutorService, ScheduledExecutorService
EventLoop which uses kqueue under the covers. Only works on BSD!-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) final classNested 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 final Queue<KQueueEventLoop.KQueueRegistration> private final KQueueEventArrayprivate final KQueueEventArrayprivate intprivate final IovArrayprivate static final intprivate static final intprivate final FileDescriptorprivate static final InternalLoggerprivate longprivate final LongObjectMap<KQueueEventLoop.KQueueRegistration> private final IntSupplierprivate final SelectStrategyprivate static final AtomicIntegerFieldUpdater<KQueueEventLoop> private intFields inherited from class SingleThreadEventLoop
DEFAULT_MAX_PENDING_TASKS -
Constructor Summary
ConstructorsConstructorDescriptionKQueueEventLoop(EventLoopGroup parent, Executor executor, int maxEvents, SelectStrategy strategy, RejectedExecutionHandler rejectedExecutionHandler, EventLoopTaskQueueFactory taskQueueFactory, EventLoopTaskQueueFactory tailTaskQueueFactory) -
Method Summary
Modifier and TypeMethodDescription(package private) KQueueEventLoop.KQueueRegistration(package private) IovArrayprotected voidcleanup()Do nothing, sub-classes may overrideprivate voidcloseAll()private longintReturns the percentage of the desired amount of time spent for I/O in the event loop.private static voidprivate intkqueueWait(boolean oldWakeup) private intkqueueWait(int timeoutSec, int timeoutNs) private intnewTaskQueue(int maxPendingTasks) Create a newQueuewhich will holds the tasks to execute.newTaskQueue(EventLoopTaskQueueFactory queueFactory) newTaskQueue0(int maxPendingTasks) private voidprivate voidprocessReady(int ready) intprotected 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.private voidwakeup()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
afterScheduledTaskSubmitted, beforeScheduledTaskSubmitted, 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
-
WAKEN_UP_UPDATER
-
KQUEUE_WAKE_UP_IDENT
private static final int KQUEUE_WAKE_UP_IDENT- See Also:
-
KQUEUE_MAX_TIMEOUT_SECONDS
private static final int KQUEUE_MAX_TIMEOUT_SECONDS- See Also:
-
allowGrowing
private final boolean allowGrowing -
kqueueFd
-
changeList
-
eventList
-
selectStrategy
-
iovArray
-
selectNowSupplier
-
registrations
-
cancelledRegistrations
-
nextId
private long nextId -
wakenUp
private volatile int wakenUp -
ioRatio
private volatile int ioRatio
-
-
Constructor Details
-
KQueueEventLoop
KQueueEventLoop(EventLoopGroup parent, Executor executor, int maxEvents, SelectStrategy strategy, RejectedExecutionHandler rejectedExecutionHandler, EventLoopTaskQueueFactory taskQueueFactory, EventLoopTaskQueueFactory tailTaskQueueFactory)
-
-
Method Details
-
newTaskQueue
-
generateNextId
private long generateNextId() -
processCancelledRegistrations
private void processCancelledRegistrations() -
add
-
cleanArray
-
wakeup
protected void wakeup(boolean inEventLoop) - Overrides:
wakeupin classSingleThreadEventExecutor
-
wakeup
private void wakeup() -
kqueueWait
- Throws:
IOException
-
kqueueWaitNow
- Throws:
IOException
-
kqueueWait
- Throws:
IOException
-
processReady
private void processReady(int ready) -
run
protected void run()Description copied from class:SingleThreadEventExecutorRun the tasks in theSingleThreadEventExecutor.taskQueue- Specified by:
runin classSingleThreadEventExecutor
-
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.
-
cleanup
protected void cleanup()Description copied from class:SingleThreadEventExecutorDo nothing, sub-classes may override- Overrides:
cleanupin classSingleThreadEventExecutor
-
closeAll
private void closeAll() -
handleLoopException
-