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:
java.lang.Runnable
,java.util.concurrent.Future<V>
,java.util.concurrent.RunnableFuture<V>
,ExecutorNotification
,NotifyingFuture<V>
- Enclosing class:
- ExecutionService
public static class ExecutionService.DistributedFuture<V> extends java.lang.Object implements java.util.concurrent.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 Classes Modifier and Type Class Description protected static class
ExecutionService.DistributedFuture.Sync<V>
Synchronization control for FutureTask.
-
Field Summary
Fields Modifier and Type Field Description protected ExecutionService.DistributedFuture.Sync<V>
sync
Synchronization control for FutureTask
-
Constructor Summary
Constructors Constructor Description DistributedFuture(JChannel channel, java.util.concurrent.locks.Lock unfinishedLock, java.util.concurrent.locks.Condition condition, java.util.Set<java.util.concurrent.Future<?>> futuresToFinish, java.lang.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, java.util.concurrent.locks.Lock unfinishedLock, java.util.concurrent.locks.Condition condition, java.util.Set<java.util.concurrent.Future<?>> futuresToFinish, java.util.concurrent.Callable<V> callable)
Creates a FutureTask that will upon running, execute the given Callable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
cancel(boolean mayInterruptIfRunning)
protected void
done()
Protected method invoked when this task transitions to state isDone (whether normally or via cancellation).V
get()
V
get(long timeout, java.util.concurrent.TimeUnit unit)
java.util.concurrent.Callable<V>
getCallable()
void
interrupted(java.lang.Runnable runnable)
boolean
isCancelled()
boolean
isDone()
void
resultReturned(java.lang.Object obj)
void
run()
Sets this Future to the result of its computation unless it has been cancelled.protected void
set(V v)
Sets the result of this Future to the given value unless this future has already been set or has been cancelled.protected void
setException(java.lang.Throwable t)
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.NotifyingFuture<V>
setListener(FutureListener<V> listener)
Attaches a listener and returns the same future instance, to allow for 'building' futures.void
throwableEncountered(java.lang.Throwable t)
java.lang.String
toString()
-
-
-
Field Detail
-
sync
protected final ExecutionService.DistributedFuture.Sync<V> sync
Synchronization control for FutureTask
-
-
Constructor Detail
-
DistributedFuture
public DistributedFuture(JChannel channel, java.util.concurrent.locks.Lock unfinishedLock, java.util.concurrent.locks.Condition condition, java.util.Set<java.util.concurrent.Future<?>> futuresToFinish, java.util.concurrent.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, java.util.concurrent.locks.Lock unfinishedLock, java.util.concurrent.locks.Condition condition, java.util.Set<java.util.concurrent.Future<?>> futuresToFinish, java.lang.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:
java.lang.NullPointerException
- if runnable is null
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getCallable
public java.util.concurrent.Callable<V> getCallable()
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfacejava.util.concurrent.Future<V>
-
isDone
public boolean isDone()
- Specified by:
isDone
in interfacejava.util.concurrent.Future<V>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
- Specified by:
cancel
in interfacejava.util.concurrent.Future<V>
-
get
public V get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Specified by:
get
in interfacejava.util.concurrent.Future<V>
- Throws:
java.util.concurrent.CancellationException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
get
public V get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
- Specified by:
get
in interfacejava.util.concurrent.Future<V>
- Throws:
java.util.concurrent.CancellationException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.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
public NotifyingFuture<V> setListener(FutureListener<V> listener)
Description copied from interface:NotifyingFuture
Attaches a listener and returns the same future instance, to allow for 'building' futures.- Specified by:
setListener
in interfaceNotifyingFuture<V>
- Parameters:
listener
- listener to attach- Returns:
- the same future instance
-
set
protected void set(V v)
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
protected void setException(java.lang.Throwable t)
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:
run
in interfacejava.lang.Runnable
- Specified by:
run
in interfacejava.util.concurrent.RunnableFuture<V>
-
resultReturned
public void resultReturned(java.lang.Object obj)
- Specified by:
resultReturned
in interfaceExecutorNotification
-
throwableEncountered
public void throwableEncountered(java.lang.Throwable t)
- Specified by:
throwableEncountered
in interfaceExecutorNotification
-
interrupted
public void interrupted(java.lang.Runnable runnable)
- Specified by:
interrupted
in interfaceExecutorNotification
-
-