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,ThreadAwareExecutor,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 Modifier and Type Class Description (package private) static classEmbeddedEventLoop.FreezableTickerTicker that implements the oldEmbeddedChanneltime freezing mechanics.-
Nested classes/interfaces inherited from class io.netty.util.concurrent.AbstractEventExecutor
AbstractEventExecutor.LazyRunnable
-
-
Constructor Summary
Constructors Constructor Description EmbeddedEventLoop(Ticker ticker)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanawaitTermination(long timeout, java.util.concurrent.TimeUnit unit)protected voidcancelScheduledTasks()Cancel all scheduled tasks.voidexecute(java.lang.Runnable command)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 one of theEventExecutors managed by thisEventExecutorGroup.(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.Tickerticker()The ticker for this executor.-
Methods inherited from class io.netty.util.concurrent.AbstractScheduledEventExecutor
afterScheduledTaskSubmitted, beforeScheduledTaskSubmitted, deadlineToDelayNanos, delayNanos, fetchFromScheduledTaskQueue, 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.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
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
-
-
-
-
Field Detail
-
ticker
private final Ticker ticker
-
tasks
private final java.util.Queue<java.lang.Runnable> tasks
-
-
Constructor Detail
-
EmbeddedEventLoop
EmbeddedEventLoop(Ticker ticker)
-
-
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:EventExecutorGroupReturns one of theEventExecutors managed by thisEventExecutorGroup.- 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()
-
ticker
public Ticker ticker()
Description copied from interface:EventExecutorGroupThe ticker for this executor. Usually theEventExecutorGroup.schedule(java.lang.Runnable, long, java.util.concurrent.TimeUnit)methods will follow thesystem ticker(i.e.System.nanoTime()), but especially for testing it is sometimes useful to have more control over the ticker. In that case, this method will be overridden. Code that schedules tasks on this executor should use this ticker in order to stay consistent with the executor (e.g. not be surprised by scheduled tasks running "early").- Specified by:
tickerin interfaceEventExecutorGroup- Overrides:
tickerin classAbstractScheduledEventExecutor- Returns:
- The ticker for this scheduler
-
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
-
cancelScheduledTasks
protected void cancelScheduledTasks()
Description copied from class:AbstractScheduledEventExecutorCancel all scheduled tasks. This method MUST be called only whenEventExecutor.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
-
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
-
-