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
,AutoCloseable
,Iterable<EventExecutor>
,Executor
,ExecutorService
,ScheduledExecutorService
- Direct Known Subclasses:
EmbeddedEventLoop
,GlobalEventExecutor
,SingleThreadEventExecutor
Abstract base class for
EventExecutor
s that want to support scheduling.-
Nested Class Summary
Nested classes/interfaces inherited from class io.netty.util.concurrent.AbstractEventExecutor
AbstractEventExecutor.LazyRunnable
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) long
private static final Comparator
<ScheduledFutureTask<?>> (package private) PriorityQueue
<ScheduledFutureTask<?>> private static final long
(package private) static final Runnable
Fields inherited from class io.netty.util.concurrent.AbstractEventExecutor
DEFAULT_SHUTDOWN_QUIET_PERIOD, DEFAULT_SHUTDOWN_TIMEOUT
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
protected
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
afterScheduledTaskSubmitted
(long deadlineNanos) protected boolean
beforeScheduledTaskSubmitted
(long deadlineNanos) Called from arbitrary non-EventExecutor
threads prior to scheduled task submission.protected void
Cancel all scheduled tasks.(package private) static long
deadlineNanos
(long nanoTime, long delay) protected static long
deadlineToDelayNanos
(long deadlineNanos) Given an arbitrary deadlinedeadlineNanos
, calculate the number of nano seconds from nowdeadlineNanos
would expire.(package private) static long
protected long
Get the current time in nanoseconds by this executor's clock.protected final boolean
Returnstrue
if a scheduled task is ready for processing.protected static long
The initial value used for delay and computations based upon a monatomic time source.private static boolean
isNullOrEmpty
(Queue<ScheduledFutureTask<?>> queue) protected static long
nanoTime()
Deprecated.protected final long
Return the deadline (in nanoseconds) when the next scheduled task is ready to be run or-1
if no task is scheduled.protected final long
Return the nanoseconds until the next scheduled task is ready to be run or-1
if no task is scheduled.(package private) final ScheduledFutureTask
<?> protected final Runnable
protected final Runnable
pollScheduledTask
(long nanoTime) Return theRunnable
which is ready to be executed with the givennanoTime
.(package private) final void
removeScheduled
(ScheduledFutureTask<?> task) private <V> ScheduledFuture
<V> schedule
(ScheduledFutureTask<V> task) <V> ScheduledFuture
<V> scheduleAtFixedRate
(Runnable command, long initialDelay, long period, TimeUnit unit) (package private) PriorityQueue
<ScheduledFutureTask<?>> (package private) final void
scheduleFromEventLoop
(ScheduledFutureTask<?> task) scheduleWithFixedDelay
(Runnable command, long initialDelay, long delay, TimeUnit unit) protected void
validateScheduled
(long amount, TimeUnit unit) Deprecated.will be removed in the future.private void
validateScheduled0
(long amount, TimeUnit unit) Methods inherited from class io.netty.util.concurrent.AbstractEventExecutor
inEventLoop, iterator, lazyExecute, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, next, parent, runTask, 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
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, close, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
SCHEDULED_FUTURE_TASK_COMPARATOR
-
START_TIME
private static final long START_TIME -
WAKEUP_TASK
-
scheduledTaskQueue
PriorityQueue<ScheduledFutureTask<?>> scheduledTaskQueue -
nextTaskId
long nextTaskId
-
-
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. -
defaultCurrentTimeNanos
static long defaultCurrentTimeNanos() -
deadlineNanos
static long deadlineNanos(long nanoTime, long delay) -
deadlineToDelayNanos
protected static long deadlineToDelayNanos(long deadlineNanos) Given an arbitrary deadlinedeadlineNanos
, calculate the number of nano seconds from nowdeadlineNanos
would expire.- Parameters:
deadlineNanos
- An arbitrary deadline in nano seconds.- Returns:
- the number of nano seconds from now
deadlineNanos
would 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
-
cancelScheduledTasks
protected void cancelScheduledTasks()Cancel all scheduled tasks. This method MUST be called only whenAbstractEventExecutor.inEventLoop()
istrue
. -
pollScheduledTask
- See Also:
-
pollScheduledTask
Return theRunnable
which 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-1
if 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-1
if no task is scheduled. -
peekScheduledTask
-
hasScheduledTasks
protected final boolean hasScheduledTasks()Returnstrue
if a scheduled task is ready for processing. -
schedule
- Specified by:
schedule
in interfaceEventExecutorGroup
- Specified by:
schedule
in interfaceScheduledExecutorService
- Overrides:
schedule
in classAbstractEventExecutor
-
schedule
- Specified by:
schedule
in interfaceEventExecutorGroup
- Specified by:
schedule
in interfaceScheduledExecutorService
- Overrides:
schedule
in classAbstractEventExecutor
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) - Specified by:
scheduleAtFixedRate
in interfaceEventExecutorGroup
- Specified by:
scheduleAtFixedRate
in interfaceScheduledExecutorService
- Overrides:
scheduleAtFixedRate
in classAbstractEventExecutor
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) - Specified by:
scheduleWithFixedDelay
in interfaceEventExecutorGroup
- Specified by:
scheduleWithFixedDelay
in interfaceScheduledExecutorService
- Overrides:
scheduleWithFixedDelay
in classAbstractEventExecutor
-
validateScheduled0
-
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. -
scheduleFromEventLoop
-
schedule
-
removeScheduled
-
beforeScheduledTaskSubmitted
protected boolean beforeScheduledTaskSubmitted(long deadlineNanos) Called from arbitrary non-EventExecutor
threads prior to scheduled task submission. Returnstrue
if theEventExecutor
thread should be woken immediately to process the scheduled task (if not already awake).If
false
is returned,afterScheduledTaskSubmitted(long)
will be called with the same value after the scheduled task is enqueued, providing another opportunity to wake theEventExecutor
thread if required.- Parameters:
deadlineNanos
- deadline of the to-be-scheduled task relative togetCurrentTimeNanos()
- Returns:
true
if theEventExecutor
thread should be woken,false
otherwise
-
afterScheduledTaskSubmitted
protected boolean afterScheduledTaskSubmitted(long deadlineNanos) SeebeforeScheduledTaskSubmitted(long)
. Called only after that method returns false.- Parameters:
deadlineNanos
- relative togetCurrentTimeNanos()
- Returns:
true
if theEventExecutor
thread should be woken,false
otherwise
-
getCurrentTimeNanos()
instead.