Class AbstractScheduledService.CustomScheduler.ReschedulableCallable
- java.lang.Object
-
- com.google.common.util.concurrent.AbstractScheduledService.CustomScheduler.ReschedulableCallable
-
- All Implemented Interfaces:
java.util.concurrent.Callable<java.lang.Void>
- Enclosing class:
- AbstractScheduledService.CustomScheduler
private final class AbstractScheduledService.CustomScheduler.ReschedulableCallable extends java.lang.Object implements java.util.concurrent.Callable<java.lang.Void>
A callable class that can reschedule itself using aAbstractScheduledService.CustomScheduler
.
-
-
Field Summary
Fields Modifier and Type Field Description private AbstractScheduledService.CustomScheduler.SupplantableFuture
cancellationDelegate
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()
private AbstractScheduledService.Cancellable
initializeOrUpdateCancellationDelegate(AbstractScheduledService.CustomScheduler.Schedule schedule)
AbstractScheduledService.Cancellable
reschedule()
Atomically reschedules this task and assigns the new future tocancellationDelegate
.private java.util.concurrent.ScheduledFuture<java.lang.Void>
submitToExecutor(AbstractScheduledService.CustomScheduler.Schedule schedule)
-
-
-
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.
-
cancellationDelegate
@CheckForNull private AbstractScheduledService.CustomScheduler.SupplantableFuture cancellationDelegate
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
@CheckForNull 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 AbstractScheduledService.Cancellable reschedule()
Atomically reschedules this task and assigns the new future tocancellationDelegate
.
-
initializeOrUpdateCancellationDelegate
private AbstractScheduledService.Cancellable initializeOrUpdateCancellationDelegate(AbstractScheduledService.CustomScheduler.Schedule schedule)
-
submitToExecutor
private java.util.concurrent.ScheduledFuture<java.lang.Void> submitToExecutor(AbstractScheduledService.CustomScheduler.Schedule schedule)
-
-