Class AbstractScheduledService.CustomScheduler.ReschedulableCallable
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.util.concurrent.ForwardingFuture<java.lang.Void>
-
- com.google.common.util.concurrent.AbstractScheduledService.CustomScheduler.ReschedulableCallable
-
- All Implemented Interfaces:
java.util.concurrent.Callable<java.lang.Void>,java.util.concurrent.Future<java.lang.Void>
- Enclosing class:
- AbstractScheduledService.CustomScheduler
private class AbstractScheduledService.CustomScheduler.ReschedulableCallable extends ForwardingFuture<java.lang.Void> implements java.util.concurrent.Callable<java.lang.Void>
A callable class that can reschedule itself using aAbstractScheduledService.CustomScheduler.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.common.util.concurrent.ForwardingFuture
ForwardingFuture.SimpleForwardingFuture<V>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.Future<java.lang.Void>currentFutureThe future that represents the next execution of this task.private java.util.concurrent.ScheduledExecutorServiceexecutorThe executor on which this Callable will be scheduled.private java.util.concurrent.locks.ReentrantLocklockThis lock is used to ensure safe and correct cancellation, it ensures that a new task is not scheduled while a cancel is ongoing.private AbstractServiceserviceThe service that is managing this callable.private java.lang.RunnablewrappedRunnableThe 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.Voidcall()booleancancel(boolean mayInterruptIfRunning)protected java.util.concurrent.Future<java.lang.Void>delegate()Returns the backing delegate instance that methods are forwarded to.booleanisCancelled()voidreschedule()Atomically reschedules this task and assigns the new future tocurrentFuture.-
Methods inherited from class com.google.common.util.concurrent.ForwardingFuture
get, get, isDone
-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
-
-
-
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:
callin interfacejava.util.concurrent.Callable<java.lang.Void>- Throws:
java.lang.Exception
-
reschedule
public void reschedule()
Atomically reschedules this task and assigns the new future tocurrentFuture.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
- Specified by:
cancelin interfacejava.util.concurrent.Future<java.lang.Void>- Overrides:
cancelin classForwardingFuture<java.lang.Void>
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfacejava.util.concurrent.Future<java.lang.Void>- Overrides:
isCancelledin classForwardingFuture<java.lang.Void>
-
delegate
protected java.util.concurrent.Future<java.lang.Void> delegate()
Description copied from class:ForwardingObjectReturns 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 asForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegatein classForwardingFuture<java.lang.Void>
-
-