Package io.netty.util.concurrent
Class ImmediateEventExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- io.netty.util.concurrent.AbstractEventExecutor
-
- io.netty.util.concurrent.ImmediateEventExecutor
-
- All Implemented Interfaces:
EventExecutor
,EventExecutorGroup
,java.lang.Iterable<EventExecutor>
,java.util.concurrent.Executor
,java.util.concurrent.ExecutorService
,java.util.concurrent.ScheduledExecutorService
public final class ImmediateEventExecutor extends AbstractEventExecutor
ExecutesRunnable
objects in the caller's thread. If theexecute(Runnable)
is reentrant it will be queued until the originalRunnable
finishes execution.All
Throwable
objects thrown fromexecute(Runnable)
will be swallowed and logged. This is to ensure that all queuedRunnable
objects have the chance to be run.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ImmediateEventExecutor.ImmediateProgressivePromise<V>
(package private) static class
ImmediateEventExecutor.ImmediatePromise<V>
-
Nested classes/interfaces inherited from class io.netty.util.concurrent.AbstractEventExecutor
AbstractEventExecutor.LazyRunnable
-
-
Field Summary
Fields Modifier and Type Field Description private static FastThreadLocal<java.util.Queue<java.lang.Runnable>>
DELAYED_RUNNABLES
A Runnable will be queued if we are executing a Runnable.static ImmediateEventExecutor
INSTANCE
private static InternalLogger
logger
private static FastThreadLocal<java.lang.Boolean>
RUNNING
Set totrue
if we are executing a runnable.private Future<?>
terminationFuture
-
Fields inherited from class io.netty.util.concurrent.AbstractEventExecutor
DEFAULT_SHUTDOWN_QUIET_PERIOD, DEFAULT_SHUTDOWN_TIMEOUT
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ImmediateEventExecutor()
-
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()
CallsEventExecutor.inEventLoop(Thread)
withThread.currentThread()
as argumentboolean
inEventLoop(java.lang.Thread thread)
Returntrue
if the givenThread
is executed in the event loop,false
otherwise.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()
<V> ProgressivePromise<V>
newProgressivePromise()
Create a newProgressivePromise
.<V> Promise<V>
newPromise()
Return a newPromise
.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.-
Methods inherited from class io.netty.util.concurrent.AbstractEventExecutor
iterator, lazyExecute, newFailedFuture, newSucceededFuture, newTaskFor, newTaskFor, next, parent, safeExecute, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, shutdownGracefully, shutdownNow, submit, submit, submit
-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
INSTANCE
public static final ImmediateEventExecutor INSTANCE
-
DELAYED_RUNNABLES
private static final FastThreadLocal<java.util.Queue<java.lang.Runnable>> DELAYED_RUNNABLES
A Runnable will be queued if we are executing a Runnable. This is to prevent aStackOverflowError
.
-
RUNNING
private static final FastThreadLocal<java.lang.Boolean> RUNNING
Set totrue
if we are executing a runnable.
-
terminationFuture
private final Future<?> terminationFuture
-
-
Method Detail
-
inEventLoop
public boolean inEventLoop()
Description copied from interface:EventExecutor
CallsEventExecutor.inEventLoop(Thread)
withThread.currentThread()
as argument- Specified by:
inEventLoop
in interfaceEventExecutor
- Overrides:
inEventLoop
in classAbstractEventExecutor
-
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.
-
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.- 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()
-
terminationFuture
public Future<?> terminationFuture()
Description copied from interface:EventExecutorGroup
Returns theFuture
which is notified when allEventExecutor
s managed by thisEventExecutorGroup
have been terminated.
-
shutdown
@Deprecated public void shutdown()
Deprecated.- Specified by:
shutdown
in interfaceEventExecutorGroup
- Specified by:
shutdown
in interfacejava.util.concurrent.ExecutorService
- Specified by:
shutdown
in classAbstractEventExecutor
-
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.
-
isShutdown
public boolean isShutdown()
-
isTerminated
public boolean isTerminated()
-
awaitTermination
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
-
execute
public void execute(java.lang.Runnable command)
-
newPromise
public <V> Promise<V> newPromise()
Description copied from interface:EventExecutor
Return a newPromise
.- Specified by:
newPromise
in interfaceEventExecutor
- Overrides:
newPromise
in classAbstractEventExecutor
-
newProgressivePromise
public <V> ProgressivePromise<V> newProgressivePromise()
Description copied from interface:EventExecutor
Create a newProgressivePromise
.- Specified by:
newProgressivePromise
in interfaceEventExecutor
- Overrides:
newProgressivePromise
in classAbstractEventExecutor
-
-