Package io.netty.channel
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,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
public class ManualIoEventLoop extends io.netty.util.concurrent.AbstractScheduledEventExecutor implements IoEventLoop
IoEventLoopimplementation that is owned by the user and so needs to be driven by the user manually with the givenThread. This means that the user is responsible to call eitherrunNow()orrun(long)to execute IO and tasks that were submitted to thisIoEventLoop.This is for advanced use-cases only, where the user wants to own the
Threadthat drives theIoEventLoopto also do other work. Care must be taken that theor {@link #waitAndRun()}methods are called in a timely fashion.
-
-
Constructor Summary
Constructors Constructor Description ManualIoEventLoop(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, io.netty.util.concurrent.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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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.voidexecute(Runnable command)booleaninEventLoop(Thread thread)<T> List<Future<T>>invokeAll(Collection<? extends Callable<T>> tasks)<T> List<Future<T>>invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)<T> TinvokeAny(Collection<? extends Callable<T>> tasks)<T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)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)booleanisShutdown()booleanisShuttingDown()booleanisTerminated()ManualIoEventLoopnext()Return the nextEventLoopto useIoEventLoopGroupparent()ChannelFutureregister(Channel channel)Deprecated.ChannelFutureregister(ChannelPromise promise)Deprecated.ChannelFutureregister(Channel channel, ChannelPromise promise)Deprecated.io.netty.util.concurrent.Future<IoRegistration>register(IoHandle handle)intrun(long waitNanos)Run all ready IO and tasks for thisIoEventLoop.intrun(long waitNanos, long runAllTasksTimeoutNanos)Run all ready IO and tasks for thisIoEventLoop.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.intrunNow()Run all ready IO and tasks for thisIoEventLoop.intrunNow(long runAllTasksTimeoutNanos)Executes all ready IO and tasks for thisIoEventLoop.voidsetOwningThread(Thread owningThread)Set the owning thread that will callrun(io.netty.channel.IoHandlerContext, long).voidshutdown()Deprecated.io.netty.util.concurrent.Future<?>shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)io.netty.util.concurrent.Future<?>terminationFuture()io.netty.util.concurrent.Tickerticker()voidwakeup()Force a wakeup and so therun(long)method will unblock and return even if there was nothing to do.-
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, lazyExecute, 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, isExecutorThread, isSuspended, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, trySuspend
-
Methods inherited from interface io.netty.util.concurrent.EventExecutorGroup
iterator, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, shutdownGracefully, shutdownNow, submit, submit, submit
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
ManualIoEventLoop
public 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. 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
public ManualIoEventLoop(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. 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, io.netty.util.concurrent.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 Detail
-
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
public final io.netty.util.concurrent.Ticker ticker()
- Specified by:
tickerin interfaceio.netty.util.concurrent.EventExecutorGroup- Overrides:
tickerin classio.netty.util.concurrent.AbstractScheduledEventExecutor
-
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:
runAllTasksTimeoutNanos- the maximum time in nanoseconds to run tasks. If= 0, no timeout is applied; if< 0it just perform I/O tasks.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.
-
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
public final ManualIoEventLoop 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 classio.netty.util.concurrent.AbstractEventExecutor
-
parent
public final IoEventLoopGroup parent()
-
register
@Deprecated public final ChannelFuture register(Channel channel)
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 public final ChannelFuture register(ChannelPromise promise)
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
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.
-
register
@Deprecated public final ChannelFuture register(Channel channel, ChannelPromise promise)
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
public final 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 final 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.
-
inEventLoop
public final boolean inEventLoop(Thread thread)
- Specified by:
inEventLoopin interfaceio.netty.util.concurrent.EventExecutor
-
setOwningThread
public final void setOwningThread(Thread owningThread)
Set the owning thread that will callrun(io.netty.channel.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
public final io.netty.util.concurrent.Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)- Specified by:
shutdownGracefullyin interfaceio.netty.util.concurrent.EventExecutorGroup
-
shutdown
@Deprecated public final void shutdown()
Deprecated.- Specified by:
shutdownin interfaceio.netty.util.concurrent.EventExecutorGroup- Specified by:
shutdownin interfaceExecutorService- Specified by:
shutdownin classio.netty.util.concurrent.AbstractEventExecutor
-
terminationFuture
public final io.netty.util.concurrent.Future<?> terminationFuture()
- Specified by:
terminationFuturein interfaceio.netty.util.concurrent.EventExecutorGroup
-
isShuttingDown
public final boolean isShuttingDown()
- Specified by:
isShuttingDownin interfaceio.netty.util.concurrent.EventExecutorGroup
-
isShutdown
public final boolean isShutdown()
- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public final boolean isTerminated()
- Specified by:
isTerminatedin interfaceExecutorService
-
awaitTermination
public final boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException- Specified by:
awaitTerminationin interfaceExecutorService- Throws:
InterruptedException
-
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
-
-