Class AbstractScheduledEventExecutor

    • Constructor Detail

      • AbstractScheduledEventExecutor

        protected AbstractScheduledEventExecutor()
    • Method Detail

      • nanoTime

        public static long nanoTime()
        The time elapsed since initialization of this class in nanoseconds. This may return a negative number just like System.nanoTime().
      • 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.
      • getCurrentTimeNanos

        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.
      • cancelScheduledTasks

        protected final void cancelScheduledTasks()
        Cancel all scheduled tasks.

        This method MUST be called only when EventExecutor.inEventLoop() is true.

      • nextScheduledTaskNano

        protected final long nextScheduledTaskNano()
        Return the nanoseconds when the next scheduled task is ready to be run or -1 if no task is scheduled.

        This method MUST be called only when EventExecutor.inEventLoop() is true.

      • hasScheduledTasks

        protected final boolean hasScheduledTasks()
        Returns true if a scheduled task is ready for processing.

        This method MUST be called only when EventExecutor.inEventLoop() is true.

      • schedule

        public Future<Void> schedule​(Runnable command,
                                     long delay,
                                     TimeUnit unit)
        Description copied from interface: EventExecutorGroup
        Schedule the given task for execution after the given delay, in the next available EventExecutor in this group, and return a future that produces a null result when the task completes.
        Parameters:
        command - The task that should be executed in this EventExecutorGroup after the given delay.
        delay - A positive time delay, in the given time unit.
        unit - The non-null time unit for the delay.
        Returns:
        A future that represents the completion of the scheduled task.
      • schedule

        public <V> Future<V> schedule​(Callable<V> callable,
                                      long delay,
                                      TimeUnit unit)
        Description copied from interface: EventExecutorGroup
        Schedule the given task for execution after the given delay, in the next available EventExecutor in this group, and return a future that will return the result of the callable when the task completes.
        Type Parameters:
        V - The type of the future result.
        Parameters:
        callable - The task that should be executed in this EventExecutorGroup after the given delay.
        delay - A positive time delay, in the given time unit.
        unit - The non-null time unit for the delay.
        Returns:
        A future that represents the completion of the scheduled task.
      • scheduleAtFixedRate

        public Future<Void> scheduleAtFixedRate​(Runnable command,
                                                long initialDelay,
                                                long period,
                                                TimeUnit unit)
        Description copied from interface: EventExecutorGroup
        Schedule the given task for periodic execution in the next available EventExecutor. The first execution will occur after the given initial delay, and the following repeated executions will occur with the given period of time between each execution is started. If the task takes longer to complete than the requested period, then the following executions will be delayed, rather than allowing multiple instances of the task to run concurrently.

        The task will be executed repeatedly until it either fails with an exception, or its future is cancelled. The future thus will never complete successfully.

        Parameters:
        command - The task that should be scheduled to execute at a fixed rate in this EventExecutorGroup.
        initialDelay - The positive initial delay for the first task execution, in terms of the given time unit.
        period - The positive period for the execution frequency to use after the first execution has started, in terms of the given time unit.
        unit - The non-null time unit for the delay and period.
        Returns:
        A future that represents the recurring task, and which can be cancelled to stop future executions.
      • scheduleWithFixedDelay

        public Future<Void> scheduleWithFixedDelay​(Runnable command,
                                                   long initialDelay,
                                                   long delay,
                                                   TimeUnit unit)
        Description copied from interface: EventExecutorGroup
        Schedule the given task for periodic execution in the next available EventExecutor. The first execution will occur after the given initial delay, and the following repeated executions will occur with the given subsequent delay between one task completing and the next task starting. The delay from the completion of one task, to the start of the next, stays unchanged regardless of how long a task takes to complete.

        This is in contrast to EventExecutorGroup.scheduleAtFixedRate(Runnable, long, long, TimeUnit) which varies the delays between the tasks in order to hit a given frequency.

        The task will be executed repeatedly until it either fails with an exception, or its future is cancelled. The future thus will never complete successfully.

        Parameters:
        command - The task that should be scheduled to execute with fixed delays in this EventExecutorGroup.
        initialDelay - The positive initial delay for the first task execution, in terms of the given time unit.
        delay - The positive subsequent delay between task, to use after the first execution has completed, in terms of the given time unit.
        unit - The non-null time unit for the delays.
        Returns:
        A future that represents the recurring task, and which can be cancelled to stop future executions.
      • newScheduledTaskFor

        protected <V> RunnableScheduledFuture<V> newScheduledTaskFor​(Callable<V> callable,
                                                                     long deadlineNanos,
                                                                     long period)
        Returns a RunnableScheduledFuture for the given values.