RecursiveLookup Class Reference

#include <RecursiveLookup.h>

Inheritance diagram for RecursiveLookup:
RpcListener AbstractLookup

List of all members.

Public Member Functions

 RecursiveLookup (BaseOverlay *overlay, RoutingType routingType, const RecursiveLookupConfiguration &config, 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 uint32_t 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
int redundantNodes
int numRetries
bool appLookup

Detailed Description

Definition at line 48 of file RecursiveLookup.h.


Constructor & Destructor Documentation

RecursiveLookup::RecursiveLookup ( BaseOverlay overlay,
RoutingType  routingType,
const RecursiveLookupConfiguration config,
bool  appLookup 
)

Definition at line 31 of file RecursiveLookup.cc.

00035                                                  :
00036     overlay(overlay),
00037     routingType(routingType),
00038     redundantNodes(config.redundantNodes),
00039     numRetries(config.numRetries),
00040     appLookup(appLookup)
00041 {
00042     valid = false;
}

RecursiveLookup::~RecursiveLookup (  )  [virtual]

Virtual destructor.

Definition at line 44 of file RecursiveLookup.cc.

00045 {
00046     if (listener != NULL) {
00047         delete listener;
00048         listener = NULL;
00049     }
00050 
00051     overlay->removeLookup(this);
00052 }


Member Function Documentation

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.

Definition at line 82 of file RecursiveLookup.cc.

00083 {
00084     overlay->cancelRpcMessage(nonce);
00085 
00086     delete this;
00087 }

uint32_t RecursiveLookup::getAccumulatedHops (  )  const [virtual]

Returns the total number of hops for all lookup paths.

Returns:
The accumulated number of hops.

Implements AbstractLookup.

Definition at line 89 of file RecursiveLookup.cc.

00090 {
00091     //throw new cRuntimeError("RecursiveLookup is asked for # accumulated hops!");
00092     return 0; //TODO hopCount in findNodeCall/Response ?
00093 }

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

Returns the result of the lookup.

Returns:
The result node vector.

Implements AbstractLookup.

Definition at line 72 of file RecursiveLookup.cc.

00073 {
00074     return siblings;
00075 }

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.

Definition at line 112 of file RecursiveLookup.cc.

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

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.

Definition at line 95 of file RecursiveLookup.cc.

00099 {
00100     //TODO retry
00101     valid = false;
00102 
00103     // inform listener
00104     if (listener != NULL) {
00105         listener->lookupFinished(this);
00106         listener = NULL;
00107     }
00108 
00109     delete this;
00110 }

bool RecursiveLookup::isValid (  )  const [virtual]

Returns true, if the lookup was successful.

Returns:
true, if the lookup was successful.

Implements AbstractLookup.

Definition at line 77 of file RecursiveLookup.cc.

00078 {
00079     return valid;
00080 }

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.

Definition at line 54 of file RecursiveLookup.cc.

00057 {
00058     this->listener = listener;
00059 
00060     FindNodeCall* call = new FindNodeCall("FindNodeCall");
00061     if (appLookup) call->setStatType(APP_LOOKUP_STAT);
00062     else call->setStatType(MAINTENANCE_STAT);
00063     call->setLookupKey(key);
00064     call->setNumRedundantNodes(redundantNodes);
00065     call->setNumSiblings(numSiblings);
00066     call->setBitLength(FINDNODECALL_L(call));
00067 
00068     nonce = overlay->sendRouteRpcCall(OVERLAY_COMP, key, call, NULL,
00069                                       routingType, -1, retries, -1, this);
00070 }


Member Data Documentation

Definition at line 110 of file RecursiveLookup.h.

Referenced by lookup().

Definition at line 103 of file RecursiveLookup.h.

Referenced by handleRpcResponse(), handleRpcTimeout(), and ~RecursiveLookup().

uint32_t RecursiveLookup::nonce [private]

Definition at line 104 of file RecursiveLookup.h.

Referenced by abortLookup(), and lookup().

Definition at line 109 of file RecursiveLookup.h.

Definition at line 102 of file RecursiveLookup.h.

Referenced by abortLookup(), lookup(), and ~RecursiveLookup().

Definition at line 108 of file RecursiveLookup.h.

Referenced by lookup().

RoutingType RecursiveLookup::routingType [private]

Definition at line 107 of file RecursiveLookup.h.

Referenced by lookup().

Definition at line 106 of file RecursiveLookup.h.

Referenced by getResult(), and handleRpcResponse().

bool RecursiveLookup::valid [private]

Definition at line 105 of file RecursiveLookup.h.

Referenced by handleRpcResponse(), handleRpcTimeout(), isValid(), and RecursiveLookup().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:19 2010 for OverSim by  doxygen 1.6.3