Package io.netty.channel
Class SingleThreadIoEventLoop
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- All Implemented Interfaces:
EventLoop
,EventLoopGroup
,IoEventLoop
,IoEventLoopGroup
,EventExecutor
,EventExecutorGroup
,OrderedEventExecutor
,ThreadAwareExecutor
,java.lang.Iterable<EventExecutor>
,java.util.concurrent.Executor
,java.util.concurrent.ExecutorService
,java.util.concurrent.ScheduledExecutorService
- Direct Known Subclasses:
EpollEventLoop
,NioEventLoop
public class SingleThreadIoEventLoop extends SingleThreadEventLoop implements IoEventLoop
IoEventLoop
implementation that execute all its submitted tasks in a single thread using the providedIoHandler
.
-
-
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 inherited from class io.netty.channel.SingleThreadEventLoop
DEFAULT_MAX_PENDING_TASKS
-
-
Constructor Summary
Constructors Modifier Constructor Description SingleThreadIoEventLoop(IoEventLoopGroup parent, java.util.concurrent.Executor executor, IoHandlerFactory ioHandlerFactory)
Creates a new instanceSingleThreadIoEventLoop(IoEventLoopGroup parent, java.util.concurrent.Executor executor, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs)
Creates a new instanceprotected
SingleThreadIoEventLoop(IoEventLoopGroup parent, java.util.concurrent.Executor executor, IoHandlerFactory ioHandlerFactory, java.util.Queue<java.lang.Runnable> taskQueue, java.util.Queue<java.lang.Runnable> tailTaskQueue, RejectedExecutionHandler rejectedExecutionHandler)
Creates a new instanceSingleThreadIoEventLoop(IoEventLoopGroup parent, java.util.concurrent.ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory)
Creates a new instanceSingleThreadIoEventLoop(IoEventLoopGroup parent, java.util.concurrent.ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs)
Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canSuspend(int state)
protected void
cleanup()
Do nothing, sub-classes may overrideprotected IoHandler
ioHandler()
boolean
isCompatible(java.lang.Class<? extends IoHandle> handleType)
Returnstrue
if the given type is compatible with thisIoEventLoopGroup
and so can be registered to the containedIoEventLoop
s,false
otherwise.boolean
isIoType(java.lang.Class<? extends IoHandler> handlerType)
IoEventLoop
next()
Returns one of theEventExecutor
s managed by thisEventExecutorGroup
.Future<IoRegistration>
register(IoHandle handle)
protected void
run()
Run the tasks in theSingleThreadEventExecutor.taskQueue
protected int
runIo()
Called when IO will be processed for all theIoHandle
s on thisSingleThreadIoEventLoop
.protected void
wakeup(boolean inEventLoop)
-
Methods inherited from class io.netty.channel.SingleThreadEventLoop
afterRunningAllTasks, executeAfterEventLoopIteration, hasTasks, parent, pendingTasks, register, register, register, registeredChannels, registeredChannelsIterator
-
Methods inherited from class io.netty.util.concurrent.SingleThreadEventExecutor
addShutdownHook, addTask, awaitTermination, canSuspend, confirmShutdown, deadlineNanos, delayNanos, execute, inEventLoop, interruptThread, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isShuttingDown, isSuspended, isTerminated, lazyExecute, newTaskQueue, newTaskQueue, peekTask, pollTask, pollTaskFrom, reject, reject, removeShutdownHook, removeTask, runAllTasks, runAllTasks, runAllTasksFrom, runScheduledAndExecutorTasks, shutdown, shutdownGracefully, takeTask, terminationFuture, threadProperties, trySuspend, updateLastExecutionTime, wakesUpForTask
-
Methods inherited from class io.netty.util.concurrent.AbstractScheduledEventExecutor
afterScheduledTaskSubmitted, beforeScheduledTaskSubmitted, cancelScheduledTasks, deadlineToDelayNanos, delayNanos, fetchFromScheduledTaskQueue, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, validateScheduled
-
Methods inherited from class io.netty.util.concurrent.AbstractEventExecutor
iterator, 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, isExecutorThread, isSuspended, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, trySuspend
-
Methods inherited from interface io.netty.util.concurrent.EventExecutorGroup
isShuttingDown, iterator, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, shutdown, shutdownGracefully, shutdownGracefully, shutdownNow, submit, submit, submit, terminationFuture
-
Methods inherited from interface io.netty.channel.EventLoopGroup
register
-
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated
-
Methods inherited from interface io.netty.channel.IoEventLoopGroup
register, register
-
-
-
-
Constructor Detail
-
SingleThreadIoEventLoop
public SingleThreadIoEventLoop(IoEventLoopGroup parent, java.util.concurrent.ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory)
Creates a new instance- Parameters:
parent
- the parent that holds thisIoEventLoop
.threadFactory
- theThreadFactory
that is used to create the underlyingThread
.ioHandlerFactory
- theIoHandlerFactory
that should be used to obtainIoHandler
to handle IO.
-
SingleThreadIoEventLoop
public SingleThreadIoEventLoop(IoEventLoopGroup parent, java.util.concurrent.Executor executor, IoHandlerFactory ioHandlerFactory)
Creates a new instance- Parameters:
parent
- the parent that holds thisIoEventLoop
.executor
- theExecutor
that is used for dispatching the work.ioHandlerFactory
- theIoHandlerFactory
that should be used to obtainIoHandler
to handle IO.
-
SingleThreadIoEventLoop
public SingleThreadIoEventLoop(IoEventLoopGroup parent, java.util.concurrent.ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs)
Creates a new instance- Parameters:
parent
- the parent that holds thisIoEventLoop
.threadFactory
- theThreadFactory
that is used to create the underlyingThread
.ioHandlerFactory
- theIoHandlerFactory
that should be used to obtainIoHandler
to handle IO.maxPendingTasks
- the maximum pending tasks that are allowed beforeRejectedExecutionHandler.rejected(Runnable, SingleThreadEventExecutor)
is called to handle it.rejectedExecutionHandler
- theRejectedExecutionHandler
that handles when more tasks are added then allowed permaxPendingTasks
.maxTaskProcessingQuantumMs
- the maximum number of milliseconds that will be spent to run tasks before trying to run IO again.
-
SingleThreadIoEventLoop
public SingleThreadIoEventLoop(IoEventLoopGroup parent, java.util.concurrent.Executor executor, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs)
Creates a new instance- Parameters:
parent
- the parent that holds thisIoEventLoop
.ioHandlerFactory
- theIoHandlerFactory
that should be used to obtainIoHandler
to handle IO.maxPendingTasks
- the maximum pending tasks that are allowed beforeRejectedExecutionHandler.rejected(Runnable, SingleThreadEventExecutor)
is called to handle it.rejectedExecutionHandler
- theRejectedExecutionHandler
that handles when more tasks are added then allowed permaxPendingTasks
.maxTaskProcessingQuantumMs
- the maximum number of milliseconds that will be spent to run tasks before trying to run IO again.
-
SingleThreadIoEventLoop
protected SingleThreadIoEventLoop(IoEventLoopGroup parent, java.util.concurrent.Executor executor, IoHandlerFactory ioHandlerFactory, java.util.Queue<java.lang.Runnable> taskQueue, java.util.Queue<java.lang.Runnable> tailTaskQueue, RejectedExecutionHandler rejectedExecutionHandler)
Creates a new instance- Parameters:
parent
- the parent that holds thisIoEventLoop
.executor
- theExecutor
that is used for dispatching the work.ioHandlerFactory
- theIoHandlerFactory
that should be used to obtainIoHandler
to handle IO.taskQueue
- theQueue
used for storing pending tasks.tailTaskQueue
- theQueue
used for storing tail pending tasks.rejectedExecutionHandler
- theRejectedExecutionHandler
that handles when more tasks are added then allowed.
-
-
Method Detail
-
run
protected void run()
Description copied from class:SingleThreadEventExecutor
Run the tasks in theSingleThreadEventExecutor.taskQueue
- Specified by:
run
in classSingleThreadEventExecutor
-
ioHandler
protected final IoHandler ioHandler()
-
canSuspend
protected boolean canSuspend(int state)
Description copied from class:SingleThreadEventExecutor
Returnstrue
if thisSingleThreadEventExecutor
can be suspended at the moment,false
otherwise. Subclasses might override this method to add extra checks.- Overrides:
canSuspend
in classSingleThreadEventExecutor
- Parameters:
state
- the current internal state of theSingleThreadEventExecutor
.- Returns:
- if suspension is possible at the moment.
-
runIo
protected int runIo()
Called when IO will be processed for all theIoHandle
s on thisSingleThreadIoEventLoop
. This method returns the number ofIoHandle
s for which IO was processed. This method must be called from theEventLoop
thread.
-
next
public IoEventLoop next()
Description copied from interface:EventExecutorGroup
Returns one of theEventExecutor
s managed by thisEventExecutorGroup
.- Specified by:
next
in interfaceEventExecutorGroup
- Specified by:
next
in interfaceEventLoopGroup
- Specified by:
next
in interfaceIoEventLoop
- Specified by:
next
in interfaceIoEventLoopGroup
- Overrides:
next
in classSingleThreadEventLoop
-
register
public final Future<IoRegistration> register(IoHandle handle)
Description copied from interface:IoEventLoop
- Specified by:
register
in interfaceIoEventLoop
- Specified by:
register
in interfaceIoEventLoopGroup
- Parameters:
handle
- theIoHandle
to register.- 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(java.lang.Class<? extends IoHandle> handleType)
Description copied from interface:IoEventLoopGroup
Returnstrue
if the given type is compatible with thisIoEventLoopGroup
and so can be registered to the containedIoEventLoop
s,false
otherwise.- Specified by:
isCompatible
in interfaceIoEventLoop
- Specified by:
isCompatible
in interfaceIoEventLoopGroup
- Parameters:
handleType
- the type of theIoHandle
.- Returns:
- if compatible of not.
-
isIoType
public boolean isIoType(java.lang.Class<? extends IoHandler> handlerType)
Description copied from interface:IoEventLoopGroup
- Specified by:
isIoType
in interfaceIoEventLoop
- Specified by:
isIoType
in interfaceIoEventLoopGroup
- Parameters:
handlerType
- the type of theIoHandler
.- Returns:
- if used or not.
-
-