Class AbstractScheduledEventExecutor

    • Field Detail

      • SCHEDULED_FUTURE_TASK_COMPARATOR

        private static final java.util.Comparator<ScheduledFutureTask<?>> SCHEDULED_FUTURE_TASK_COMPARATOR
      • START_TIME

        private static final long START_TIME
      • WAKEUP_TASK

        static final java.lang.Runnable WAKEUP_TASK
      • nextTaskId

        long nextTaskId
    • Constructor Detail

      • AbstractScheduledEventExecutor

        protected AbstractScheduledEventExecutor()
      • AbstractScheduledEventExecutor

        protected AbstractScheduledEventExecutor​(EventExecutorGroup parent)
    • Method Detail

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

        @Deprecated
        protected static long nanoTime()
        Deprecated.
        Use the non-static getCurrentTimeNanos() instead.
      • defaultCurrentTimeNanos

        static long defaultCurrentTimeNanos()
      • deadlineNanos

        static long deadlineNanos​(long nanoTime,
                                  long delay)
      • deadlineToDelayNanos

        protected static long deadlineToDelayNanos​(long deadlineNanos)
        Given an arbitrary deadline deadlineNanos, calculate the number of nano seconds from now deadlineNanos 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.
      • isNullOrEmpty

        private static boolean isNullOrEmpty​(java.util.Queue<ScheduledFutureTask<?>> queue)
      • pollScheduledTask

        protected final java.lang.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.
      • 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.
      • hasScheduledTasks

        protected final boolean hasScheduledTasks()
        Returns true if a scheduled task is ready for processing.
      • 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.
      • beforeScheduledTaskSubmitted

        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 - deadline of the to-be-scheduled task relative to getCurrentTimeNanos()
        Returns:
        true if the EventExecutor thread should be woken, false otherwise