Top Description Inners Fields Constructors Methods
io.netty5.channel

public Class SingleThreadEventLoop

extends SingleThreadEventExecutor
implements EventLoop
Class Inheritance
All Implemented Interfaces
io.netty5.channel.EventLoop, io.netty5.channel.EventLoopGroup, io.netty5.util.concurrent.EventExecutorGroup, java.util.concurrent.Executor, java.lang.Iterable, io.netty5.util.concurrent.OrderedEventExecutor, io.netty5.util.concurrent.EventExecutor, io.netty5.util.concurrent.FuturePromiseFactory
Imports
io.netty5.util.concurrent.Future, .Promise, .RejectedExecutionHandler, .RejectedExecutionHandlers, .SingleThreadEventExecutor, io.netty5.util.internal.PlatformDependent, .SystemPropertyUtil, java.util.Queue, java.util.concurrent.Executor, .ThreadFactory

EventLoop that execute all its submitted tasks in a single thread and uses an IoHandler for IO processing.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
SingleThreadEventLoop.NonWakeupRunnable

Marker interface for Runnable that will not trigger an wakeup(boolean) in all cases.

Field Summary

Modifier and TypeField and Description
private final IoExecutionContext
protected static final int
protected static final int
private final IoHandler
private final int
Inherited from io.netty5.util.concurrent.SingleThreadEventExecutor:
DEFAULT_MAX_PENDING_EXECUTOR_TASKS

Constructor Summary

AccessConstructor and Description
public
SingleThreadEventLoop(ThreadFactory
the ThreadFactory which will be used for the used Thread
threadFactory
,
IoHandler
the IoHandler to use.
ioHandler
)

Create a new instance

public
SingleThreadEventLoop(Executor
the Executor which will be used to run this EventLoop.
executor
,
IoHandler
the IoHandler to use.
ioHandler
)

Create a new instance

public
SingleThreadEventLoop(ThreadFactory
the ThreadFactory which will be used for the used Thread
threadFactory
,
IoHandler
the IoHandler to use.
ioHandler
,
int
the maximum number of pending tasks before new tasks will be rejected.
maxPendingTasks
,
RejectedExecutionHandler rejectedHandler)

Create a new instance

public
SingleThreadEventLoop(Executor
the Executor which will be used to run this EventLoop.
executor
,
IoHandler
the IoHandler to use.
ioHandler
,
int
the maximum number of pending tasks before new tasks will be rejected.
maxPendingTasks
,
RejectedExecutionHandler rejectedHandler)

Create a new instance

public
SingleThreadEventLoop(ThreadFactory
the ThreadFactory which will be used for the used Thread
threadFactory
,
IoHandler
the IoHandler to use.
ioHandler
,
int
the maximum number of pending tasks before new tasks will be rejected.
maxPendingTasks
,
RejectedExecutionHandler rejectedHandler, int
the maximum number of tasks per EventLoop run that will be processed before trying to handle IO again.
maxTasksPerRun
)

Create a new instance

public
SingleThreadEventLoop(Executor
the Executor which will be used to run this EventLoop.
executor
,
IoHandler
the IoHandler to use.
ioHandler
,
int
the maximum number of pending tasks before new tasks will be rejected.
maxPendingTasks
,
RejectedExecutionHandler rejectedHandler, int
the maximum number of tasks per EventLoop run that will be processed before trying to handle IO again.
maxTasksPerRun
)

Create a new instance

Method Summary

Modifier and TypeMethod and Description
private static void
protected final void
cleanup()

Overrides io.netty5.util.concurrent.SingleThreadEventExecutor.cleanup.

Do nothing, sub-classes may override.
public final Future<Void>
deregisterForIo(IoHandle
the IoHandle to deregister.
handle
)

Implements io.netty5.channel.EventLoop.deregisterForIo.

Deregister the Channel from the EventLoop for I/O processing.
private void
public boolean
isCompatible(Class<? extends IoHandle>
the type of the IoHandle.
handleType
)

Implements io.netty5.channel.EventLoop.isCompatible.

Returns true if the given type is compatible with this EventLoopGroup and so can be registered to the contained EventLoops, false otherwise.
protected Queue<Runnable>
newTaskQueue(int maxPendingTasks)

Overrides io.netty5.util.concurrent.SingleThreadEventExecutor.newTaskQueue.

Create a new Queue which will holds the tasks to execute.
public final Future<Void>
registerForIo(IoHandle
the IoHandle to register.
handle
)

Implements io.netty5.channel.EventLoop.registerForIo.

Register the IoHandle to the EventLoop for I/O processing.
private void
registerForIO0(IoHandle handle, Promise<Void> promise)

protected void
protected int
runIO()

Called when IO will be processed for all the Channels on this SingleThreadEventLoop.

protected final boolean
wakesUpForTask(Runnable task)

Overrides io.netty5.util.concurrent.SingleThreadEventExecutor.wakesUpForTask.

Returns true if wakeup(boolean) should be called for this Runnable, false otherwise.
protected final void
Inherited from io.netty5.util.concurrent.SingleThreadEventExecutor:
addShutdownHookawaitTerminationconfirmShutdowndeadlineNanosdelayNanosexecutehasTasksinEventLoopinterruptThreadisShutdownisShuttingDownisTerminatedofferTaskpendingTaskspollTaskrejectremoveShutdownHookremoveTaskrunAllTasksshutdownGracefullytakeTaskterminationFuturethreadPropertiesupdateLastExecutionTime

Field Detail

contextback to summary
private final IoExecutionContext context
DEFAULT_MAX_PENDING_TASKSback to summary
protected static final int DEFAULT_MAX_PENDING_TASKS
DEFAULT_MAX_TASKS_PER_RUNback to summary
protected static final int DEFAULT_MAX_TASKS_PER_RUN
ioHandlerback to summary
private final IoHandler ioHandler
maxTasksPerRunback to summary
private final int maxTasksPerRun

Constructor Detail

SingleThreadEventLoopback to summary
public SingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler)

Create a new instance

Parameters
threadFactory:ThreadFactory

the ThreadFactory which will be used for the used Thread

ioHandler:IoHandler

the IoHandler to use.

SingleThreadEventLoopback to summary
public SingleThreadEventLoop(Executor executor, IoHandler ioHandler)

Create a new instance

Parameters
executor:Executor

the Executor which will be used to run this EventLoop.

ioHandler:IoHandler

the IoHandler to use.

SingleThreadEventLoopback to summary
public SingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)

Create a new instance

Parameters
threadFactory:ThreadFactory

the ThreadFactory which will be used for the used Thread

ioHandler:IoHandler

the IoHandler to use.

maxPendingTasks:int

the maximum number of pending tasks before new tasks will be rejected.

rejectedHandler:RejectedExecutionHandler

the RejectedExecutionHandler to use.

SingleThreadEventLoopback to summary
public SingleThreadEventLoop(Executor executor, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)

Create a new instance

Parameters
executor:Executor

the Executor which will be used to run this EventLoop.

ioHandler:IoHandler

the IoHandler to use.

maxPendingTasks:int

the maximum number of pending tasks before new tasks will be rejected.

rejectedHandler:RejectedExecutionHandler

the RejectedExecutionHandler to use.

SingleThreadEventLoopback to summary
public SingleThreadEventLoop(ThreadFactory threadFactory, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, int maxTasksPerRun)

Create a new instance

Parameters
threadFactory:ThreadFactory

the ThreadFactory which will be used for the used Thread

ioHandler:IoHandler

the IoHandler to use.

maxPendingTasks:int

the maximum number of pending tasks before new tasks will be rejected.

rejectedHandler:RejectedExecutionHandler

the RejectedExecutionHandler to use.

maxTasksPerRun:int

the maximum number of tasks per EventLoop run that will be processed before trying to handle IO again.

SingleThreadEventLoopback to summary
public SingleThreadEventLoop(Executor executor, IoHandler ioHandler, int maxPendingTasks, RejectedExecutionHandler rejectedHandler, int maxTasksPerRun)

Create a new instance

Parameters
executor:Executor

the Executor which will be used to run this EventLoop.

ioHandler:IoHandler

the IoHandler to use.

maxPendingTasks:int

the maximum number of pending tasks before new tasks will be rejected.

rejectedHandler:RejectedExecutionHandler

the RejectedExecutionHandler to use.

maxTasksPerRun:int

the maximum number of tasks per EventLoop run that will be processed before trying to handle IO again.

Method Detail

checkInEventLoopIfPossibleback to summary
private static void checkInEventLoopIfPossible(IoHandle handle)
cleanupback to summary
protected final void cleanup()

Overrides io.netty5.util.concurrent.SingleThreadEventExecutor.cleanup.

Doc from io.netty5.util.concurrent.SingleThreadEventExecutor.cleanup.

Do nothing, sub-classes may override.

Annotations
@Override
deregisterForIoback to summary
public final Future<Void> deregisterForIo(IoHandle handle)

Implements io.netty5.channel.EventLoop.deregisterForIo.

Doc from io.netty5.channel.EventLoop.deregisterForIo.

Deregister the Channel from the EventLoop for I/O processing.

Parameters
handle:IoHandle

the IoHandle to deregister.

Returns:Future<Void>

the Future that is notified once the operations completes.

Annotations
@Override
deregisterForIOback to summary
private void deregisterForIO(IoHandle handle, Promise<Void> promise)
isCompatibleback to summary
public boolean isCompatible(Class<? extends IoHandle> handleType)

Implements io.netty5.channel.EventLoop.isCompatible.

Doc from io.netty5.channel.EventLoopGroup.isCompatible.

Returns true if the given type is compatible with this EventLoopGroup and so can be registered to the contained EventLoops, false otherwise.

Parameters
handleType:Class<? extends IoHandle>

the type of the IoHandle.

Returns:boolean

if compatible of not.

Annotations
@Override
newTaskQueueback to summary
protected Queue<Runnable> newTaskQueue(int maxPendingTasks)

Overrides io.netty5.util.concurrent.SingleThreadEventExecutor.newTaskQueue.

Doc from io.netty5.util.concurrent.SingleThreadEventExecutor.newTaskQueue.

Create a new Queue which will holds the tasks to execute. This default implementation will return a LinkedBlockingQueue but if your sub-class of SingleThreadEventExecutor will not do any blocking calls on the this Queue 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 of run() depends on a BlockingQueue so you will need to override run() as well if you return a non BlockingQueue 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.

Annotations
@Override
registerForIoback to summary
public final Future<Void> registerForIo(IoHandle handle)

Implements io.netty5.channel.EventLoop.registerForIo.

Doc from io.netty5.channel.EventLoop.registerForIo.

Register the IoHandle to the EventLoop for I/O processing.

Parameters
handle:IoHandle

the IoHandle to register.

Returns:Future<Void>

the Future that is notified once the operations completes.

Annotations
@Override
registerForIO0back to summary
private void registerForIO0(IoHandle handle, Promise<Void> promise)
runback to summary
protected void run()

Overrides io.netty5.util.concurrent.SingleThreadEventExecutor.run.

Doc from io.netty5.util.concurrent.SingleThreadEventExecutor.run.

Run tasks that are submitted to this SingleThreadEventExecutor. The implementation depends on the fact that newTaskQueue(int) returns a BlockingQueue. If you change this by overriding newTaskQueue(int) be aware that you also need to override run(). This method must be called from the EventExecutor thread.

Annotations
@Override
runIOback to summary
protected int runIO()

Called when IO will be processed for all the Channels on this SingleThreadEventLoop. This method returns the number of Channels for which IO was processed. This method must be called from the EventLoop thread.

wakesUpForTaskback to summary
protected final boolean wakesUpForTask(Runnable task)

Overrides io.netty5.util.concurrent.SingleThreadEventExecutor.wakesUpForTask.

Doc from io.netty5.util.concurrent.SingleThreadEventExecutor.wakesUpForTask.

Returns true if wakeup(boolean) should be called for this Runnable, false otherwise.

Annotations
@Override
wakeupback to summary
protected final void wakeup(boolean inEventLoop)

Overrides io.netty5.util.concurrent.SingleThreadEventExecutor.wakeup.

Annotations
@Override
io.netty5.channel back to summary

pack-priv Interface SingleThreadEventLoop.NonWakeupRunnable

extends Runnable
Known Direct Implementers
io.netty5.channel.DefaultChannelHandlerContext.WriteTask

Marker interface for Runnable that will not trigger an wakeup(boolean) in all cases.

Method Summary

Inherited from java.lang.Runnable:
run