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 BinaryValuegetData (const OverlayKey &key)
 Returns the value of a stored data item with a given key.
virtual const NodeHandlegetSourceNode (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 BinaryValuegetDataAtPos (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, DHTDatadataMap
 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
00059 {
00060     return dataMap.size();
00061 }

void DHTDataStorage::clear (  )  [virtual]

Clears all stored data items.

00053 {
00054     dataMap.clear();
00055 }

bool DHTDataStorage::isEmpty (  )  [virtual]

Checks if the data storage map is empty.

Returns:
returns false if there are stored data items, true otherwise.
00064 {
00065     if (dataMap.size() == 0)
00066         return true;
00067     else
00068         return false;
00069 }

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
00071                                                                 {
00072 
00073     std::map<OverlayKey, DHTData>::iterator it =  dataMap.find(key);
00074 
00075     if (it == dataMap.end())
00076         return BinaryValue::UNSPECIFIED_VALUE;
00077     else
00078         return it->second.value;
00079 }

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
00081                                                                      {
00082 
00083     std::map<OverlayKey, DHTData>::iterator it =  dataMap.find(key);
00084 
00085     if (it == dataMap.end())
00086         return NodeHandle::UNSPECIFIED_NODE;
00087     else
00088         return it->second.sourceNode;
00089 }

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
00091                                                             {
00092     std::map<OverlayKey, DHTData>::iterator it =  dataMap.find(key);
00093 
00094     if (it == dataMap.end())
00095         return NULL;
00096     else
00097         return it->second.ttlMessage;
00098 }

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
00100                                                              {
00101 
00102     std::map<OverlayKey, DHTData>::iterator it =  dataMap.find(key);
00103 
00104     if (it == dataMap.end())
00105         return true;
00106     else
00107         return it->second.is_modifiable;
00108 }

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
00112 {
00113     if (pos >= dataMap.size()) {
00114         error("Index out of bound (DHTDataStorage, getDataAtPos())");
00115     }
00116 
00117     std::map<OverlayKey, DHTData>::iterator it = dataMap.begin();
00118     for (uint i= 0; i < pos; i++) {
00119         it++;
00120         if (i == (pos-1))
00121             return it->second.value;
00122     }
00123     return it->second.value;
00124 }

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

Returns an iterator to the beginning of the map.

Returns:
An iterator
00127 {
00128     return dataMap.begin();
00129 }

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
00132 {
00133     DHTData entry;
00134     entry.value = value;
00135     entry.ttlMessage = ttlMessage;
00136     entry.sourceNode = sourceNode;
00137     entry.is_modifiable = is_modifiable;
00138     entry.responsible = responsible;
00139     // replace with new value
00140     dataMap.erase(key);
00141     dataMap.insert(make_pair(key, entry));
00142 }

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
00145 {
00146     dataMap.erase(key);
00147 }

void DHTDataStorage::display (  ) 

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

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
00150 {
00151     dhtDataVector* vect = new dhtDataVector();
00152     map<OverlayKey, DHTData>::iterator iter;
00153     if (lkey > rkey) { //the zero key is between this to keys
00154         //we fetch everything after lkey
00155         for( iter = dataMap.lower_bound(lkey); iter != dataMap.end(); iter++ ) {
00156             vect->insert(vect->end(), std::make_pair(iter->first, iter->second));
00157         }
00158         //and everything before rkey
00159         for( iter = dataMap.upper_bound(rkey); iter != (dataMap.begin()--); iter-- ) {
00160             vect->insert(vect->end(), std::make_pair(iter->first, iter->second));
00161         }
00162     }
00163     else {
00164         for (iter = dataMap.lower_bound(lkey); iter != (dataMap.upper_bound(rkey) ++); iter++) {
00165             vect->insert(vect->end(), std::make_pair(iter->first, iter->second));
00166         }
00167     }
00168 
00169     return vect;
00170 }

void DHTDataStorage::updateDisplayString (  )  [protected]

Displays the current number of successors in the list.

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

void DHTDataStorage::updateTooltip (  )  [protected]

Displays the first 4 successor nodes as tooltip.

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


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 Tue Jul 24 16:51:18 2007 for ITM OverSim by  doxygen 1.5.1