- java.lang.Object
-
- io.netty5.util.concurrent.AbstractEventExecutor
-
- io.netty5.util.concurrent.AbstractScheduledEventExecutor
-
- io.netty5.util.concurrent.SingleThreadEventExecutor
-
- io.netty5.channel.SingleThreadEventLoop
-
- All Implemented Interfaces:
EventLoop
,EventLoopGroup
,EventExecutor
,EventExecutorGroup
,FuturePromiseFactory
,OrderedEventExecutor
,Iterable<EventExecutor>
,Executor
public class SingleThreadEventLoop extends SingleThreadEventExecutor implements EventLoop
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
DEFAULT_MAX_PENDING_TASKS
protected static int
DEFAULT_MAX_TASKS_PER_RUN
-
Fields inherited from class io.netty5.util.concurrent.SingleThreadEventExecutor
DEFAULT_MAX_PENDING_EXECUTOR_TASKS
-
-
Constructor Summary
Constructors Constructor Description SingleThreadEventLoop(Executor executor, IoHandler ioHandler)
Create a new instanceSingleThreadEventLoop(Executor executor, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
Create a new instanceSingleThreadEventLoop(Executor executor, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, int maxTasksPerRun)
Create a new instanceSingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler)
Create a new instanceSingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
Create a new instanceSingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, int maxTasksPerRun)
Create a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cleanup()
Do nothing, sub-classes may override.Future<Void>
deregisterForIo(IoHandle handle)
boolean
isCompatible(Class<? extends IoHandle> handleType)
Returnstrue
if the given type is compatible with thisEventLoopGroup
and so can be registered to the containedEventLoop
s,false
otherwise.protected Queue<Runnable>
newTaskQueue(int maxPendingTasks)
Create a newQueue
which will holds the tasks to execute.Future<Void>
registerForIo(IoHandle handle)
protected void
run()
Run tasks that are submitted to thisSingleThreadEventExecutor
.protected int
runIO()
Called when IO will be processed for all theChannel
s on thisSingleThreadEventLoop
.protected boolean
wakesUpForTask(Runnable task)
Returnstrue
ifSingleThreadEventExecutor.wakeup(boolean)
should be called for thisRunnable
,false
otherwise.protected void
wakeup(boolean inEventLoop)
-
Methods inherited from class io.netty5.util.concurrent.SingleThreadEventExecutor
addShutdownHook, awaitTermination, confirmShutdown, deadlineNanos, delayNanos, execute, hasTasks, inEventLoop, interruptThread, isShutdown, isShuttingDown, isTerminated, offerTask, pendingTasks, pollTask, reject, removeShutdownHook, removeTask, runAllTasks, shutdownGracefully, takeTask, terminationFuture, threadProperties, updateLastExecutionTime
-
Methods inherited from class io.netty5.util.concurrent.AbstractScheduledEventExecutor
cancelScheduledTasks, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, newRunnableScheduledFuture, newScheduledTaskFor, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay
-
Methods inherited from class io.netty5.util.concurrent.AbstractEventExecutor
newSucceededFuture, newTaskFor, newTaskFor, 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.netty5.util.concurrent.EventExecutor
execute, inEventLoop, inEventLoop, iterator, newFailedFuture, newPromise, newSucceededFuture, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submit, submit, submit
-
Methods inherited from interface io.netty5.util.concurrent.EventExecutorGroup
awaitTermination, isShutdown, isShuttingDown, isTerminated, shutdownGracefully, shutdownGracefully, terminationFuture
-
Methods inherited from interface io.netty5.util.concurrent.FuturePromiseFactory
newSucceededFuture
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
SingleThreadEventLoop
public SingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler)
Create a new instance- Parameters:
threadFactory
- theThreadFactory
which will be used for the usedThread
ioHandler
- theIoHandler
to use.
-
SingleThreadEventLoop
public SingleThreadEventLoop(Executor executor, IoHandler ioHandler)
Create a new instance
-
SingleThreadEventLoop
public SingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
Create a new instance- Parameters:
threadFactory
- theThreadFactory
which will be used for the usedThread
ioHandler
- theIoHandler
to use.maxPendingTasks
- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler
- theRejectedExecutionHandler
to use.
-
SingleThreadEventLoop
public SingleThreadEventLoop(Executor executor, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
Create a new instance- Parameters:
executor
- theExecutor
which will be used to run thisEventLoop
.ioHandler
- theIoHandler
to use.maxPendingTasks
- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler
- theRejectedExecutionHandler
to use.
-
SingleThreadEventLoop
public SingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, int maxTasksPerRun)
Create a new instance- Parameters:
threadFactory
- theThreadFactory
which will be used for the usedThread
ioHandler
- theIoHandler
to use.maxPendingTasks
- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler
- theRejectedExecutionHandler
to use.maxTasksPerRun
- the maximum number of tasks perEventLoop
run that will be processed before trying to handle IO again.
-
SingleThreadEventLoop
public SingleThreadEventLoop(Executor executor, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, int maxTasksPerRun)
Create a new instance- Parameters:
executor
- theExecutor
which will be used to run thisEventLoop
.ioHandler
- theIoHandler
to use.maxPendingTasks
- the maximum number of pending tasks before new tasks will be rejected.rejectedHandler
- theRejectedExecutionHandler
to use.maxTasksPerRun
- the maximum number of tasks perEventLoop
run that will be processed before trying to handle IO again.
-
-
Method Detail
-
newTaskQueue
protected Queue<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. Be aware that the implementation ofSingleThreadEventExecutor.run()
depends on aBlockingQueue
so you will need to overrideSingleThreadEventExecutor.run()
as well if you return a nonBlockingQueue
from this method. As this method is called from within the constructor you can only use the parameters passed into the method when overriding this method.- Overrides:
newTaskQueue
in classSingleThreadEventExecutor
-
wakesUpForTask
protected final boolean wakesUpForTask(Runnable task)
Description copied from class:SingleThreadEventExecutor
Returnstrue
ifSingleThreadEventExecutor.wakeup(boolean)
should be called for thisRunnable
,false
otherwise.- Overrides:
wakesUpForTask
in classSingleThreadEventExecutor
-
run
protected void run()
Description copied from class:SingleThreadEventExecutor
Run tasks that are submitted to thisSingleThreadEventExecutor
. The implementation depends on the fact thatSingleThreadEventExecutor.newTaskQueue(int)
returns aBlockingQueue
. If you change this by overridingSingleThreadEventExecutor.newTaskQueue(int)
be aware that you also need to overrideSingleThreadEventExecutor.run()
. This method must be called from theEventExecutor
thread.- Overrides:
run
in classSingleThreadEventExecutor
-
runIO
protected int runIO()
Called when IO will be processed for all theChannel
s on thisSingleThreadEventLoop
. This method returns the number ofChannel
s for which IO was processed. This method must be called from theEventLoop
thread.
-
registerForIo
public final Future<Void> registerForIo(IoHandle handle)
Description copied from interface:EventLoop
- Specified by:
registerForIo
in interfaceEventLoop
- Parameters:
handle
- theIoHandle
to register.- Returns:
- the
Future
that is notified once the operations completes.
-
deregisterForIo
public final Future<Void> deregisterForIo(IoHandle handle)
Description copied from interface:EventLoop
- Specified by:
deregisterForIo
in interfaceEventLoop
- Returns:
- the
Future
that is notified once the operations completes.
-
wakeup
protected final void wakeup(boolean inEventLoop)
- Overrides:
wakeup
in classSingleThreadEventExecutor
-
cleanup
protected final void cleanup()
Description copied from class:SingleThreadEventExecutor
Do nothing, sub-classes may override.- Overrides:
cleanup
in classSingleThreadEventExecutor
-
isCompatible
public boolean isCompatible(Class<? extends IoHandle> handleType)
Description copied from interface:EventLoopGroup
Returnstrue
if the given type is compatible with thisEventLoopGroup
and so can be registered to the containedEventLoop
s,false
otherwise.- Specified by:
isCompatible
in interfaceEventLoop
- Specified by:
isCompatible
in interfaceEventLoopGroup
- Parameters:
handleType
- the type of theIoHandle
.- Returns:
- if compatible of not.
-
-