Class AbstractScheduledEventExecutor

    • Constructor Detail

      • AbstractScheduledEventExecutor

        protected AbstractScheduledEventExecutor()
      • AbstractScheduledEventExecutor

        protected AbstractScheduledEventExecutor​(EventExecutorGroup parent)
    • Method Detail

      • ticker

        public Ticker ticker()
        Description copied from interface: EventExecutorGroup
        The ticker for this executor. Usually the EventExecutorGroup.schedule(java.lang.Runnable, long, java.util.concurrent.TimeUnit) methods will follow the system ticker (i.e. System.nanoTime()), but especially for testing it is sometimes useful to have more control over the ticker. In that case, this method will be overridden. Code that schedules tasks on this executor should use this ticker in order to stay consistent with the executor (e.g. not be surprised by scheduled tasks running "early").
        Returns:
        The ticker for this scheduler
      • getCurrentTimeNanos

        @Deprecated
        protected long getCurrentTimeNanos()
        Deprecated.
        Please use (or override) ticker() instead. This method delegates to ticker(). Old code may still call this method for compatibility.
        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 ticker() instead.
      • deadlineToDelayNanos

        @Deprecated
        protected static long deadlineToDelayNanos​(long deadlineNanos)
        Deprecated.
        Use ticker() instead
        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

        @Deprecated
        protected static long initialNanoTime()
        Deprecated.
        Use ticker() instead
        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