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>
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 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:
call
in 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:
cancel
in interfacejava.util.concurrent.Future<java.lang.Void>
- Overrides:
cancel
in classForwardingFuture<java.lang.Void>
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfacejava.util.concurrent.Future<java.lang.Void>
- Overrides:
isCancelled
in classForwardingFuture<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 asForwardingSet.delegate()
. Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegate
in classForwardingFuture<java.lang.Void>
-
-