Package io.netty.channel
Class SingleThreadIoEventLoop
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- io.netty.util.concurrent.AbstractEventExecutor
-
- io.netty.util.concurrent.AbstractScheduledEventExecutor
-
- io.netty.util.concurrent.SingleThreadEventExecutor
-
- io.netty.channel.SingleThreadEventLoop
-
- io.netty.channel.SingleThreadIoEventLoop
-
- All Implemented Interfaces:
EventLoop,EventLoopGroup,IoEventLoop,IoEventLoopGroup,io.netty.util.concurrent.EventExecutor,io.netty.util.concurrent.EventExecutorGroup,io.netty.util.concurrent.OrderedEventExecutor,io.netty.util.concurrent.ThreadAwareExecutor,Iterable<io.netty.util.concurrent.EventExecutor>,Executor,ExecutorService,ScheduledExecutorService
- Direct Known Subclasses:
NioEventLoop
public class SingleThreadIoEventLoop extends SingleThreadEventLoop implements IoEventLoop
IoEventLoopimplementation 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>
-
-
Field Summary
-
Fields inherited from class io.netty.channel.SingleThreadEventLoop
DEFAULT_MAX_PENDING_TASKS
-
-
Constructor Summary
Constructors Modifier Constructor Description SingleThreadIoEventLoop(IoEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory)Creates a new instanceSingleThreadIoEventLoop(IoEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, io.netty.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs)Creates a new instanceprotectedSingleThreadIoEventLoop(IoEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory, Queue<Runnable> taskQueue, Queue<Runnable> tailTaskQueue, io.netty.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)Creates a new instanceSingleThreadIoEventLoop(IoEventLoopGroup parent, ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory)Creates a new instanceSingleThreadIoEventLoop(IoEventLoopGroup parent, ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, io.netty.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs)Creates a new instance
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanSuspend(int state)protected voidcleanup()protected IoHandlerioHandler()booleanisCompatible(Class<? extends IoHandle> handleType)Returnstrueif the given type is compatible with thisIoEventLoopGroupand so can be registered to the containedIoEventLoops,falseotherwise.booleanisIoType(Class<? extends IoHandler> handlerType)protected Queue<Runnable>newTaskQueue(int maxPendingTasks)protected static Queue<Runnable>newTaskQueue0(int maxPendingTasks)IoEventLoopnext()Return the nextEventLoopto useio.netty.util.concurrent.Future<IoRegistration>register(IoHandle handle)protected voidrun()protected intrunIo()Called when IO will be processed for all theIoHandles on thisSingleThreadIoEventLoop.protected voidwakeup(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, 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, ticker, 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, ticker
-
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
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
SingleThreadIoEventLoop
public SingleThreadIoEventLoop(IoEventLoopGroup parent, ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory)
Creates a new instance- Parameters:
parent- the parent that holds thisIoEventLoop.threadFactory- theThreadFactorythat is used to create the underlyingThread.ioHandlerFactory- theIoHandlerFactorythat should be used to obtainIoHandlerto handle IO.
-
SingleThreadIoEventLoop
public SingleThreadIoEventLoop(IoEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory)
Creates a new instance- Parameters:
parent- the parent that holds thisIoEventLoop.executor- theExecutorthat is used for dispatching the work.ioHandlerFactory- theIoHandlerFactorythat should be used to obtainIoHandlerto handle IO.
-
SingleThreadIoEventLoop
public SingleThreadIoEventLoop(IoEventLoopGroup parent, ThreadFactory threadFactory, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, io.netty.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs)
Creates a new instance- Parameters:
parent- the parent that holds thisIoEventLoop.threadFactory- theThreadFactorythat is used to create the underlyingThread.ioHandlerFactory- theIoHandlerFactorythat should be used to obtainIoHandlerto handle IO.maxPendingTasks- the maximum pending tasks that are allowed beforeRejectedExecutionHandler.rejected(Runnable, SingleThreadEventExecutor)is called to handle it.rejectedExecutionHandler- theRejectedExecutionHandlerthat 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, Executor executor, IoHandlerFactory ioHandlerFactory, int maxPendingTasks, io.netty.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler, long maxTaskProcessingQuantumMs)
Creates a new instance- Parameters:
parent- the parent that holds thisIoEventLoop.ioHandlerFactory- theIoHandlerFactorythat should be used to obtainIoHandlerto handle IO.maxPendingTasks- the maximum pending tasks that are allowed beforeRejectedExecutionHandler.rejected(Runnable, SingleThreadEventExecutor)is called to handle it.rejectedExecutionHandler- theRejectedExecutionHandlerthat 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, Executor executor, IoHandlerFactory ioHandlerFactory, Queue<Runnable> taskQueue, Queue<Runnable> tailTaskQueue, io.netty.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
Creates a new instance- Parameters:
parent- the parent that holds thisIoEventLoop.executor- theExecutorthat is used for dispatching the work.ioHandlerFactory- theIoHandlerFactorythat should be used to obtainIoHandlerto handle IO.taskQueue- theQueueused for storing pending tasks.tailTaskQueue- theQueueused for storing tail pending tasks.rejectedExecutionHandler- theRejectedExecutionHandlerthat handles when more tasks are added then allowed.
-
-
Method Detail
-
run
protected void run()
- Specified by:
runin classio.netty.util.concurrent.SingleThreadEventExecutor
-
ioHandler
protected final IoHandler ioHandler()
-
canSuspend
protected boolean canSuspend(int state)
- Overrides:
canSuspendin classio.netty.util.concurrent.SingleThreadEventExecutor
-
runIo
protected int runIo()
Called when IO will be processed for all theIoHandles on thisSingleThreadIoEventLoop. This method returns the number ofIoHandles for which IO was processed. This method must be called from theEventLoopthread.
-
next
public IoEventLoop next()
Description copied from interface:EventLoopGroupReturn the nextEventLoopto use- Specified by:
nextin interfaceio.netty.util.concurrent.EventExecutorGroup- Specified by:
nextin interfaceEventLoopGroup- Specified by:
nextin interfaceIoEventLoop- Specified by:
nextin interfaceIoEventLoopGroup- Overrides:
nextin classSingleThreadEventLoop
-
register
public final io.netty.util.concurrent.Future<IoRegistration> register(IoHandle handle)
Description copied from interface:IoEventLoop- Specified by:
registerin interfaceIoEventLoop- Specified by:
registerin interfaceIoEventLoopGroup- Parameters:
handle- theIoHandleto register.- Returns:
- the
Futurethat is notified once the operations completes.
-
wakeup
protected final void wakeup(boolean inEventLoop)
- Overrides:
wakeupin classio.netty.util.concurrent.SingleThreadEventExecutor
-
cleanup
protected final void cleanup()
- Overrides:
cleanupin classio.netty.util.concurrent.SingleThreadEventExecutor
-
isCompatible
public boolean isCompatible(Class<? extends IoHandle> handleType)
Description copied from interface:IoEventLoopGroupReturnstrueif the given type is compatible with thisIoEventLoopGroupand so can be registered to the containedIoEventLoops,falseotherwise.- Specified by:
isCompatiblein interfaceIoEventLoop- Specified by:
isCompatiblein interfaceIoEventLoopGroup- Parameters:
handleType- the type of theIoHandle.- Returns:
- if compatible of not.
-
isIoType
public boolean isIoType(Class<? extends IoHandler> handlerType)
Description copied from interface:IoEventLoopGroup- Specified by:
isIoTypein interfaceIoEventLoop- Specified by:
isIoTypein interfaceIoEventLoopGroup- Parameters:
handlerType- the type of theIoHandler.- Returns:
- if used or not.
-
newTaskQueue
protected Queue<Runnable> newTaskQueue(int maxPendingTasks)
- Overrides:
newTaskQueuein classio.netty.util.concurrent.SingleThreadEventExecutor
-
-