Package org.jgroups.blocks.executor
Class ExecutionService.DistributedFuture<V>
java.lang.Object
org.jgroups.blocks.executor.ExecutionService.DistributedFuture<V>
- Type Parameters:
V-
- All Implemented Interfaces:
Runnable,Future<V>,RunnableFuture<V>,ExecutorNotification,NotifyingFuture<V>
- Enclosing class:
ExecutionService
public static class ExecutionService.DistributedFuture<V>
extends Object
implements RunnableFuture<V>, ExecutorNotification, NotifyingFuture<V>
This is basically a copy of the FutureTask in java.util.concurrent but
added serializable to it. Also added in the NotifyingFuture
so that the channel can update the future when the value is calculated.
- Author:
- wburns
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classSynchronization control for FutureTask.Nested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ExecutionService.DistributedFuture.Sync<V> Synchronization control for FutureTask -
Constructor Summary
ConstructorsConstructorDescriptionDistributedFuture(JChannel channel, Lock unfinishedLock, Condition condition, Set<Future<?>> futuresToFinish, Runnable runnable, V result) Creates a FutureTask that will upon running, execute the given Runnable, and arrange that get will return the given result on successful completion.DistributedFuture(JChannel channel, Lock unfinishedLock, Condition condition, Set<Future<?>> futuresToFinish, Callable<V> callable) Creates a FutureTask that will upon running, execute the given Callable. -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel(boolean mayInterruptIfRunning) protected voiddone()Protected method invoked when this task transitions to state isDone (whether normally or via cancellation).get()voidinterrupted(Runnable runnable) booleanbooleanisDone()voidresultReturned(Object obj) voidrun()Sets this Future to the result of its computation unless it has been cancelled.protected booleanExecutes the computation without setting its result, and then resets this Future to initial state, failing to do so if the computation encounters an exception or is cancelled.protected voidSets the result of this Future to the given value unless this future has already been set or has been cancelled.protected voidCauses this future to report an ExecutionException with the given throwable as its cause, unless this Future has already been set or has been cancelled.setListener(FutureListener<V> listener) Attaches a listener and returns the same future instance, to allow for 'building' futures.voidtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.Future
exceptionNow, resultNow, state
-
Field Details
-
sync
Synchronization control for FutureTask
-
-
Constructor Details
-
DistributedFuture
public DistributedFuture(JChannel channel, Lock unfinishedLock, Condition condition, Set<Future<?>> futuresToFinish, Callable<V> callable) Creates a FutureTask that will upon running, execute the given Callable.- Parameters:
channel- The channel that messages are sent downunfinishedLock- The lock which protects the futuresToFinish set object.condition- The condition to signal when this future finishesfuturesToFinish- The set to remove this future from when it is finished.callable- The callable to actually run on the server side
-
DistributedFuture
public DistributedFuture(JChannel channel, Lock unfinishedLock, Condition condition, Set<Future<?>> futuresToFinish, Runnable runnable, V result) Creates a FutureTask that will upon running, execute the given Runnable, and arrange that get will return the given result on successful completion.- Parameters:
channel- The channel that messages are sent downunfinishedLock- The lock which protects the futuresToFinish set object.condition- The condition to signal when this future finishesfuturesToFinish- The set to remove this future from when it is finished.runnable- the runnable taskresult- the result to return on successful completion. If you don't need a particular result, consider using constructions of the form: Future<?> f = new FutureTask<Object>(runnable, null)- Throws:
NullPointerException- if runnable is null
-
-
Method Details
-
toString
-
getCallable
-
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceFuture<V>
-
isDone
public boolean isDone() -
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
get
-
get
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException -
done
protected void done()Protected method invoked when this task transitions to state isDone (whether normally or via cancellation). The default implementation does nothing. Subclasses may override this method to invoke completion callbacks or perform bookkeeping. Note that you can query status inside the implementation of this method to determine whether this task has been cancelled. -
setListener
Description copied from interface:NotifyingFutureAttaches a listener and returns the same future instance, to allow for 'building' futures.- Specified by:
setListenerin interfaceNotifyingFuture<V>- Parameters:
listener- listener to attach- Returns:
- the same future instance
-
set
Sets the result of this Future to the given value unless this future has already been set or has been cancelled. This method is invoked internally by the run method upon successful completion of the computation.- Parameters:
v- the value
-
setException
Causes this future to report an ExecutionException with the given throwable as its cause, unless this Future has already been set or has been cancelled. This method is invoked internally by the run method upon failure of the computation.- Parameters:
t- the cause of failure
-
run
public void run()Sets this Future to the result of its computation unless it has been cancelled.- Specified by:
runin interfaceRunnable- Specified by:
runin interfaceRunnableFuture<V>
-
runAndReset
protected boolean runAndReset()Executes the computation without setting its result, and then resets this Future to initial state, failing to do so if the computation encounters an exception or is cancelled. This is designed for use with tasks that intrinsically execute more than once.- Returns:
- true if successfully run and reset
-
resultReturned
- Specified by:
resultReturnedin interfaceExecutorNotification
-
throwableEncountered
- Specified by:
throwableEncounteredin interfaceExecutorNotification
-
interrupted
- Specified by:
interruptedin interfaceExecutorNotification
-