/** * Constructs a runnable future with a callable work unit. * * @param recurring boolean to indicate if this task can run multiple times, and thus must be reset after each run * @param task callable to be run * @param executingExecutor Executor task will be run on for possible listener optimization, or {@code null} */ public ListenableFutureTask(boolean recurring, Callable<T> task, Executor executingExecutor) { super(task); this.listenerHelper = new RunnableListenerHelper(true); this.recurring = recurring; this.callable = task; this.executingExecutor = executingExecutor; }
/** * Constructs a runnable future with a callable work unit. * * @param recurring boolean to indicate if this task can run multiple times, and thus must be reset after each run * @param task callable to be run * @param executingExecutor Executor task will be run on for possible listener optimization, or {@code null} */ public ListenableFutureTask(boolean recurring, Callable<T> task, Executor executingExecutor) { super(task); this.listenerHelper = new RunnableListenerHelper(true); this.recurring = recurring; this.callable = task; this.executingExecutor = executingExecutor; }
/** * Constructs a new {@link SettableListenableFuture}. You can return this immediately and * provide a result to the object later when it is ready. * <p> * This constructor allows you to control the behavior when results are attempt to be set after * the future has already completed (either by * {@link #cancel(boolean)}, {@link #setResult(Object)}, or {@link #setFailure(Throwable)}). * <p> * If {@code true}, any additional attempts to {@link #setResult(Object)} or * {@link #setFailure(Throwable)} will result in a {@link IllegalStateException} being thrown. * <p> * If {@code false}, additional attempts to set a result will just be silently ignored. * * @param throwIfAlreadyComplete Defines the behavior when result or failure is set on a completed future * @param executingExecutor Executor this future will complete on, used for optimizations */ protected SettableListenableFuture(boolean throwIfAlreadyComplete, Executor executingExecutor) { this.listenerHelper = new RunnableListenerHelper(true); this.resultLock = listenerHelper; // cheating to avoiding another object just for a lock this.throwIfAlreadyComplete = throwIfAlreadyComplete; this.runningThread = null; this.executingExecutor = executingExecutor; done = false; cancelStateMessage = null; resultCleared = false; result = null; failure = null; }
/** * Constructs a new {@link SettableListenableFuture}. You can return this immediately and * provide a result to the object later when it is ready. * <p> * This constructor allows you to control the behavior when results are attempt to be set after * the future has already completed (either by * {@link #cancel(boolean)}, {@link #setResult(Object)}, or {@link #setFailure(Throwable)}). * <p> * If {@code true}, any additional attempts to {@link #setResult(Object)} or * {@link #setFailure(Throwable)} will result in a {@link IllegalStateException} being thrown. * <p> * If {@code false}, additional attempts to set a result will just be silently ignored. * * @param throwIfAlreadyComplete Defines the behavior when result or failure is set on a completed future * @param executingExecutor Executor this future will complete on, used for optimizations */ protected SettableListenableFuture(boolean throwIfAlreadyComplete, Executor executingExecutor) { this.listenerHelper = new RunnableListenerHelper(true); this.resultLock = listenerHelper; // cheating to avoiding another object just for a lock this.throwIfAlreadyComplete = throwIfAlreadyComplete; this.runningThread = null; this.executingExecutor = executingExecutor; done = false; cancelStateMessage = null; resultCleared = false; result = null; failure = null; }
@Before public void setup() { onceHelper = new RunnableListenerHelper(true); repeatedHelper = new RunnableListenerHelper(false); }