net.tomp2p.futures
Class FutureForkJoin<K extends BaseFuture>
java.lang.Object
net.tomp2p.futures.BaseFutureImpl<FutureForkJoin<K>>
net.tomp2p.futures.FutureForkJoin<K>
- Type Parameters:
K
-
- All Implemented Interfaces:
- BaseFuture, Cancellable
public class FutureForkJoin<K extends BaseFuture>
- extends BaseFutureImpl<FutureForkJoin<K>>
- implements BaseFuture
The key future for recursive loops. A first version with the fork-join framework did not reduce the code complexity
significantly, thus I decided to write this class. The basic idea is that you can create parallel loops. For example
in a routing process (loop to find closest peers), one starts to ask 3 peers in parallel, the first that returns
result gets evaluated for new information about other peers, and a new peer is asked. If two peers finish, then two
other peers are asked. Thus, we keep always 3 connections running until we get the result.
- Author:
- Thomas Bocek
Constructor Summary |
FutureForkJoin(int nrFinishFuturesSuccess,
boolean cancelFuturesOnFinish,
K... forks)
Create a future fork join object |
FutureForkJoin(K... forks)
Facade if we expect everything to return successfully |
Methods inherited from class net.tomp2p.futures.BaseFutureImpl |
addCancellation, addListener, addListener, await, await, awaitListeners, awaitUninterruptibly, awaitUninterruptibly, cancel, getType, isCompleted, isFailed, isSuccess, notifyListerenrs, removeListener, self, setCompletedAndNotify, setFailed, setFailed, setFailed, setFailed, setFailed |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.tomp2p.futures.BaseFuture |
addCancellation, addListener, addListener, await, await, awaitListeners, awaitUninterruptibly, awaitUninterruptibly, getType, isCompleted, isFailed, isSuccess, removeListener, setFailed, setFailed, setFailed, setFailed, setFailed |
FutureForkJoin
public FutureForkJoin(K... forks)
- Facade if we expect everything to return successfully
- Parameters:
forks
- The futures
FutureForkJoin
public FutureForkJoin(int nrFinishFuturesSuccess,
boolean cancelFuturesOnFinish,
K... forks)
- Create a future fork join object
- Parameters:
nrFinishFuturesSuccess
- Is the number of futures that we expect to succeed.cancelFuturesOnFinish
- Tells use if we should cancel the remaining futures. For get() it makes sense to
cancel, for store() it does not.forks
- The future array, that may contain null futures.
getFailedReason
public String getFailedReason()
- Description copied from interface:
BaseFuture
- The default failed reason is Unknown.
- Specified by:
getFailedReason
in interface BaseFuture
- Overrides:
getFailedReason
in class BaseFutureImpl<FutureForkJoin<K extends BaseFuture>>
- Returns:
- Returns the reason why a future failed.
getLast
public K getLast()
- Returns the last evaluated future. This method may return null if an array with null values have been has been
used.
- Returns:
- The last evaluated future.
getCompleted
public List<K> getCompleted()
- Returns a list of evaluated futures. The last completed future is the same as retrieved with
getLast()
.
- Returns:
- A list of evaluated futures.
getSuccessCounter
public int getSuccessCounter()
- Returns the number of successful finished futures
- Returns:
- The number of successful finished futures
Copyright © 2013. All Rights Reserved.