Class AbstractScheduledService.CustomScheduler.ReschedulableCallable

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.Future<java.lang.Void> currentFuture
      The future that represents the next execution of this task.
      private java.util.concurrent.ScheduledExecutorService executor
      The executor on which this Callable will be scheduled.
      private java.util.concurrent.locks.ReentrantLock lock
      This lock is used to ensure safe and correct cancellation, it ensures that a new task is not scheduled while a cancel is ongoing.
      private AbstractService service
      The service that is managing this callable.
      private java.lang.Runnable wrappedRunnable
      The underlying task.
    • Constructor Summary

      Constructors 
      Constructor Description
      ReschedulableCallable​(AbstractService service, java.util.concurrent.ScheduledExecutorService executor, java.lang.Runnable runnable)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Void call()  
      boolean cancel​(boolean mayInterruptIfRunning)  
      protected java.util.concurrent.Future<java.lang.Void> delegate()
      Returns the backing delegate instance that methods are forwarded to.
      boolean isCancelled()  
      void reschedule()
      Atomically reschedules this task and assigns the new future to currentFuture.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • wrappedRunnable

        private final java.lang.Runnable wrappedRunnable
        The underlying task.
      • executor

        private final java.util.concurrent.ScheduledExecutorService executor
        The executor on which this Callable will be scheduled.
      • service

        private final AbstractService service
        The service that is managing this callable. This is used so that failure can be reported properly.
      • lock

        private final java.util.concurrent.locks.ReentrantLock lock
        This lock is used to ensure safe and correct cancellation, it ensures that a new task is not scheduled while a cancel is ongoing. Also it protects the currentFuture variable to ensure that it is assigned atomically with being scheduled.
      • currentFuture

        private java.util.concurrent.Future<java.lang.Void> currentFuture
        The future that represents the next execution of this task.
    • Constructor Detail

      • ReschedulableCallable

        ReschedulableCallable​(AbstractService service,
                              java.util.concurrent.ScheduledExecutorService executor,
                              java.lang.Runnable runnable)
    • Method Detail

      • call

        public java.lang.Void call()
                            throws java.lang.Exception
        Specified by:
        call in interface java.util.concurrent.Callable<java.lang.Void>
        Throws:
        java.lang.Exception
      • reschedule

        public void reschedule()
        Atomically reschedules this task and assigns the new future to currentFuture.
      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface java.util.concurrent.Future<java.lang.Void>
        Overrides:
        cancel in class ForwardingFuture<java.lang.Void>
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface java.util.concurrent.Future<java.lang.Void>
        Overrides:
        isCancelled in class ForwardingFuture<java.lang.Void>
      • delegate

        protected java.util.concurrent.Future<java.lang.Void> delegate()
        Description copied from class: ForwardingObject
        Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.
        Specified by:
        delegate in class ForwardingFuture<java.lang.Void>