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,java.lang.Iterable<EventExecutor>,java.util.concurrent.Executor,java.util.concurrent.ExecutorService,java.util.concurrent.ScheduledExecutorService
final class EmbeddedEventLoop extends AbstractScheduledEventExecutor implements EventLoop
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty.util.concurrent.AbstractEventExecutor
AbstractEventExecutor.LazyRunnable
-
-
Field Summary
Fields Modifier and Type Field Description private longfrozenTimestampWhen time is frozen, the timestamp returned bygetCurrentTimeNanos().private longstartTimeWhen time is notfrozen, the base time to subtract fromSystem.nanoTime().private java.util.Queue<java.lang.Runnable>tasksprivate booleantimeFrozenWhether time is currently frozen.
-
Constructor Summary
Constructors Constructor Description EmbeddedEventLoop()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description (package private) voidadvanceTimeBy(long nanos)booleanawaitTermination(long timeout, java.util.concurrent.TimeUnit unit)protected voidcancelScheduledTasks()Cancel all scheduled tasks.voidexecute(java.lang.Runnable command)(package private) voidfreezeTime()protected longgetCurrentTimeNanos()Get the current time in nanoseconds by this executor's clock.(package private) booleanhasPendingNormalTasks()booleaninEventLoop()CallsEventExecutor.inEventLoop(Thread)withThread.currentThread()as argumentbooleaninEventLoop(java.lang.Thread thread)Returntrueif the givenThreadis executed in the event loop,falseotherwise.booleanisShutdown()booleanisShuttingDown()Returnstrueif and only if allEventExecutors managed by thisEventExecutorGroupare being shut down gracefully or was shut down.booleanisTerminated()EventLoopnext()Returns a reference to itself.(package private) longnextScheduledTask()EventLoopGroupparent()Return theEventExecutorGroupwhich is the parent of thisEventExecutor,ChannelFutureregister(Channel channel)ChannelFutureregister(ChannelPromise promise)ChannelFutureregister(Channel channel, ChannelPromise promise)Deprecated.(package private) longrunScheduledTasks()(package private) voidrunTasks()voidshutdown()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 theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave been terminated.(package private) voidunfreezeTime()-
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
-
-
-
-
Field Detail
-
startTime
private long startTime
When 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 frozenTimestamp
When time is frozen, the timestamp returned bygetCurrentTimeNanos(). When unfrozen, this is unused.
-
timeFrozen
private boolean timeFrozen
Whether time is currently frozen.
-
tasks
private final java.util.Queue<java.lang.Runnable> tasks
-
-
Method Detail
-
parent
public EventLoopGroup parent()
Description copied from interface:EventExecutorReturn theEventExecutorGroupwhich is the parent of thisEventExecutor,- Specified by:
parentin interfaceEventExecutor- Specified by:
parentin interfaceEventLoop- Overrides:
parentin classAbstractEventExecutor
-
next
public EventLoop next()
Description copied from interface:EventExecutorReturns a reference to itself.- Specified by:
nextin interfaceEventExecutor- Specified by:
nextin interfaceEventExecutorGroup- Specified by:
nextin interfaceEventLoopGroup- Overrides:
nextin classAbstractEventExecutor
-
execute
public void execute(java.lang.Runnable command)
- Specified by:
executein interfacejava.util.concurrent.Executor
-
runTasks
void runTasks()
-
hasPendingNormalTasks
boolean hasPendingNormalTasks()
-
runScheduledTasks
long runScheduledTasks()
-
nextScheduledTask
long nextScheduledTask()
-
getCurrentTimeNanos
protected long getCurrentTimeNanos()
Description copied from class:AbstractScheduledEventExecutorGet 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:
getCurrentTimeNanosin 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:AbstractScheduledEventExecutorCancel all scheduled tasks. This method MUST be called only whenAbstractEventExecutor.inEventLoop()istrue.- Overrides:
cancelScheduledTasksin classAbstractScheduledEventExecutor
-
shutdownGracefully
public Future<?> shutdownGracefully(long quietPeriod, long timeout, java.util.concurrent.TimeUnit unit)
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()
-
terminationFuture
public Future<?> terminationFuture()
Description copied from interface:EventExecutorGroupReturns theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave been terminated.- Specified by:
terminationFuturein interfaceEventExecutorGroup
-
shutdown
@Deprecated public void shutdown()
Deprecated.- Specified by:
shutdownin interfaceEventExecutorGroup- Specified by:
shutdownin interfacejava.util.concurrent.ExecutorService- Specified by:
shutdownin classAbstractEventExecutor
-
isShuttingDown
public 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 boolean isShutdown()
- Specified by:
isShutdownin interfacejava.util.concurrent.ExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminatedin interfacejava.util.concurrent.ExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)- Specified by:
awaitTerminationin interfacejava.util.concurrent.ExecutorService
-
register
public ChannelFuture register(Channel channel)
Description copied from interface:EventLoopGroupRegister aChannelwith thisEventLoop. The returnedChannelFuturewill get notified once the registration was complete.- Specified by:
registerin interfaceEventLoopGroup
-
register
public ChannelFuture register(ChannelPromise promise)
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
-
register
@Deprecated public 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
-
inEventLoop
public boolean inEventLoop()
Description copied from interface:EventExecutorCallsEventExecutor.inEventLoop(Thread)withThread.currentThread()as argument- Specified by:
inEventLoopin interfaceEventExecutor- Overrides:
inEventLoopin classAbstractEventExecutor
-
inEventLoop
public boolean inEventLoop(java.lang.Thread thread)
Description copied from interface:EventExecutorReturntrueif the givenThreadis executed in the event loop,falseotherwise.- Specified by:
inEventLoopin interfaceEventExecutor
-
-