DHTDataStorage Class Reference

#include <DHTDataStorage.h>

List of all members.

Public Member Functions

virtual int numInitStages () const
virtual void initialize (int stage)
virtual void handleMessage (cMessage *msg)
virtual uint getSize ()
 Returns number of stored data items in the map.
virtual void clear ()
 Clears all stored data items.
virtual bool isEmpty ()
 Checks if the data storage map is empty.
virtual const
BinaryValue
getData (const OverlayKey &key)
 Returns the value of a stored data item with a given key.
virtual const
NodeHandle
getSourceNode (const OverlayKey &key)
 Returns the source node of a stored data item with a given key.
virtual cMessage * getTtlMessage (const OverlayKey &key)
 Returns the ttlMessage of a stored data item with a given key.
virtual const bool isModifiable (const OverlayKey &key)
 Returns a boolean telling if this data if modifiable.
virtual const
BinaryValue
getDataAtPos (uint pos=0)
 Returns the value of the data item stored at position pos.
virtual const
std::map< OverlayKey,
DHTData >::iterator 
begin ()
 Returns an iterator to the beginning of the map.
virtual void addData (OverlayKey key, BinaryValue value, cMessage *ttlMessage, bool is_modifiable=true, NodeHandle sourceNode=NodeHandle::UNSPECIFIED_NODE, bool responsible=true)
 Store a new data item in the map.
virtual void removeData (OverlayKey key)
 Removes a certain data item from the map.
void display ()
dhtDataVectorget_range (const OverlayKey lkey, const OverlayKey rkey)
 Return a vector containing every keys/values between the two bounds.

Protected Member Functions

void updateDisplayString ()
 Displays the current number of successors in the list.
void updateTooltip ()
 Displays the first 4 successor nodes as tooltip.

Protected Attributes

std::map< OverlayKey,
DHTData
dataMap
 internal representation of the data storage


Member Function Documentation

virtual int DHTDataStorage::numInitStages (  )  const [inline, virtual]

00062     {
00063         return MAX_STAGE_APP + 1;
00064     }

void DHTDataStorage::initialize ( int  stage  )  [virtual]

00040 {
00041     if (stage != MIN_STAGE_APP)
00042         return;
00043 
00044     WATCH_MAP(dataMap);
00045 }

void DHTDataStorage::handleMessage ( cMessage *  msg  )  [virtual]

00048 {
00049     error("This module doesn't handle messages!");
00050 }

uint DHTDataStorage::getSize (  )  [virtual]

Returns number of stored data items in the map.

Returns:
number of stored data items
00063 {
00064     return dataMap.size();
00065 }

void DHTDataStorage::clear (  )  [virtual]

Clears all stored data items.

00053 {
00054   map<OverlayKey, DHTData>::iterator iter;
00055   for( iter = dataMap.begin(); iter != dataMap.end(); iter++ ) {
00056     cancelAndDelete(iter->second.ttlMessage);
00057   }
00058   dataMap.clear();
00059 }

bool DHTDataStorage::isEmpty (  )  [virtual]

Checks if the data storage map is empty.

Returns:
returns false if there are stored data items, true otherwise.
00068 {
00069     if (dataMap.size() == 0)
00070         return true;
00071     else
00072         return false;
00073 }

const BinaryValue & DHTDataStorage::getData ( const OverlayKey key  )  [virtual]

Returns the value of a stored data item with a given key.

Parameters:
key The key of the data item
Returns:
The value of the data item with the given key
00075                                                                 {
00076 
00077     std::map<OverlayKey, DHTData>::iterator it =  dataMap.find(key);
00078 
00079     if (it == dataMap.end())
00080         return BinaryValue::UNSPECIFIED_VALUE;
00081     else
00082         return it->second.value;
00083 }

const NodeHandle & DHTDataStorage::getSourceNode ( const OverlayKey key  )  [virtual]

Returns the source node of a stored data item with a given key.

Parameters:
key The key of the data item
Returns:
The source node of the data item with the given key
00085                                                                      {
00086 
00087     std::map<OverlayKey, DHTData>::iterator it =  dataMap.find(key);
00088 
00089     if (it == dataMap.end())
00090         return NodeHandle::UNSPECIFIED_NODE;
00091     else
00092         return it->second.sourceNode;
00093 }

cMessage * DHTDataStorage::getTtlMessage ( const OverlayKey key  )  [virtual]

Returns the ttlMessage of a stored data item with a given key.

Parameters:
key The key of the data item
Returns:
The ttlMessage of the data item with the given key
00095                                                             {
00096     std::map<OverlayKey, DHTData>::iterator it =  dataMap.find(key);
00097 
00098     if (it == dataMap.end())
00099         return NULL;
00100     else
00101         return it->second.ttlMessage;
00102 }

const bool DHTDataStorage::isModifiable ( const OverlayKey key  )  [virtual]

Returns a boolean telling if this data if modifiable.

Parameters:
key The key of the data item
Returns:
The value of the is_modifiable value
00104                                                              {
00105 
00106     std::map<OverlayKey, DHTData>::iterator it =  dataMap.find(key);
00107 
00108     if (it == dataMap.end())
00109         return true;
00110     else
00111         return it->second.is_modifiable;
00112 }

const BinaryValue & DHTDataStorage::getDataAtPos ( uint  pos = 0  )  [virtual]

Returns the value of the data item stored at position pos.

Parameters:
pos position in data storage map
Returns:
The value of the data item at position pos
00116 {
00117     if (pos >= dataMap.size()) {
00118         error("Index out of bound (DHTDataStorage, getDataAtPos())");
00119     }
00120 
00121     std::map<OverlayKey, DHTData>::iterator it = dataMap.begin();
00122     for (uint i= 0; i < pos; i++) {
00123         it++;
00124         if (i == (pos-1))
00125             return it->second.value;
00126     }
00127     return it->second.value;
00128 }

const std::map< OverlayKey, DHTData >::iterator DHTDataStorage::begin (  )  [virtual]

Returns an iterator to the beginning of the map.

Returns:
An iterator
00131 {
00132     return dataMap.begin();
00133 }

void DHTDataStorage::addData ( OverlayKey  key,
BinaryValue  value,
cMessage *  ttlMessage,
bool  is_modifiable = true,
NodeHandle  sourceNode = NodeHandle::UNSPECIFIED_NODE,
bool  responsible = true 
) [virtual]

Store a new data item in the map.

Parameters:
key The key of the data item to be stored
value The value of the data item to be stored
ttlMessage The self-message sent for the ttl expiration
is_modifiable Flag that tell if the data can be change by anyone, or just by the sourceNode
sourceNode Node which asked to store the value
responsible 
00136 {
00137     DHTData entry;
00138     entry.value = value;
00139     entry.ttlMessage = ttlMessage;
00140     entry.sourceNode = sourceNode;
00141     entry.is_modifiable = is_modifiable;
00142     entry.responsible = responsible;
00143     // replace with new value
00144     dataMap.erase(key);
00145     dataMap.insert(make_pair(key, entry));
00146 }

void DHTDataStorage::removeData ( OverlayKey  key  )  [virtual]

Removes a certain data item from the map.

Parameters:
key The key of the data item to be removed
00149 {
00150     dataMap.erase(key);
00151 }

void DHTDataStorage::display (  ) 

00214 {
00215     cout << "Content of DHTDataStorage:" << endl;
00216     for (std::map<OverlayKey, DHTData>::iterator it = dataMap.begin();
00217          it != dataMap.end(); it++) {
00218         cout << "Key: " << it->first << " Value: " << it->second.value << "End-time: " << it->second.ttlMessage->arrivalTime() << endl;
00219     }
00220 }

dhtDataVector * DHTDataStorage::get_range ( const OverlayKey  lkey,
const OverlayKey  rkey 
)

Return a vector containing every keys/values between the two bounds.

Parameters:
lkey The beginning of the range
rkey The end of the range
00154 {
00155     dhtDataVector* vect = new dhtDataVector();
00156     map<OverlayKey, DHTData>::iterator iter;
00157     if (lkey > rkey) { //the zero key is between this to keys
00158         //we fetch everything after lkey
00159         for( iter = dataMap.lower_bound(lkey); iter != dataMap.end(); iter++ ) {
00160             vect->insert(vect->end(), std::make_pair(iter->first, iter->second));
00161         }
00162         //and everything before rkey
00163         for( iter = dataMap.upper_bound(rkey); iter != (dataMap.begin()--); iter-- ) {
00164             vect->insert(vect->end(), std::make_pair(iter->first, iter->second));
00165         }
00166     }
00167     else {
00168         for (iter = dataMap.lower_bound(lkey); iter != (dataMap.upper_bound(rkey) ++); iter++) {
00169             vect->insert(vect->end(), std::make_pair(iter->first, iter->second));
00170         }
00171     }
00172 
00173     return vect;
00174 }

void DHTDataStorage::updateDisplayString (  )  [protected]

Displays the current number of successors in the list.

00177 {
00178 // FIXME: doesn't work without tcl/tk
00179 //      if (ev.isGUI()) {
00180     if (1) {
00181         char buf[80];
00182 
00183         if (dataMap.size() == 1) {
00184             sprintf(buf, "1 data item");
00185         } else {
00186             sprintf(buf, "%zi data items", dataMap.size());
00187         }
00188 
00189         displayString().setTagArg("t", 0, buf);
00190         displayString().setTagArg("t", 2, "blue");
00191     }
00192 
00193 }

void DHTDataStorage::updateTooltip (  )  [protected]

Displays the first 4 successor nodes as tooltip.

00196 {
00197     if (ev.isGUI()) {
00198         std::stringstream str;
00199         for (uint i = 0; i < dataMap.size(); i++)       {
00200             str << getDataAtPos(i);
00201   
00202             if ( i != dataMap.size() - 1 )
00203                 str << endl;
00204         }
00205 
00206 
00207         char buf[1024];
00208         sprintf(buf, "%s", str.str().c_str());
00209         displayString().setTagArg("tt", 0, buf);
00210     }
00211 }


Member Data Documentation

std::map<OverlayKey, DHTData> DHTDataStorage::dataMap [protected]

internal representation of the data storage


The documentation for this class was generated from the following files:
Generated on Thu Apr 17 13:19:28 2008 for ITM OverSim by  doxygen 1.5.3