Package io.netty.util.concurrent
Class AbstractScheduledEventExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- io.netty.util.concurrent.AbstractEventExecutor
-
- io.netty.util.concurrent.AbstractScheduledEventExecutor
-
- All Implemented Interfaces:
EventExecutor,EventExecutorGroup,java.lang.Iterable<EventExecutor>,java.util.concurrent.Executor,java.util.concurrent.ExecutorService,java.util.concurrent.ScheduledExecutorService
- Direct Known Subclasses:
EmbeddedEventLoop,GlobalEventExecutor,SingleThreadEventExecutor
public abstract class AbstractScheduledEventExecutor extends AbstractEventExecutor
Abstract base class forEventExecutors that want to support scheduling.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty.util.concurrent.AbstractEventExecutor
AbstractEventExecutor.LazyRunnable
-
-
Field Summary
Fields Modifier and Type Field Description (package private) longnextTaskIdprivate static java.util.Comparator<ScheduledFutureTask<?>>SCHEDULED_FUTURE_TASK_COMPARATOR(package private) PriorityQueue<ScheduledFutureTask<?>>scheduledTaskQueue(package private) static java.lang.RunnableWAKEUP_TASK-
Fields inherited from class io.netty.util.concurrent.AbstractEventExecutor
DEFAULT_SHUTDOWN_QUIET_PERIOD, DEFAULT_SHUTDOWN_TIMEOUT
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractScheduledEventExecutor()protectedAbstractScheduledEventExecutor(EventExecutorGroup parent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected booleanafterScheduledTaskSubmitted(long deadlineNanos)protected booleanbeforeScheduledTaskSubmitted(long deadlineNanos)Called from arbitrary non-EventExecutorthreads prior to scheduled task submission.protected voidcancelScheduledTasks()Cancel all scheduled tasks.protected static longdeadlineToDelayNanos(long deadlineNanos)Given an arbitrary deadlinedeadlineNanos, calculate the number of nano seconds from nowdeadlineNanoswould expire.protected booleanhasScheduledTasks()Returnstrueif a scheduled task is ready for processing.protected static longinitialNanoTime()The initial value used for delay and computations based upon a monatomic time source.private static booleanisNullOrEmpty(java.util.Queue<ScheduledFutureTask<?>> queue)protected static longnanoTime()protected longnextScheduledTaskDeadlineNanos()Return the deadline (in nanoseconds) when the next scheduled task is ready to be run or-1if no task is scheduled.protected longnextScheduledTaskNano()Return the nanoseconds until the next scheduled task is ready to be run or-1if no task is scheduled.(package private) ScheduledFutureTask<?>peekScheduledTask()protected java.lang.RunnablepollScheduledTask()protected java.lang.RunnablepollScheduledTask(long nanoTime)Return theRunnablewhich is ready to be executed with the givennanoTime.(package private) voidremoveScheduled(ScheduledFutureTask<?> task)private <V> ScheduledFuture<V>schedule(ScheduledFutureTask<V> task)ScheduledFuture<?>schedule(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)<V> ScheduledFuture<V>schedule(java.util.concurrent.Callable<V> callable, long delay, java.util.concurrent.TimeUnit unit)ScheduledFuture<?>scheduleAtFixedRate(java.lang.Runnable command, long initialDelay, long period, java.util.concurrent.TimeUnit unit)(package private) PriorityQueue<ScheduledFutureTask<?>>scheduledTaskQueue()(package private) voidscheduleFromEventLoop(ScheduledFutureTask<?> task)ScheduledFuture<?>scheduleWithFixedDelay(java.lang.Runnable command, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)protected voidvalidateScheduled(long amount, java.util.concurrent.TimeUnit unit)Deprecated.will be removed in the future.private voidvalidateScheduled0(long amount, java.util.concurrent.TimeUnit unit)-
Methods inherited from class io.netty.util.concurrent.AbstractEventExecutor
inEventLoop, iterator, lazyExecute, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, next, parent, safeExecute, shutdown, 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
inEventLoop
-
Methods inherited from interface io.netty.util.concurrent.EventExecutorGroup
isShuttingDown, shutdownGracefully, terminationFuture
-
-
-
-
Field Detail
-
SCHEDULED_FUTURE_TASK_COMPARATOR
private static final java.util.Comparator<ScheduledFutureTask<?>> SCHEDULED_FUTURE_TASK_COMPARATOR
-
WAKEUP_TASK
static final java.lang.Runnable WAKEUP_TASK
-
scheduledTaskQueue
PriorityQueue<ScheduledFutureTask<?>> scheduledTaskQueue
-
nextTaskId
long nextTaskId
-
-
Constructor Detail
-
AbstractScheduledEventExecutor
protected AbstractScheduledEventExecutor()
-
AbstractScheduledEventExecutor
protected AbstractScheduledEventExecutor(EventExecutorGroup parent)
-
-
Method Detail
-
nanoTime
protected static long nanoTime()
-
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.
-
scheduledTaskQueue
PriorityQueue<ScheduledFutureTask<?>> scheduledTaskQueue()
-
isNullOrEmpty
private static boolean isNullOrEmpty(java.util.Queue<ScheduledFutureTask<?>> queue)
-
cancelScheduledTasks
protected void cancelScheduledTasks()
Cancel all scheduled tasks. This method MUST be called only whenAbstractEventExecutor.inEventLoop()istrue.
-
pollScheduledTask
protected final java.lang.Runnable pollScheduledTask()
- See Also:
pollScheduledTask(long)
-
pollScheduledTask
protected final java.lang.Runnable pollScheduledTask(long nanoTime)
Return theRunnablewhich is ready to be executed with the givennanoTime. You should usenanoTime()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.
-
peekScheduledTask
final ScheduledFutureTask<?> peekScheduledTask()
-
hasScheduledTasks
protected final boolean hasScheduledTasks()
Returnstrueif a scheduled task is ready for processing.
-
schedule
public ScheduledFuture<?> schedule(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)
- Specified by:
schedulein interfaceEventExecutorGroup- Specified by:
schedulein interfacejava.util.concurrent.ScheduledExecutorService- Overrides:
schedulein classAbstractEventExecutor
-
schedule
public <V> ScheduledFuture<V> schedule(java.util.concurrent.Callable<V> callable, long delay, java.util.concurrent.TimeUnit unit)
- Specified by:
schedulein interfaceEventExecutorGroup- Specified by:
schedulein interfacejava.util.concurrent.ScheduledExecutorService- Overrides:
schedulein classAbstractEventExecutor
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable command, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
- Specified by:
scheduleAtFixedRatein interfaceEventExecutorGroup- Specified by:
scheduleAtFixedRatein interfacejava.util.concurrent.ScheduledExecutorService- Overrides:
scheduleAtFixedRatein classAbstractEventExecutor
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable command, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)
- Specified by:
scheduleWithFixedDelayin interfaceEventExecutorGroup- Specified by:
scheduleWithFixedDelayin interfacejava.util.concurrent.ScheduledExecutorService- Overrides:
scheduleWithFixedDelayin classAbstractEventExecutor
-
validateScheduled0
private void validateScheduled0(long amount, java.util.concurrent.TimeUnit unit)
-
validateScheduled
@Deprecated protected void validateScheduled(long amount, java.util.concurrent.TimeUnit unit)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.
-
scheduleFromEventLoop
final void scheduleFromEventLoop(ScheduledFutureTask<?> task)
-
schedule
private <V> ScheduledFuture<V> schedule(ScheduledFutureTask<V> task)
-
removeScheduled
final void removeScheduled(ScheduledFutureTask<?> 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 tonanoTime()- 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 tonanoTime()- Returns:
trueif theEventExecutorthread should be woken,falseotherwise
-
-