Top Description Fields Constructors Methods
io.netty.util.concurrent

public abstract Class AbstractScheduledEventExecutor

extends AbstractEventExecutor
Class Inheritance
Known Direct Subclasses
io.netty.util.concurrent.GlobalEventExecutor, io.netty.util.concurrent.SingleThreadEventExecutor
Imports
io.netty.util.internal.DefaultPriorityQueue, .ObjectUtil, .PriorityQueue, java.util.Comparator, .Queue, java.util.concurrent.Callable, .TimeUnit

Abstract base class for EventExecutors that want to support scheduling.

Field Summary

Modifier and TypeField and Description
pack-priv long
private static final Comparator<ScheduledFutureTask<?>>
pack-priv PriorityQueue<ScheduledFutureTask<?>>
private static final long
pack-priv static final Runnable
Inherited from io.netty.util.concurrent.AbstractEventExecutor:
DEFAULT_SHUTDOWN_QUIET_PERIODDEFAULT_SHUTDOWN_TIMEOUT

Constructor Summary

AccessConstructor and Description
protected
protected

Method Summary

Modifier and TypeMethod and Description
protected boolean

Returns:

true if the EventExecutor thread should be woken, false otherwise
afterScheduledTaskSubmitted
(long deadlineNanos)

See beforeScheduledTaskSubmitted(long).

protected boolean

Returns:

true if the EventExecutor thread should be woken, false otherwise
beforeScheduledTaskSubmitted
(long
deadline of the to-be-scheduled task relative to AbstractScheduledEventExecutor#getCurrentTimeNanos()
deadlineNanos
)

Called from arbitrary non-EventExecutor threads prior to scheduled task submission.

protected void
cancelScheduledTasks()

Cancel all scheduled tasks.

pack-priv static long
deadlineNanos(long nanoTime, long delay)

protected static long

Returns:

the number of nano seconds from now deadlineNanos would expire.
deadlineToDelayNanos
(long
An arbitrary deadline in nano seconds.
deadlineNanos
)

Given an arbitrary deadline deadlineNanos, calculate the number of nano seconds from now deadlineNanos would expire.

pack-priv static long
protected long
getCurrentTimeNanos()

Get the current time in nanoseconds by this executor's clock.

protected final boolean
hasScheduledTasks()

Returns true if a scheduled task is ready for processing.

protected static long

Returns:

initial value used for delay and computations based upon a monatomic time source.
initialNanoTime
()

The initial value used for delay and computations based upon a monatomic time source.

private static boolean
protected static long
nanoTime()

Deprecated Use the non-static getCurrentTimeNanos() instead.
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.

protected final long
nextScheduledTaskNano()

Return the nanoseconds until the next scheduled task is ready to be run or -1 if no task is scheduled.

pack-priv final ScheduledFutureTask<?>
protected final Runnable
protected final Runnable
pollScheduledTask(long nanoTime)

Return the Runnable which is ready to be executed with the given nanoTime.

pack-priv final void
public ScheduledFuture<?>
schedule(Runnable
the task to execute
command
,
long
the time from now to delay execution
delay
,
TimeUnit
the time unit of the delay parameter
unit
)

Overrides io.netty.util.concurrent.AbstractEventExecutor.schedule.

Implements io.netty.util.concurrent.EventExecutorGroup.schedule.

Submits a one-shot task that becomes enabled after the given delay.
public <V> ScheduledFuture<V>
schedule(Callable<V>
the function to execute
callable
,
long
the time from now to delay execution
delay
,
TimeUnit
the time unit of the delay parameter
unit
)

Overrides io.netty.util.concurrent.AbstractEventExecutor.schedule.

Implements io.netty.util.concurrent.EventExecutorGroup.schedule.

Submits a value-returning one-shot task that becomes enabled after the given delay.
private <V> ScheduledFuture<V>
public ScheduledFuture<?>
scheduleAtFixedRate(Runnable
the task to execute
command
,
long
the time to delay first execution
initialDelay
,
long
the period between successive executions
period
,
TimeUnit
the time unit of the initialDelay and period parameters
unit
)

Overrides io.netty.util.concurrent.AbstractEventExecutor.scheduleAtFixedRate.

Implements io.netty.util.concurrent.EventExecutorGroup.scheduleAtFixedRate.

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is, executions will commence after initialDelay, then initialDelay + period, then initialDelay + 2 * period, and so on.
pack-priv PriorityQueue<ScheduledFutureTask<?>>
pack-priv final void
public ScheduledFuture<?>
scheduleWithFixedDelay(Runnable
the task to execute
command
,
long
the time to delay first execution
initialDelay
,
long
the delay between the termination of one execution and the commencement of the next
delay
,
TimeUnit
the time unit of the initialDelay and delay parameters
unit
)

Overrides io.netty.util.concurrent.AbstractEventExecutor.scheduleWithFixedDelay.

Implements io.netty.util.concurrent.EventExecutorGroup.scheduleWithFixedDelay.

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.
protected void
validateScheduled(long amount, 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.
private void
validateScheduled0(long amount, TimeUnit unit)

Inherited from io.netty.util.concurrent.AbstractEventExecutor:
inEventLoopiteratorlazyExecutenewFailedFuturenewProgressivePromisenewPromisenewSucceededFuturenewTaskFornewTaskFornextparentrunTasksafeExecuteshutdownshutdownGracefullyshutdownNowsubmitsubmitsubmit

Field Detail

nextTaskIdback to summary
pack-priv long nextTaskId
SCHEDULED_FUTURE_TASK_COMPARATORback to summary
private static final Comparator<ScheduledFutureTask<?>> SCHEDULED_FUTURE_TASK_COMPARATOR
scheduledTaskQueueback to summary
pack-priv PriorityQueue<ScheduledFutureTask<?>> scheduledTaskQueue
START_TIMEback to summary
private static final long START_TIME
WAKEUP_TASKback to summary
pack-priv static final Runnable WAKEUP_TASK

Constructor Detail

AbstractScheduledEventExecutorback to summary
protected AbstractScheduledEventExecutor()
AbstractScheduledEventExecutorback to summary
protected AbstractScheduledEventExecutor(EventExecutorGroup parent)

Method Detail

afterScheduledTaskSubmittedback to summary
protected boolean afterScheduledTaskSubmitted(long deadlineNanos)

See beforeScheduledTaskSubmitted(long). Called only after that method returns false.

Parameters
deadlineNanos:long

relative to AbstractScheduledEventExecutor#getCurrentTimeNanos()

Returns:boolean

true if the EventExecutor thread should be woken, false otherwise

beforeScheduledTaskSubmittedback to summary
protected boolean beforeScheduledTaskSubmitted(long deadlineNanos)

Called from arbitrary non-EventExecutor threads prior to scheduled task submission. Returns true if the EventExecutor 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 the EventExecutor thread if required.

Parameters
deadlineNanos:long

deadline of the to-be-scheduled task relative to AbstractScheduledEventExecutor#getCurrentTimeNanos()

Returns:boolean

true if the EventExecutor thread should be woken, false otherwise

cancelScheduledTasksback to summary
protected void cancelScheduledTasks()

Cancel all scheduled tasks. This method MUST be called only when inEventLoop() is true.

deadlineNanosback to summary
pack-priv static long deadlineNanos(long nanoTime, long delay)
deadlineToDelayNanosback to summary
protected static long deadlineToDelayNanos(long deadlineNanos)

Given an arbitrary deadline deadlineNanos, calculate the number of nano seconds from now deadlineNanos would expire.

Parameters
deadlineNanos:long

An arbitrary deadline in nano seconds.

Returns:long

the number of nano seconds from now deadlineNanos would expire.

defaultCurrentTimeNanosback to summary
pack-priv static long defaultCurrentTimeNanos()
getCurrentTimeNanosback to summary
protected long getCurrentTimeNanos()

Get the current time in nanoseconds by this executor's clock. This is not the same as System#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.
hasScheduledTasksback to summary
protected final boolean hasScheduledTasks()

Returns true if a scheduled task is ready for processing.

initialNanoTimeback to summary
protected static long initialNanoTime()

The initial value used for delay and computations based upon a monatomic time source.

Returns:long

initial value used for delay and computations based upon a monatomic time source.

isNullOrEmptyback to summary
private static boolean isNullOrEmpty(Queue<ScheduledFutureTask<?>> queue)
nanoTimeback to summary
protected static long nanoTime()

Deprecated

Use the non-static getCurrentTimeNanos() instead.

Annotations
@Deprecated
nextScheduledTaskDeadlineNanosback to summary
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.

nextScheduledTaskNanoback to summary
protected final long nextScheduledTaskNano()

Return the nanoseconds until the next scheduled task is ready to be run or -1 if no task is scheduled.

peekScheduledTaskback to summary
pack-priv final ScheduledFutureTask<?> peekScheduledTask()
pollScheduledTaskback to summary
protected final Runnable pollScheduledTask()
See Also
pollScheduledTask(long)
pollScheduledTaskback to summary
protected final Runnable pollScheduledTask(long nanoTime)

Return the Runnable which is ready to be executed with the given nanoTime. You should use getCurrentTimeNanos() to retrieve the correct nanoTime.

removeScheduledback to summary
pack-priv final void removeScheduled(final ScheduledFutureTask<?> task)
scheduleback to summary
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)

Overrides io.netty.util.concurrent.AbstractEventExecutor.schedule.

Implements io.netty.util.concurrent.EventExecutorGroup.schedule.

Doc from java.util.concurrent.ScheduledExecutorService.schedule.

Submits a one-shot task that becomes enabled after the given delay.

Parameters
command:Runnable

the task to execute

delay:long

the time from now to delay execution

unit:TimeUnit

the time unit of the delay parameter

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the task and whose get() method will return null upon completion

Annotations
@Override
scheduleback to summary
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit)

Overrides io.netty.util.concurrent.AbstractEventExecutor.schedule.

Implements io.netty.util.concurrent.EventExecutorGroup.schedule.

Doc from java.util.concurrent.ScheduledExecutorService.schedule.

Submits a value-returning one-shot task that becomes enabled after the given delay.

Parameters
<V>
the type of the callable's result
callable:Callable<V>

the function to execute

delay:long

the time from now to delay execution

unit:TimeUnit

the time unit of the delay parameter

Returns:ScheduledFuture<V>

a ScheduledFuture that can be used to extract result or cancel

Annotations
@Override
scheduleback to summary
private <V> ScheduledFuture<V> schedule(final ScheduledFutureTask<V> task)
scheduleAtFixedRateback to summary
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)

Overrides io.netty.util.concurrent.AbstractEventExecutor.scheduleAtFixedRate.

Implements io.netty.util.concurrent.EventExecutorGroup.scheduleAtFixedRate.

Doc from java.util.concurrent.ScheduledExecutorService.scheduleAtFixedRate.

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is, executions will commence after initialDelay, then initialDelay + period, then initialDelay + 2 * period, and so on.

The sequence of task executions continues indefinitely until one of the following exceptional completions occur:

  • The task is explicitly cancelled via the returned future.
  • The executor terminates, also resulting in task cancellation.
  • An execution of the task throws an exception. In this case calling get on the returned future will throw ExecutionException, holding the exception as its cause.
Subsequent executions are suppressed. Subsequent calls to isDone() on the returned future will return true.

If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.

Parameters
command:Runnable

the task to execute

initialDelay:long

the time to delay first execution

period:long

the period between successive executions

unit:TimeUnit

the time unit of the initialDelay and period parameters

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the series of repeated tasks. The future's get() method will never return normally, and will throw an exception upon task cancellation or abnormal termination of a task execution.

Annotations
@Override
scheduledTaskQueueback to summary
pack-priv PriorityQueue<ScheduledFutureTask<?>> scheduledTaskQueue()
scheduleFromEventLoopback to summary
pack-priv final void scheduleFromEventLoop(final ScheduledFutureTask<?> task)
scheduleWithFixedDelayback to summary
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)

Overrides io.netty.util.concurrent.AbstractEventExecutor.scheduleWithFixedDelay.

Implements io.netty.util.concurrent.EventExecutorGroup.scheduleWithFixedDelay.

Doc from java.util.concurrent.ScheduledExecutorService.scheduleWithFixedDelay.

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.

The sequence of task executions continues indefinitely until one of the following exceptional completions occur:

  • The task is explicitly cancelled via the returned future.
  • The executor terminates, also resulting in task cancellation.
  • An execution of the task throws an exception. In this case calling get on the returned future will throw ExecutionException, holding the exception as its cause.
Subsequent executions are suppressed. Subsequent calls to isDone() on the returned future will return true.
Parameters
command:Runnable

the task to execute

initialDelay:long

the time to delay first execution

delay:long

the delay between the termination of one execution and the commencement of the next

unit:TimeUnit

the time unit of the initialDelay and delay parameters

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the series of repeated tasks. The future's get() method will never return normally, and will throw an exception upon task cancellation or abnormal termination of a task execution.

Annotations
@Override
validateScheduledback to summary
protected void validateScheduled(long amount, 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.

Annotations
@Deprecated
validateScheduled0back to summary
private void validateScheduled0(long amount, TimeUnit unit)
Annotations
@SuppressWarnings:deprecation