Class AbstractScheduledEventExecutor

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

        protected long delayNanos​(long currentTimeNanos,
                                  long scheduledPurgeInterval)
        Returns the amount of time left until the scheduled task with the closest dead line is executed.
      • 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.
      • cancelScheduledTasks

        protected void cancelScheduledTasks()
        Cancel all scheduled tasks. This method MUST be called only when EventExecutor.inEventLoop() is true.
      • fetchFromScheduledTaskQueue

        protected boolean fetchFromScheduledTaskQueue​(java.util.Queue<java.lang.Runnable> taskQueue)
        Fetch scheduled tasks from the internal queue and add these to the given Queue.
        Parameters:
        taskQueue - the task queue into which the fetched scheduled tasks should be transferred.
        Returns:
        true if we were able to transfer everything, false if we need to call this method again as soon as there is space again in taskQueue.
      • 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.
      • 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