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
,EventExecutor
,EventExecutorGroup
,OrderedEventExecutor
,ThreadAwareExecutor
,java.lang.Iterable<EventExecutor>
,java.util.concurrent.Executor
,java.util.concurrent.ExecutorService
,java.util.concurrent.ScheduledExecutorService
public final class ManualIoEventLoop extends AbstractScheduledEventExecutor implements IoEventLoop
IoEventLoop
implementation 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
Thread
that drives theIoEventLoop
to also do other work. Care must be taken that theor {@link #waitAndRun()}
methods are called in a timely fashion.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty.util.concurrent.AbstractEventExecutor
AbstractEventExecutor.LazyRunnable
-
-
Constructor Summary
Constructors Constructor Description ManualIoEventLoop(IoEventLoopGroup parent, java.lang.Thread owningThread, IoHandlerFactory factory)
Create a newIoEventLoop
that is owned by the user and so needs to be driven by the user with the givenThread
.ManualIoEventLoop(java.lang.Thread owningThread, IoHandlerFactory factory)
Create a newIoEventLoop
that 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 boolean
awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
void
execute(java.lang.Runnable command)
boolean
inEventLoop(java.lang.Thread thread)
Returntrue
if the givenThread
is executed in the event loop,false
otherwise.<T> java.util.List<java.util.concurrent.Future<T>>
invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
<T> java.util.List<java.util.concurrent.Future<T>>
invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)
<T> T
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
<T> T
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)
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)
boolean
isShutdown()
boolean
isShuttingDown()
Returnstrue
if and only if allEventExecutor
s managed by thisEventExecutorGroup
are being shut down gracefully or was shut down.boolean
isTerminated()
ManualIoEventLoop
next()
Returns one of theEventExecutor
s managed by thisEventExecutorGroup
.IoEventLoopGroup
parent()
Return theEventExecutorGroup
which is the parent of thisEventExecutor
,ChannelFuture
register(Channel channel)
Deprecated.ChannelFuture
register(ChannelPromise promise)
Deprecated.ChannelFuture
register(Channel channel, ChannelPromise promise)
Deprecated.Future<IoRegistration>
register(IoHandle handle)
int
run(long waitNanos)
Run all ready IO and tasks for thisIoEventLoop
.int
runNow()
Run all ready IO and tasks for thisIoEventLoop
.void
setOwningThread(java.lang.Thread owningThread)
Set the owning thread that will callrun(io.netty.channel.IoHandlerContext)
.void
shutdown()
Deprecated.Future<?>
shutdownGracefully(long quietPeriod, long timeout, java.util.concurrent.TimeUnit unit)
Signals this executor that the caller wants the executor to be shut down.Future<?>
terminationFuture()
Returns theFuture
which is notified when allEventExecutor
s managed by thisEventExecutorGroup
have been terminated.void
wakeup()
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
-
-
-
-
Constructor Detail
-
ManualIoEventLoop
public ManualIoEventLoop(java.lang.Thread owningThread, IoHandlerFactory factory)
Create a newIoEventLoop
that 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
- theThread
that executes the IO and tasks for thisIoEventLoop
. The user will use thisThread
to callrunNow()
orrun(long)
to make progress.factory
- theIoHandlerFactory
that will be used to create theIoHandler
that is used by thisIoEventLoop
.
-
ManualIoEventLoop
public ManualIoEventLoop(IoEventLoopGroup parent, java.lang.Thread owningThread, IoHandlerFactory factory)
Create a newIoEventLoop
that 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 parentIoEventLoopGroup
ornull
if no parent.owningThread
- theThread
that executes the IO and tasks for thisIoEventLoop
. The user will use thisThread
to callrunNow()
orrun(long)
to make progress. Ifnull
, must be set later usingsetOwningThread(Thread)
.factory
- theIoHandlerFactory
that will be used to create theIoHandler
that is used by thisIoEventLoop
.
-
-
Method Detail
-
runNow
public 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
Thread
that was passed as an parameter on construction.- Returns:
- the number of IO and tasks executed.
-
run
public 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
Thread
that was passed as an parameter on construction.- Parameters:
waitNanos
- the maximum amount of nanoseconds to wait before returning.- Returns:
- the number of IO and tasks executed.
-
wakeup
public void wakeup()
Force a wakeup and so therun(long)
method will unblock and return even if there was nothing to do.
-
next
public ManualIoEventLoop 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 classAbstractEventExecutor
-
parent
public IoEventLoopGroup parent()
Description copied from interface:EventExecutor
Return theEventExecutorGroup
which is the parent of thisEventExecutor
,- Specified by:
parent
in interfaceEventExecutor
- Specified by:
parent
in interfaceEventLoop
- Overrides:
parent
in classAbstractEventExecutor
-
register
@Deprecated public ChannelFuture register(Channel channel)
Deprecated.Description copied from interface:EventLoopGroup
Register aChannel
with thisEventLoop
. The returnedChannelFuture
will get notified once the registration was complete.- Specified by:
register
in interfaceEventLoopGroup
- Specified by:
register
in interfaceIoEventLoopGroup
-
register
@Deprecated public ChannelFuture register(ChannelPromise promise)
Deprecated.Description copied from interface:EventLoopGroup
Register aChannel
with thisEventLoop
using aChannelFuture
. The passedChannelFuture
will get notified once the registration was complete and also will get returned.- Specified by:
register
in interfaceEventLoopGroup
- Specified by:
register
in interfaceIoEventLoopGroup
-
register
public 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.
-
register
@Deprecated public ChannelFuture register(Channel channel, ChannelPromise promise)
Deprecated.Description copied from interface:EventLoopGroup
Register aChannel
with thisEventLoop
. The passedChannelFuture
will get notified once the registration was complete and also will get returned.- Specified by:
register
in interfaceEventLoopGroup
-
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.
-
inEventLoop
public boolean inEventLoop(java.lang.Thread thread)
Description copied from interface:EventExecutor
Returntrue
if the givenThread
is executed in the event loop,false
otherwise.- Specified by:
inEventLoop
in interfaceEventExecutor
-
setOwningThread
public void setOwningThread(java.lang.Thread owningThread)
Set the owning thread that will callrun(io.netty.channel.IoHandlerContext)
. 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 Future<?> shutdownGracefully(long quietPeriod, long timeout, java.util.concurrent.TimeUnit unit)
Description copied from interface:EventExecutorGroup
Signals 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:
shutdownGracefully
in 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 ofquietPeriod
andtimeout
- Returns:
- the
EventExecutorGroup.terminationFuture()
-
shutdown
@Deprecated public void shutdown()
Deprecated.- Specified by:
shutdown
in interfaceEventExecutorGroup
- Specified by:
shutdown
in interfacejava.util.concurrent.ExecutorService
- Specified by:
shutdown
in classAbstractEventExecutor
-
terminationFuture
public Future<?> terminationFuture()
Description copied from interface:EventExecutorGroup
Returns theFuture
which is notified when allEventExecutor
s managed by thisEventExecutorGroup
have been terminated.- Specified by:
terminationFuture
in interfaceEventExecutorGroup
-
isShuttingDown
public boolean isShuttingDown()
Description copied from interface:EventExecutorGroup
Returnstrue
if and only if allEventExecutor
s managed by thisEventExecutorGroup
are being shut down gracefully or was shut down.- Specified by:
isShuttingDown
in interfaceEventExecutorGroup
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfacejava.util.concurrent.ExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfacejava.util.concurrent.ExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
awaitTermination
in interfacejava.util.concurrent.ExecutorService
- Throws:
java.lang.InterruptedException
-
execute
public void execute(java.lang.Runnable command)
- Specified by:
execute
in interfacejava.util.concurrent.Executor
-
invokeAny
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Specified by:
invokeAny
in interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAny
in classjava.util.concurrent.AbstractExecutorService
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
invokeAny
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
- Specified by:
invokeAny
in interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAny
in classjava.util.concurrent.AbstractExecutorService
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
-
invokeAll
public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) throws java.lang.InterruptedException
- Specified by:
invokeAll
in interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAll
in classjava.util.concurrent.AbstractExecutorService
- Throws:
java.lang.InterruptedException
-
invokeAll
public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
invokeAll
in interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAll
in classjava.util.concurrent.AbstractExecutorService
- Throws:
java.lang.InterruptedException
-
-