Class AbstractScheduledEventExecutor
java.lang.Object
java.util.concurrent.AbstractExecutorService
io.netty.util.concurrent.AbstractEventExecutor
io.netty.util.concurrent.AbstractScheduledEventExecutor
- All Implemented Interfaces:
EventExecutor, EventExecutorGroup, Iterable<EventExecutor>, Executor, ExecutorService, ScheduledExecutorService
- Direct Known Subclasses:
GlobalEventExecutor, SingleThreadEventExecutor
Abstract base class for
EventExecutors that want to support scheduling.-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractEventExecutor
AbstractEventExecutor.LazyRunnable -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotected -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanafterScheduledTaskSubmitted(long deadlineNanos) protected booleanbeforeScheduledTaskSubmitted(long deadlineNanos) Called from arbitrary non-EventExecutorthreads prior to scheduled task submission.protected voidCancel all scheduled tasks.protected static longdeadlineToDelayNanos(long deadlineNanos) Given an arbitrary deadlinedeadlineNanos, calculate the number of nano seconds from nowdeadlineNanoswould expire.protected longGet the current time in nanoseconds by this executor's clock.protected final booleanReturnstrueif a scheduled task is ready for processing.protected static longThe initial value used for delay and computations based upon a monatomic time source.protected static longnanoTime()Deprecated.Use the non-staticgetCurrentTimeNanos()instead.protected final longReturn the deadline (in nanoseconds) when the next scheduled task is ready to be run or-1if no task is scheduled.protected final longReturn the nanoseconds until the next scheduled task is ready to be run or-1if no task is scheduled.protected final Runnableprotected final RunnablepollScheduledTask(long nanoTime) Return theRunnablewhich is ready to be executed with the givennanoTime.<V> ScheduledFuture<V> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) protected voidvalidateScheduled(long amount, TimeUnit unit) Deprecated.will be removed in the future.Methods inherited from class AbstractEventExecutor
inEventLoop, iterator, lazyExecute, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, next, parent, runTask, safeExecute, shutdown, shutdownGracefully, shutdownNow, submit, submit, submitModifier and TypeMethodDescriptionbooleanCallsEventExecutor.inEventLoop(Thread)withThread.currentThread()as argumentiterator()voidlazyExecute(Runnable task) LikeExecutor.execute(Runnable)but does not guarantee the task will be run until either a non-lazy task is executed or the executor is shut down.<V> Future<V> newFailedFuture(Throwable cause) Create a newFuturewhich is marked as failed already.<V> ProgressivePromise<V> Create a newProgressivePromise.<V> Promise<V> Return a newPromise.<V> Future<V> newSucceededFuture(V result) Create a newFuturewhich is marked as succeeded already.protected final <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) protected final <T> RunnableFuture<T> newTaskFor(Callable<T> callable) next()Returns a reference to itself.parent()Return theEventExecutorGroupwhich is the parent of thisEventExecutor,protected static voidprotected static voidsafeExecute(Runnable task) abstract voidshutdown()Future<?> Shortcut method forEventExecutorGroup.shutdownGracefully(long, long, TimeUnit)with sensible default values.Future<?> <T> Future<T> <T> Future<T> Methods inherited from class AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAnyMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EventExecutor
inEventLoopMethods inherited from interface EventExecutorGroup
isShuttingDown, shutdownGracefully, terminationFutureModifier and TypeMethodDescriptionbooleanReturnstrueif and only if allEventExecutors managed by thisEventExecutorGroupare being shut down gracefully or was shut down.Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit) Signals this executor that the caller wants the executor to be shut down.Future<?> Returns theFuturewhich is notified when allEventExecutors managed by thisEventExecutorGrouphave been terminated.Methods inherited from interface ExecutorService
awaitTermination, isShutdown, isTerminatedMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
AbstractScheduledEventExecutor
protected AbstractScheduledEventExecutor() -
AbstractScheduledEventExecutor
-
-
Method Details
-
getCurrentTimeNanos
protected long getCurrentTimeNanos()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.
- We apply a fixed offset to the
-
nanoTime
Deprecated.Use the non-staticgetCurrentTimeNanos()instead. -
deadlineToDelayNanos
protected static long deadlineToDelayNanos(long deadlineNanos) Given an arbitrary deadlinedeadlineNanos, calculate the number of nano seconds from nowdeadlineNanoswould expire.- Parameters:
deadlineNanos- An arbitrary deadline in nano seconds.- Returns:
- the number of nano seconds from now
deadlineNanoswould expire.
-
initialNanoTime
protected static long initialNanoTime()The initial value used for delay and computations based upon a monatomic time source.- Returns:
- initial value used for delay and computations based upon a monatomic time source.
-
cancelScheduledTasks
protected void cancelScheduledTasks()Cancel all scheduled tasks. This method MUST be called only whenAbstractEventExecutor.inEventLoop()istrue. -
pollScheduledTask
- See Also:
-
pollScheduledTask
Return theRunnablewhich is ready to be executed with the givennanoTime. You should usegetCurrentTimeNanos()to retrieve the correctnanoTime. -
nextScheduledTaskNano
protected final long nextScheduledTaskNano()Return the nanoseconds until the next scheduled task is ready to be run or-1if no task is scheduled. -
nextScheduledTaskDeadlineNanos
protected final long nextScheduledTaskDeadlineNanos()Return the deadline (in nanoseconds) when the next scheduled task is ready to be run or-1if no task is scheduled. -
hasScheduledTasks
protected final boolean hasScheduledTasks()Returnstrueif a scheduled task is ready for processing. -
schedule
- Specified by:
schedulein interfaceEventExecutorGroup- Specified by:
schedulein interfaceScheduledExecutorService- Overrides:
schedulein classAbstractEventExecutor
-
schedule
- Specified by:
schedulein interfaceEventExecutorGroup- Specified by:
schedulein interfaceScheduledExecutorService- Overrides:
schedulein classAbstractEventExecutor
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) - Specified by:
scheduleAtFixedRatein interfaceEventExecutorGroup- Specified by:
scheduleAtFixedRatein interfaceScheduledExecutorService- Overrides:
scheduleAtFixedRatein classAbstractEventExecutor
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) - Specified by:
scheduleWithFixedDelayin interfaceEventExecutorGroup- Specified by:
scheduleWithFixedDelayin interfaceScheduledExecutorService- Overrides:
scheduleWithFixedDelayin classAbstractEventExecutor
-
validateScheduled
Deprecated.will be removed in the future.Sub-classes may override this to restrict the maximal amount of time someone can use to schedule a task. -
beforeScheduledTaskSubmitted
protected boolean beforeScheduledTaskSubmitted(long deadlineNanos) Called from arbitrary non-EventExecutorthreads prior to scheduled task submission. Returnstrueif theEventExecutorthread should be woken immediately to process the scheduled task (if not already awake).If
falseis returned,afterScheduledTaskSubmitted(long)will be called with the same value after the scheduled task is enqueued, providing another opportunity to wake theEventExecutorthread if required.- Parameters:
deadlineNanos- deadline of the to-be-scheduled task relative togetCurrentTimeNanos()- Returns:
trueif theEventExecutorthread should be woken,falseotherwise
-
afterScheduledTaskSubmitted
protected boolean afterScheduledTaskSubmitted(long deadlineNanos) SeebeforeScheduledTaskSubmitted(long). Called only after that method returns false.- Parameters:
deadlineNanos- relative togetCurrentTimeNanos()- Returns:
trueif theEventExecutorthread should be woken,falseotherwise
-
SingleThreadEventExecutor.wakesUpForTask(Runnable)to re-create this behaviour