RecursiveLookup Class Reference

#include <RecursiveLookup.h>

Inheritance diagram for RecursiveLookup:

RpcListener AbstractLookup

List of all members.

Public Member Functions

 RecursiveLookup (BaseOverlay *overlay, RoutingType routingType, bool appLookup)
virtual ~RecursiveLookup ()
 Virtual destructor.
virtual void lookup (const OverlayKey &key, int numSiblings=1, int hopCountMax=0, int retries=0, LookupListener *listener=NULL)
 Lookup siblings for a key.
virtual const NodeVectorgetResult () const
 Returns the result of the lookup.
virtual bool isValid () const
 Returns true, if the lookup was successful.
virtual void abortLookup ()
 Aborts a running lookup.
virtual uint getAccumulatedHops () const
 Returns the total number of hops for all lookup paths.
void handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 This method is called if an RPC timeout has been reached.
void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 This method is called if an RPC response has been received.

Private Attributes

BaseOverlayoverlay
LookupListenerlistener
uint32_t nonce
bool valid
NodeVector siblings
RoutingType routingType
bool appLookup


Constructor & Destructor Documentation

RecursiveLookup::RecursiveLookup ( BaseOverlay overlay,
RoutingType  routingType,
bool  appLookup 
)

00033                                                  :
00034     overlay(overlay),
00035     routingType(routingType),
00036     appLookup(appLookup)
00037 {
00038     valid = false;
00039 }

RecursiveLookup::~RecursiveLookup (  )  [virtual]

Virtual destructor.

00042 {
00043     if (listener != NULL) {
00044         delete listener;
00045         listener = NULL;
00046     }
00047 
00048     overlay->removeLookup(this);
00049 }


Member Function Documentation

void RecursiveLookup::lookup ( const OverlayKey key,
int  numSiblings = 1,
int  hopCountMax = 0,
int  retries = 0,
LookupListener listener = NULL 
) [virtual]

Lookup siblings for a key.

Parameters:
key The key to lookup
numSiblings Number of siblings to lookup
hopCountMax Maximum hop count
retries Number of retries if lookup fails
listener Listener to inform, when the lookup is done

Implements AbstractLookup.

00054 {
00055     this->listener = listener;
00056 
00057     FindNodeCall* call = new FindNodeCall("FindNodeCall");
00058     if (appLookup) call->setStatType(APP_LOOKUP_STAT);
00059     else call->setStatType(MAINTENANCE_STAT);
00060     call->setLookupKey(key);
00061     call->setNumRedundantNodes(8); //TODO
00062     call->setNumSiblings(numSiblings);
00063     call->setLength(FINDNODECALL_L(call));
00064 
00065     nonce = overlay->sendRouteRpcCall(OVERLAY_COMP, key, call, NULL,
00066                                       routingType, -1, retries, -1, this);
00067 }

const NodeVector & RecursiveLookup::getResult (  )  const [virtual]

Returns the result of the lookup.

Returns:
The result node vector.

Implements AbstractLookup.

00070 {
00071     return siblings;
00072 }

bool RecursiveLookup::isValid (  )  const [virtual]

Returns true, if the lookup was successful.

Returns:
true, if the lookup was successful.

Implements AbstractLookup.

00075 {
00076     return valid;
00077 }

void RecursiveLookup::abortLookup (  )  [virtual]

Aborts a running lookup.

This method aborts a running lookup without calling the listener and delete the lookup object.

Implements AbstractLookup.

00080 {
00081     overlay->cancelRpcMessage(nonce);
00082 
00083     delete this;
00084 }

uint RecursiveLookup::getAccumulatedHops (  )  const [virtual]

Returns the total number of hops for all lookup paths.

Returns:
The accumulated number of hops.

Implements AbstractLookup.

00087 {
00088     return 0; //TODO
00089 }

void RecursiveLookup::handleRpcTimeout ( BaseCallMessage *  msg,
const TransportAddress dest,
cPolymorphic *  context,
int  rpcId,
const OverlayKey destKey 
) [virtual]

This method is called if an RPC timeout has been reached.

Parameters:
msg The original RPC message.
dest The destination node
context Pointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code
rpcId The RPC id.
destKey the destination OverlayKey

Reimplemented from RpcListener.

00095 {
00096     valid = false;
00097 
00098     // inform listener
00099     if (listener != NULL) {
00100         listener->lookupFinished(this);
00101         listener = NULL;
00102     }
00103 
00104     delete this;
00105 }

void RecursiveLookup::handleRpcResponse ( BaseResponseMessage *  msg,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
) [virtual]

This method is called if an RPC response has been received.

Parameters:
msg The response message.
context Pointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code
rpcId The RPC id.
rtt The Round-Trip-Time of this RPC

Reimplemented from RpcListener.

00110 {
00111     FindNodeResponse* findNodeResponse = check_and_cast<FindNodeResponse*>(msg);
00112 
00113     if (findNodeResponse->getSiblings() &&
00114         findNodeResponse->getClosestNodesArraySize() > 0) {
00115         valid = true;
00116         for (uint i = 0; i < findNodeResponse->getClosestNodesArraySize();
00117              i++) {
00118             siblings.push_back(findNodeResponse->getClosestNodes(i));
00119         }
00120     }
00121 
00122 //    std::cout << "RecursiveLookup::handleRpcResponse() "
00123 //              << findNodeResponse->getClosestNodesArraySize() << std::endl;
00124 
00125     // inform listener
00126     if (listener != NULL) {
00127         listener->lookupFinished(this);
00128         listener = NULL;
00129     }
00130     delete this;
00131 }


Member Data Documentation

uint32_t RecursiveLookup::nonce [private]

Referenced by abortLookup(), and lookup().

bool RecursiveLookup::valid [private]

Referenced by getResult(), and handleRpcResponse().

RoutingType RecursiveLookup::routingType [private]

Referenced by lookup().

Referenced by lookup().


The documentation for this class was generated from the following files:

Generated on Fri Sep 19 13:05:08 2008 for ITM OverSim by  doxygen 1.5.5