Class ManualIoEventLoop
java.lang.Object
java.util.concurrent.AbstractExecutorService
io.netty.util.concurrent.AbstractEventExecutor
io.netty.util.concurrent.AbstractScheduledEventExecutor
io.netty.channel.ManualIoEventLoop
- All Implemented Interfaces:
EventLoop, EventLoopGroup, IoEventLoop, IoEventLoopGroup, EventExecutor, EventExecutorGroup, OrderedEventExecutor, ThreadAwareExecutor, Iterable<EventExecutor>, Executor, ExecutorService, ScheduledExecutorService
IoEventLoop implementation that is owned by the user and so needs to be driven by the user manually with the
given Thread. This means that the user is responsible to call either runNow() or run(long)
to execute IO and tasks that were submitted to this IoEventLoop.
This is for advanced use-cases only, where the user wants to own the Thread that drives the
IoEventLoop to also do other work. Care must be taken that the or
#waitAndRun() methods are called in a timely fashion.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractEventExecutor
AbstractEventExecutor.LazyRunnable -
Constructor Summary
ConstructorsConstructorDescriptionManualIoEventLoop(IoEventLoopGroup parent, Thread owningThread, IoHandlerFactory factory) Create a newIoEventLoopthat is owned by the user and so needs to be driven by the user with the givenThread.ManualIoEventLoop(IoEventLoopGroup parent, Thread owningThread, IoHandlerFactory factory, Ticker ticker) Create a newIoEventLoopthat is owned by the user and so needs to be driven by the user with the givenThread.ManualIoEventLoop(Thread owningThread, IoHandlerFactory factory) Create a newIoEventLoopthat is owned by the user and so needs to be driven by the user with the givenThread. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanawaitTermination(long timeout, TimeUnit unit) protected booleancanBlock()This allows to specify additional blocking conditions which will be used by theIoHandlerto decide whether it is allowed to block or not.final voidfinal booleaninEventLoop(Thread thread) invokeAll(Collection<? extends Callable<T>> tasks) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) final <T> TinvokeAny(Collection<? extends Callable<T>> tasks) final <T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) final booleanisCompatible(Class<? extends IoHandle> handleType) Returnstrueif the given type is compatible with thisIoEventLoopGroupand so can be registered to the containedIoEventLoops,falseotherwise.final booleanfinal booleanfinal booleanReturnstrueif and only if allEventExecutors managed by thisEventExecutorGroupare being shut down gracefully or was shut down.final booleanfinal ManualIoEventLoopnext()Returns one of theEventExecutors managed by thisEventExecutorGroup.final IoEventLoopGroupparent()Return theEventExecutorGroupwhich is the parent of thisEventExecutor,final ChannelFutureDeprecated.final ChannelFutureregister(ChannelPromise promise) Deprecated.final ChannelFutureregister(Channel channel, ChannelPromise promise) Deprecated.final Future<IoRegistration> final intrun(long waitNanos) Run all ready IO and tasks for thisIoEventLoop.final intrun(long waitNanos, long runAllTasksTimeoutNanos) Run all ready IO and tasks for thisIoEventLoop.final intrunNonBlockingTasks(long timeoutNanos) Poll and run tasks from the task queue, until the task queue is empty or the given deadline is exceeded.
IftimeoutNanosis less or equals 0, no deadline is applied.final intrunNow()Run all ready IO and tasks for thisIoEventLoop.final intrunNow(long runAllTasksTimeoutNanos) Executes all ready IO and tasks for thisIoEventLoop.final voidsetOwningThread(Thread owningThread) Set the owning thread that will callrun(IoHandlerContext, long).final voidshutdown()Deprecated.final Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit) Signals this executor that the caller wants the executor to be shut down.final Future<?> Returns theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave been terminated.final Tickerticker()The ticker for this executor.final voidwakeup()Force a wakeup and so therun(long)method will unblock and return even if there was nothing to do.Methods inherited from class AbstractScheduledEventExecutor
afterScheduledTaskSubmitted, beforeScheduledTaskSubmitted, cancelScheduledTasks, deadlineToDelayNanos, delayNanos, fetchFromScheduledTaskQueue, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, validateScheduledMethods inherited from class AbstractEventExecutor
iterator, lazyExecute, 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, isExecutorThread, isSuspended, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, trySuspendMethods inherited from interface EventExecutorGroup
iterator, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, shutdownGracefully, shutdownNow, submit, submit, submitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
ManualIoEventLoop
Create a newIoEventLoopthat is owned by the user and so needs to be driven by the user with the givenThread. This means that the user is responsible to call eitherrunNow()orrun(long)to execute IO or tasks that were submitted to thisIoEventLoop.- Parameters:
owningThread- theThreadthat executes the IO and tasks for thisIoEventLoop. The user will use thisThreadto callrunNow()orrun(long)to make progress.factory- theIoHandlerFactorythat will be used to create theIoHandlerthat is used by thisIoEventLoop.
-
ManualIoEventLoop
Create a newIoEventLoopthat is owned by the user and so needs to be driven by the user with the givenThread. This means that the user is responsible to call eitherrunNow()orrun(long)to execute IO or tasks that were submitted to thisIoEventLoop.- Parameters:
parent- the parentIoEventLoopGroupornullif no parent.owningThread- theThreadthat executes the IO and tasks for thisIoEventLoop. The user will use thisThreadto callrunNow()orrun(long)to make progress. Ifnull, must be set later usingsetOwningThread(Thread).factory- theIoHandlerFactorythat will be used to create theIoHandlerthat is used by thisIoEventLoop.
-
ManualIoEventLoop
public ManualIoEventLoop(IoEventLoopGroup parent, Thread owningThread, IoHandlerFactory factory, Ticker ticker) Create a newIoEventLoopthat is owned by the user and so needs to be driven by the user with the givenThread. This means that the user is responsible to call eitherrunNow()orrun(long)to execute IO or tasks that were submitted to thisIoEventLoop.- Parameters:
parent- the parentIoEventLoopGroupornullif no parent.owningThread- theThreadthat executes the IO and tasks for thisIoEventLoop. The user will use thisThreadto callrunNow()orrun(long)to make progress. Ifnull, must be set later usingsetOwningThread(Thread).factory- theIoHandlerFactorythat will be used to create theIoHandlerthat is used by thisIoEventLoop.ticker- Theticker()to use for this event loop. Note that theIoHandlerdoes not use the ticker, so if the ticker advances faster than system time, you may have towakeup()this event loop manually.
-
-
Method Details
-
canBlock
protected boolean canBlock()This allows to specify additional blocking conditions which will be used by theIoHandlerto decide whether it is allowed to block or not. -
ticker
Description copied from interface:EventExecutorGroupThe ticker for this executor. Usually theEventExecutorGroup.schedule(Runnable, long, TimeUnit)methods will follow thesystem ticker(i.e.System.nanoTime()), but especially for testing it is sometimes useful to have more control over the ticker. In that case, this method will be overridden. Code that schedules tasks on this executor should use this ticker in order to stay consistent with the executor (e.g. not be surprised by scheduled tasks running "early").- Specified by:
tickerin interfaceEventExecutorGroup- Overrides:
tickerin classAbstractScheduledEventExecutor- Returns:
- The ticker for this scheduler
-
runNonBlockingTasks
public final int runNonBlockingTasks(long timeoutNanos) Poll and run tasks from the task queue, until the task queue is empty or the given deadline is exceeded.
IftimeoutNanosis less or equals 0, no deadline is applied.- Parameters:
timeoutNanos- the maximum time in nanoseconds to run tasks.
-
runNow
public final int runNow(long runAllTasksTimeoutNanos) Executes all ready IO and tasks for thisIoEventLoop. This methods will NOT block and wait for IO / tasks to be ready, it will just return directly if there is nothing to do.Must be called from the owning
Threadthat was passed as a parameter on construction.- Parameters:
runAllTasksTimeoutNanos- the maximum time in nanoseconds to run tasks. If= 0, no timeout is applied; if< 0it just perform I/O tasks.- Returns:
- the number of IO and tasks executed.
- Throws:
IllegalStateException- if the method is not called from the owningThread.
-
runNow
public final int runNow()Run all ready IO and tasks for thisIoEventLoop. This methods will NOT block and wait for IO / tasks to be ready, it will just return directly if there is nothing to do.Must be called from the owning
Threadthat was passed as a parameter on construction.- Returns:
- the number of IO and tasks executed.
-
run
public final int run(long waitNanos, long runAllTasksTimeoutNanos) Run all ready IO and tasks for thisIoEventLoop. This methods will block and wait for IO / tasks to be ready if there is nothing to process atm for the givenwaitNanos.Must be called from the owning
Threadthat was passed as an parameter on construction.- Parameters:
waitNanos- the maximum amount of nanoseconds to wait before returning. IF0it will block until there is some IO / tasks ready, if-1will not block at all and just return directly if there is nothing to run (likerunNow()).runAllTasksTimeoutNanos- the maximum time in nanoseconds to run tasks. If= 0, no timeout is applied; if< 0it just perform I/O tasks.- Returns:
- the number of IO and tasks executed.
-
run
public final int run(long waitNanos) Run all ready IO and tasks for thisIoEventLoop. This methods will block and wait for IO / tasks to be ready if there is nothing to process atm for the givenwaitNanos.Must be called from the owning
Threadthat was passed as an parameter on construction.- Parameters:
waitNanos- the maximum amount of nanoseconds to wait before returning. IF0it will block until there is some IO / tasks ready, if-1will not block at all and just return directly if there is nothing to run (likerunNow()).- Returns:
- the number of IO and tasks executed.
-
wakeup
public final void wakeup()Force a wakeup and so therun(long)method will unblock and return even if there was nothing to do. -
next
Description copied from interface:EventExecutorGroupReturns one of theEventExecutors managed by thisEventExecutorGroup.- Specified by:
nextin interfaceEventExecutorGroup- Specified by:
nextin interfaceEventLoopGroup- Specified by:
nextin interfaceIoEventLoop- Specified by:
nextin interfaceIoEventLoopGroup- Overrides:
nextin classAbstractEventExecutor
-
parent
Description copied from interface:EventExecutorReturn theEventExecutorGroupwhich is the parent of thisEventExecutor,- Specified by:
parentin interfaceEventExecutor- Specified by:
parentin interfaceEventLoop- Overrides:
parentin classAbstractEventExecutor
-
register
Deprecated.Description copied from interface:EventLoopGroupRegister aChannelwith thisEventLoop. The returnedChannelFuturewill get notified once the registration was complete.- Specified by:
registerin interfaceEventLoopGroup- Specified by:
registerin interfaceIoEventLoopGroup
-
register
Deprecated.Description copied from interface:EventLoopGroupRegister aChannelwith thisEventLoopusing aChannelFuture. The passedChannelFuturewill get notified once the registration was complete and also will get returned.- Specified by:
registerin interfaceEventLoopGroup- Specified by:
registerin interfaceIoEventLoopGroup
-
register
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.
-
register
Deprecated.Description copied from interface:EventLoopGroupRegister aChannelwith thisEventLoop. The passedChannelFuturewill get notified once the registration was complete and also will get returned.- Specified by:
registerin interfaceEventLoopGroup
-
isCompatible
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
Description copied from interface:IoEventLoopGroup- Specified by:
isIoTypein interfaceIoEventLoop- Specified by:
isIoTypein interfaceIoEventLoopGroup- Parameters:
handlerType- the type of theIoHandler.- Returns:
- if used or not.
-
inEventLoop
Description copied from interface:EventExecutor- Specified by:
inEventLoopin interfaceEventExecutor
-
setOwningThread
Set the owning thread that will callrun(IoHandlerContext, long). May only be called once, and only if the owning thread was not set in the constructor already.- Parameters:
owningThread- The owning thread
-
shutdownGracefully
Description copied from interface:EventExecutorGroupSignals this executor that the caller wants the executor to be shut down. Once this method is called,EventExecutorGroup.isShuttingDown()starts to returntrue, and the executor prepares to shut itself down. UnlikeEventExecutorGroup.shutdown(), graceful shutdown ensures that no tasks are submitted for 'the quiet period' (usually a couple seconds) before it shuts itself down. If a task is submitted during the quiet period, it is guaranteed to be accepted and the quiet period will start over.- Specified by:
shutdownGracefullyin interfaceEventExecutorGroup- Parameters:
quietPeriod- the quiet period as described in the documentationtimeout- the maximum amount of time to wait until the executor is EventExecutorGroup.shutdown() regardless if a task was submitted during the quiet periodunit- the unit ofquietPeriodandtimeout- Returns:
- the
EventExecutorGroup.terminationFuture()
-
shutdown
Deprecated.- Specified by:
shutdownin interfaceEventExecutorGroup- Specified by:
shutdownin interfaceExecutorService- Specified by:
shutdownin classAbstractEventExecutor
-
terminationFuture
Description copied from interface:EventExecutorGroupReturns theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave been terminated.- Specified by:
terminationFuturein interfaceEventExecutorGroup
-
isShuttingDown
public final boolean isShuttingDown()Description copied from interface:EventExecutorGroupReturnstrueif and only if allEventExecutors managed by thisEventExecutorGroupare being shut down gracefully or was shut down.- Specified by:
isShuttingDownin interfaceEventExecutorGroup
-
isShutdown
public final boolean isShutdown()- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public final boolean isTerminated()- Specified by:
isTerminatedin interfaceExecutorService
-
awaitTermination
- Specified by:
awaitTerminationin interfaceExecutorService- Throws:
InterruptedException
-
execute
-
invokeAny
public final <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAnyin interfaceExecutorService- Overrides:
invokeAnyin classAbstractExecutorService- Throws:
InterruptedExceptionExecutionException
-
invokeAny
public final <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
invokeAnyin interfaceExecutorService- Overrides:
invokeAnyin classAbstractExecutorService- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
invokeAll
public final <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException - Specified by:
invokeAllin interfaceExecutorService- Overrides:
invokeAllin classAbstractExecutorService- Throws:
InterruptedException
-
invokeAll
public final <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException - Specified by:
invokeAllin interfaceExecutorService- Overrides:
invokeAllin classAbstractExecutorService- Throws:
InterruptedException
-