Package io.netty.channel.embedded
Class EmbeddedEventLoop
java.lang.Object
java.util.concurrent.AbstractExecutorService
io.netty.util.concurrent.AbstractEventExecutor
io.netty.util.concurrent.AbstractScheduledEventExecutor
io.netty.channel.embedded.EmbeddedEventLoop
- All Implemented Interfaces:
EventLoop
,EventLoopGroup
,EventExecutor
,EventExecutorGroup
,OrderedEventExecutor
,AutoCloseable
,Iterable<EventExecutor>
,Executor
,ExecutorService
,ScheduledExecutorService
-
Nested Class Summary
Nested classes/interfaces inherited from class io.netty.util.concurrent.AbstractEventExecutor
AbstractEventExecutor.LazyRunnable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
When time is frozen, the timestamp returned bygetCurrentTimeNanos()
.private long
When time is notfrozen
, the base time to subtract fromSystem.nanoTime()
.private boolean
Whether time is currently frozen. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
advanceTimeBy
(long nanos) boolean
awaitTermination
(long timeout, TimeUnit unit) protected void
Cancel all scheduled tasks.void
(package private) void
protected long
Get the current time in nanoseconds by this executor's clock.(package private) boolean
boolean
CallsEventExecutor.inEventLoop(Thread)
withThread.currentThread()
as argumentboolean
inEventLoop
(Thread thread) boolean
boolean
Returnstrue
if and only if allEventExecutor
s managed by thisEventExecutorGroup
are being shut down gracefully or was shut down.boolean
next()
Returns a reference to itself.(package private) long
parent()
Return theEventExecutorGroup
which is the parent of thisEventExecutor
,register
(ChannelPromise promise) register
(Channel channel, ChannelPromise promise) Deprecated.(package private) long
(package private) void
runTasks()
void
shutdown()
Deprecated.Future
<?> shutdownGracefully
(long quietPeriod, long timeout, TimeUnit unit) Signals this executor that the caller wants the executor to be shut down.Future
<?> Returns theFuture
which is notified when allEventExecutor
s managed by thisEventExecutorGroup
have been terminated.(package private) void
Methods inherited from class io.netty.util.concurrent.AbstractScheduledEventExecutor
afterScheduledTaskSubmitted, beforeScheduledTaskSubmitted, deadlineToDelayNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, validateScheduled
Methods inherited from class io.netty.util.concurrent.AbstractEventExecutor
iterator, lazyExecute, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, runTask, safeExecute, 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
Methods inherited from interface io.netty.util.concurrent.EventExecutor
newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture
Methods inherited from interface io.netty.util.concurrent.EventExecutorGroup
iterator, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, shutdownGracefully, shutdownNow, submit, submit, submit
Methods inherited from interface java.util.concurrent.ExecutorService
close, invokeAll, invokeAll, invokeAny, invokeAny
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
startTime
private long startTimeWhen time is notfrozen
, the base time to subtract fromSystem.nanoTime()
. When time is frozen, this variable is unused. Initialized toAbstractScheduledEventExecutor.initialNanoTime()
so that until one of the time mutator methods is called,getCurrentTimeNanos()
matches the default behavior. -
frozenTimestamp
private long frozenTimestampWhen time is frozen, the timestamp returned bygetCurrentTimeNanos()
. When unfrozen, this is unused. -
timeFrozen
private boolean timeFrozenWhether time is currently frozen. -
tasks
-
-
Constructor Details
-
EmbeddedEventLoop
EmbeddedEventLoop()
-
-
Method Details
-
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
-
next
Description copied from interface:EventExecutor
Returns a reference to itself.- Specified by:
next
in interfaceEventExecutor
- Specified by:
next
in interfaceEventExecutorGroup
- Specified by:
next
in interfaceEventLoopGroup
- Overrides:
next
in classAbstractEventExecutor
-
execute
-
runTasks
void runTasks() -
hasPendingNormalTasks
boolean hasPendingNormalTasks() -
runScheduledTasks
long runScheduledTasks() -
nextScheduledTask
long nextScheduledTask() -
getCurrentTimeNanos
protected long getCurrentTimeNanos()Description copied from class:AbstractScheduledEventExecutor
Get the current time in nanoseconds by this executor's clock. This is not the same asSystem.nanoTime()
for two reasons:- We apply a fixed offset to the
nanoTime
- Implementations (in particular EmbeddedEventLoop) may use their own time source so they can control time for testing purposes.
- Overrides:
getCurrentTimeNanos
in classAbstractScheduledEventExecutor
- We apply a fixed offset to the
-
advanceTimeBy
void advanceTimeBy(long nanos) -
freezeTime
void freezeTime() -
unfreezeTime
void unfreezeTime() -
cancelScheduledTasks
protected void cancelScheduledTasks()Description copied from class:AbstractScheduledEventExecutor
Cancel all scheduled tasks. This method MUST be called only whenAbstractEventExecutor.inEventLoop()
istrue
.- Overrides:
cancelScheduledTasks
in classAbstractScheduledEventExecutor
-
shutdownGracefully
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()
-
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
-
shutdown
Deprecated.- Specified by:
shutdown
in interfaceEventExecutorGroup
- Specified by:
shutdown
in interfaceExecutorService
- 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.- Specified by:
isShuttingDown
in interfaceEventExecutorGroup
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminated
in interfaceExecutorService
-
awaitTermination
- Specified by:
awaitTermination
in interfaceExecutorService
-
register
Description copied from interface:EventLoopGroup
Register aChannel
with thisEventLoop
. The returnedChannelFuture
will get notified once the registration was complete.- Specified by:
register
in interfaceEventLoopGroup
-
register
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
-
register
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
-
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
Description copied from interface:EventExecutor
- Specified by:
inEventLoop
in interfaceEventExecutor
-