net.tomp2p.futures
Class FutureDHT

java.lang.Object
  extended by net.tomp2p.futures.BaseFutureImpl<FutureDHT>
      extended by net.tomp2p.futures.FutureDHT
All Implemented Interfaces:
BaseFuture, Cancellable, FutureCleanup

public class FutureDHT
extends BaseFutureImpl<FutureDHT>
implements FutureCleanup

The future object for the get() and put() operations including routing.

Author:
Thomas Bocek

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.tomp2p.futures.BaseFuture
BaseFuture.FutureType
 
Field Summary
 
Fields inherited from class net.tomp2p.futures.BaseFutureImpl
completed, lock, reason, type
 
Constructor Summary
FutureDHT()
           
FutureDHT(int min, EvaluatingSchemeDHT evaluationScheme, FutureCreate<FutureDHT> futureCreate)
          Creates a new DHT future object that keeps track of the status of the DHT operations.
 
Method Summary
 void addCleanup(Cancellable cancellable)
          Call to add cleanup classes for the future e.g.
 void addRequests(FutureResponse futureResponse)
          Adds all requests that have been created for the DHT operations.
 Object getAttachement()
           
 double getAvgStoredKeys()
           
 Object getChannelBuffer()
          Return the data from send_direct (Netty buffer) after evaluation.
 Data getData()
           
 Map<Number160,Data> getDataMap()
          Return the data from get() after evaluation.
 DigestResult getDigest()
          Return the digest information from the get() after evaluation.
 Number160 getDomainKey()
           
 Collection<Number480> getEvalKeys()
          Returns the keys that have been stored or removed after evaluation.
 FutureCreate<FutureDHT> getFutureCreate()
          Returns the future object that keeps information about future object, based on this object
 FutureForkJoin<FutureResponse> getFutureRequests()
          Returns back those futures that are still running.
 FutureRouting getFutureRouting()
          Returns the future object that was used for the routing.
 Collection<Number160> getKeys()
          Deprecated. 
 Number160 getLocationKey()
           
 Object getObject()
          Return the data from send_direct (Object) after evaluation.
 Map<PeerAddress,Map<Number160,Data>> getRawData()
          Returns the raw data from the get operation
 Map<PeerAddress,DigestResult> getRawDigest()
           
 Map<PeerAddress,org.jboss.netty.buffer.ChannelBuffer> getRawDirectData1()
          Return raw data from send_dircet (Netty buffer).
 Map<PeerAddress,Object> getRawDirectData2()
          Return raw data from send_dircet (Object).
 Map<PeerAddress,Collection<Number160>> getRawKeys()
          Returns the raw keys from the storage or removal operation
 Map<PeerAddress,Collection<Number480>> getRawKeys480()
           
 boolean isMinReached()
          Checks if the minimum of expected results have been reached.
 boolean isReleaseEarly()
           
 void releaseEarly()
           
 void repeated(FutureDHT futureDHT)
          Called for futures created based on this future.
 void setDirectData1(Map<PeerAddress,org.jboss.netty.buffer.ChannelBuffer> rawChannels)
          Finish the future and set the keys and data that have send directly using the Netty buffer.
 void setDirectData2(Map<PeerAddress,Object> rawObjects)
          Finish the future and set the keys and data that have send directly using an object.
 void setDone(Object attachement)
          Finish the future and set a general purpose attachement.
 void setFutureRouting(FutureRouting futureRouting)
          Sets the future object that was used for the routing.
 void setReceivedData(Map<PeerAddress,Map<Number160,Data>> rawData)
          Finish the future and set the keys and data that have been received.
 void setReceivedDigest(Map<PeerAddress,DigestResult> rawDigest)
          Finishes the future and set the digest information that have been received.
 void setRemovedKeys(Map<PeerAddress,Collection<Number160>> rawKeys)
          Finish the future and set the keys that have been removed.
 void setStoredKeys(Number160 locationKey, Number160 domainKey, Map<PeerAddress,Collection<Number160>> rawKeys, Map<PeerAddress,Collection<Number480>> rawKeys480)
          Finish the future and set the keys that have been stored.
 void shutdown()
           
 
Methods inherited from class net.tomp2p.futures.BaseFutureImpl
addCancellation, addListener, addListener, await, await, awaitListeners, awaitUninterruptibly, awaitUninterruptibly, cancel, getFailedReason, 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
 

Constructor Detail

FutureDHT

public FutureDHT()

FutureDHT

public FutureDHT(int min,
                 EvaluatingSchemeDHT evaluationScheme,
                 FutureCreate<FutureDHT> futureCreate)
Creates a new DHT future object that keeps track of the status of the DHT operations.

Parameters:
min - The minimum of expected results
evaluationScheme - The scheme to evaluate results from multiple peers
futureCreate - The object to keep track of the futures created based on this future
futureRouting - The futures from the routing process.
Method Detail

setDone

public void setDone(Object attachement)
Finish the future and set a general purpose attachement.

Parameters:
object - General purpose attachement

getAttachement

public Object getAttachement()

setRemovedKeys

public void setRemovedKeys(Map<PeerAddress,Collection<Number160>> rawKeys)
Finish the future and set the keys that have been removed.

Parameters:
rawKeys - The removed keys with information from which peer it has been removed

setStoredKeys

public void setStoredKeys(Number160 locationKey,
                          Number160 domainKey,
                          Map<PeerAddress,Collection<Number160>> rawKeys,
                          Map<PeerAddress,Collection<Number480>> rawKeys480)
Finish the future and set the keys that have been stored. Success or failure is determined if the communication was successful. This means that we need to further check if the other peers have denied the storage (e.g., due to no storage space, no security permissions). Further evaluation can be retrieved with getAvgStoredKeys() or if the evaluation should be done by the user, use getRawKeys().

Parameters:
domainKey -
locationKey -
rawKeys - The keys that have been stored with information on which peer it has been stored
rawData480 -
ifAbsent - Flag if the user requested putIfAbsent

getAvgStoredKeys

public double getAvgStoredKeys()

setReceivedData

public void setReceivedData(Map<PeerAddress,Map<Number160,Data>> rawData)
Finish the future and set the keys and data that have been received.

Parameters:
rawData - The keys and data that have been received with information from which peer it has been received.

setReceivedDigest

public void setReceivedDigest(Map<PeerAddress,DigestResult> rawDigest)
Finishes the future and set the digest information that have been received.

Parameters:
rawDigest - The hashes of the content stored with information from which peer it has been received.

setDirectData1

public void setDirectData1(Map<PeerAddress,org.jboss.netty.buffer.ChannelBuffer> rawChannels)
Finish the future and set the keys and data that have send directly using the Netty buffer.

Parameters:
rawChannels - The raw data that have been sent directly with information on which peer it has been sent

setDirectData2

public void setDirectData2(Map<PeerAddress,Object> rawObjects)
Finish the future and set the keys and data that have send directly using an object.

Parameters:
rawObjects - The objects that have been sent directly with information on which peer it has been sent

getRawKeys

public Map<PeerAddress,Collection<Number160>> getRawKeys()
Returns the raw keys from the storage or removal operation

Returns:
The raw keys and the information which peer has been contacted

getRawData

public Map<PeerAddress,Map<Number160,Data>> getRawData()
Returns the raw data from the get operation

Returns:
The raw data and the information which peer has been contacted

getRawDigest

public Map<PeerAddress,DigestResult> getRawDigest()
Returns:
The raw digest information with hashes of the content and the information which peer has been contacted

getRawDirectData1

public Map<PeerAddress,org.jboss.netty.buffer.ChannelBuffer> getRawDirectData1()
Return raw data from send_dircet (Netty buffer).

Returns:
The raw data from send_dircet and the information which peer has been contacted

getRawDirectData2

public Map<PeerAddress,Object> getRawDirectData2()
Return raw data from send_dircet (Object).

Returns:
The raw data from send_dircet and the information which peer has been contacted

isMinReached

public boolean isMinReached()
Checks if the minimum of expected results have been reached. This flag is also used for determining the success or failure of this future for put and send_direct.

Returns:
True, if expected minimum results have been reached.

getKeys

@Deprecated
public Collection<Number160> getKeys()
Deprecated. 

Returns the keys that have been stored or removed after evaluation. The evaluation gets rid of the PeerAddress information, by either a majority vote or cumulation. Use getEvalKeys() instead of this method.

Returns:
The keys that have been stored or removed

getEvalKeys

public Collection<Number480> getEvalKeys()
Returns the keys that have been stored or removed after evaluation. The evaluation gets rid of the PeerAddress information, by either a majority vote or cumulation. Use getEvalKeys() instead of this method.

Returns:
The keys that have been stored or removed

getDataMap

public Map<Number160,Data> getDataMap()
Return the data from get() after evaluation. The evaluation gets rid of the PeerAddress information, by either a majority vote or cumulation.

Returns:
The evaluated data that have been received.

getData

public Data getData()
Returns:
The first data object from get() after evaluation.

getDigest

public DigestResult getDigest()
Return the digest information from the get() after evaluation. The evaluation gets rid of the PeerAddress information, by either a majority vote or cumulation.

Returns:
The evaluated digest information that have been received.

getObject

public Object getObject()
Return the data from send_direct (Object) after evaluation. The evaluation gets rid of the PeerAddress information, by either a majority vote or cumulation.

Returns:
The data that have been received.

getChannelBuffer

public Object getChannelBuffer()
Return the data from send_direct (Netty buffer) after evaluation. The evaluation gets rid of the PeerAddress information, by either a majority vote or cumulation.

Returns:
The data that have been received.

getRawKeys480

public Map<PeerAddress,Collection<Number480>> getRawKeys480()

getLocationKey

public Number160 getLocationKey()

getDomainKey

public Number160 getDomainKey()

getFutureCreate

public FutureCreate<FutureDHT> getFutureCreate()
Returns the future object that keeps information about future object, based on this object

Returns:
FutureCreate object.

getFutureRouting

public FutureRouting getFutureRouting()
Returns the future object that was used for the routing. Before the FutureDHT is used, FutureRouting has to be completed successfully.

Returns:
The future object during the previous routing, or null if routing failed completely.

setFutureRouting

public void setFutureRouting(FutureRouting futureRouting)
Sets the future object that was used for the routing. Before the FutureDHT is used, FutureRouting has to be completed successfully.

Parameters:
futureRouting - The future object to set

getFutureRequests

public FutureForkJoin<FutureResponse> getFutureRequests()
Returns back those futures that are still running. If 6 storage futures are started at the same time and 5 of them finish, and we specified that we are fine if 5 finishes, then futureDHT returns success. However, the future that may still be running is the one that stores the content to the closest peer. For testing this is not acceptable, thus after waiting for futureDHT, one needs to wait for the running futures as well.

Returns:
A future that finishes if all running futures are finished.

addRequests

public void addRequests(FutureResponse futureResponse)
Adds all requests that have been created for the DHT operations. Those were created after the routing process.

Parameters:
futureResponse - The futurRepsonse that has been created

repeated

public void repeated(FutureDHT futureDHT)
Called for futures created based on this future. This is used for scheduled futures.

Parameters:
futureDHT - The newly created future

addCleanup

public void addCleanup(Cancellable cancellable)
Description copied from interface: FutureCleanup
Call to add cleanup classes for the future e.g. to stop creating more scheduled futures.

Specified by:
addCleanup in interface FutureCleanup
Parameters:
cancellable - The cleanup classes

shutdown

public void shutdown()

releaseEarly

public void releaseEarly()

isReleaseEarly

public boolean isReleaseEarly()


Copyright © 2013. All Rights Reserved.