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 uint32_t getSize ()
 Returns number of stored data items in the map.
virtual void clear ()
 Clears all stored data items.
DhtDataEntrygetDataEntry (const OverlayKey &key, uint32_t kind, uint32_t id)
 Returns a pointer to the requested stored data item.
virtual DhtDataVectorgetDataVector (const OverlayKey &key, uint32_t kind=0, uint32_t id=0)
 Returns the stored data items with a given key, kind and id.
virtual const NodeHandlegetSourceNode (const OverlayKey &key, uint32_t kind, uint32_t id)
 Returns the source node of a stored data item with a given key.
virtual const bool isModifiable (const OverlayKey &key, uint32_t kind, uint32_t id)
 Returns a boolean telling if this data if modifiable.
virtual const DhtDataMap::iterator begin ()
 Returns an iterator to the beginning of the map.
virtual void addData (const OverlayKey &key, uint32_t kind, uint32_t id, 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 (const OverlayKey &key, uint32_t kind, uint32_t id)
 Removes a certain data item from the map.
void display ()
DhtDumpVectordumpDht (const OverlayKey &key=OverlayKey::UNSPECIFIED_KEY, uint32_t kind=0, uint32_t id=0)
 Dump filtered local data records into a vector.

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

DhtDataMap dataMap
 internal representation of the data storage


Detailed Description

Definition at line 66 of file DHTDataStorage.h.


Member Function Documentation

void DHTDataStorage::addData ( const OverlayKey key,
uint32_t  kind,
uint32_t  id,
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
kind The kind of the data item
id A random integer to identify multiple items with same key and kind
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 

Definition at line 141 of file DHTDataStorage.cc.

Referenced by DHT::handlePutRequest(), and CBRDHT::handlePutRequest().

00145 {
00146     DhtDataEntry entry;
00147     entry.kind = kind;
00148     entry.id = id;
00149     entry.value = value;
00150     entry.ttlMessage = ttlMessage;
00151     entry.sourceNode = sourceNode;
00152     entry.is_modifiable = is_modifiable;
00153     entry.responsible = responsible;
00154 
00155     if ((kind == 0) || (id == 0)) {
00156         throw cRuntimeError("DHTDataStorage::addData(): "
00157                             "Not allowed to add data with kind = 0 or id = 0!");
00158     }
00159 
00160     pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
00161         dataMap.equal_range(key);
00162 
00163     // insert new record in sorted multimap (order: key, kind, id)
00164     while ((pos.first != pos.second) && (pos.first->second.kind < kind)) {
00165         ++pos.first;
00166     }
00167 
00168     while ((pos.first != pos.second) && (pos.first->second.kind == kind)
00169             && (pos.first->second.id < id)) {
00170         ++pos.first;
00171     }
00172 
00173     dataMap.insert(pos.first, make_pair(key, entry));
00174 }

const DhtDataMap::iterator DHTDataStorage::begin (  )  [virtual]

Returns an iterator to the beginning of the map.

Returns:
An iterator

Definition at line 135 of file DHTDataStorage.cc.

Referenced by DHT::update(), and CBRDHT::update().

00136 {
00137     return dataMap.begin();
00138 }

void DHTDataStorage::clear (  )  [virtual]

Clears all stored data items.

Definition at line 57 of file DHTDataStorage.cc.

Referenced by CBRDHT::~CBRDHT(), and DHT::~DHT().

00058 {
00059     map<OverlayKey, DhtDataEntry>::iterator iter;
00060 
00061     for( iter = dataMap.begin(); iter != dataMap.end(); iter++ ) {
00062         cancelAndDelete(iter->second.ttlMessage);
00063     }
00064 
00065     dataMap.clear();
00066 }

void DHTDataStorage::display (  ) 

Definition at line 269 of file DHTDataStorage.cc.

00270 {
00271     cout << "Content of DHTDataStorage:" << endl;
00272     for (DhtDataMap::iterator it = dataMap.begin();
00273          it != dataMap.end(); it++) {
00274         cout << "Key: " << it->first << " Kind: " << it->second.kind
00275              << " ID: " << it->second.id << " Value: "
00276              << it->second.value << "End-time: "
00277              << it->second.ttlMessage->getArrivalTime() << endl;
00278     }
00279 }

DhtDumpVector * DHTDataStorage::dumpDht ( const OverlayKey key = OverlayKey::UNSPECIFIED_KEY,
uint32_t  kind = 0,
uint32_t  id = 0 
)

Dump filtered local data records into a vector.

Parameters:
key The key of the data items to dump
kind The kind of the data items to dump
id The id of the data items to dump
Returns:
the vector containing all matching data items

Definition at line 194 of file DHTDataStorage.cc.

Referenced by DHT::handleDumpDhtRequest(), CBRDHT::handleDumpDhtRequest(), and DHT::handleGetRequest().

00196 {
00197     DhtDumpVector* vect = new DhtDumpVector();
00198     DhtDumpEntry entry;
00199 
00200     DhtDataMap::iterator iter, end;
00201 
00202     if (key.isUnspecified()) {
00203         iter = dataMap.begin();
00204         end = dataMap.end();
00205     } else {
00206         iter = dataMap.lower_bound(key);
00207         end = dataMap.upper_bound(key);
00208     }
00209 
00210     for (; iter != end; iter++) {
00211         if (((kind == 0) || (iter->second.kind == kind)) &&
00212                 ((id == 0) || (iter->second.id == id))) {
00213 
00214             entry.setKey(iter->first);
00215             entry.setKind(iter->second.kind);
00216             entry.setId(iter->second.id);
00217             entry.setValue(iter->second.value);
00218             entry.setTtl((int)SIMTIME_DBL(
00219                         iter->second.ttlMessage->getArrivalTime() - simTime()));
00220             entry.setOwnerNode(iter->second.sourceNode);
00221             entry.setIs_modifiable(iter->second.is_modifiable);
00222             entry.setResponsible(iter->second.responsible);
00223             vect->push_back(entry);
00224         }
00225     }
00226 
00227     return vect;
00228 }

DhtDataEntry * DHTDataStorage::getDataEntry ( const OverlayKey key,
uint32_t  kind,
uint32_t  id 
)

Returns a pointer to the requested stored data item.

Parameters:
key The key of the data item
kind The kind of the data item
id A random integer to identify multiple items with same key and kind
Returns:
pointer to the data item or NULL if data item is not available

Definition at line 74 of file DHTDataStorage.cc.

Referenced by getSourceNode(), CBRDHT::handleGetRequest(), and isModifiable().

00076 {
00077     pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
00078         dataMap.equal_range(key);
00079 
00080     while (pos.first != pos.second) {
00081         if ((pos.first->second.kind == kind) &&
00082                 (pos.first->second.id == id)) {
00083             return &pos.first->second;
00084         }
00085         ++pos.first;
00086     }
00087 
00088     return NULL;
00089 }

DhtDataVector * DHTDataStorage::getDataVector ( const OverlayKey key,
uint32_t  kind = 0,
uint32_t  id = 0 
) [virtual]

Returns the stored data items with a given key, kind and id.

Parameters:
key The key of the data item
kind The kind of the data item
id A random integer to identify multiple items with same key and kind
Returns:
The value of the data item with the given key

Definition at line 93 of file DHTDataStorage.cc.

00095 {
00096     DhtDataVector* vect = new DhtDataVector();
00097     DhtDataEntry entry;
00098 
00099     pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
00100         dataMap.equal_range(key);
00101 
00102     while (pos.first != pos.second) {
00103         entry = pos.first->second;
00104         vect->push_back(make_pair(key, entry));
00105         ++pos.first;
00106     }
00107 
00108     return vect;
00109 }

uint32_t DHTDataStorage::getSize (  )  [virtual]

Returns number of stored data items in the map.

Returns:
number of stored data items

Definition at line 69 of file DHTDataStorage.cc.

Referenced by DHT::update(), and CBRDHT::update().

00070 {
00071     return dataMap.size();
00072 }

const NodeHandle & DHTDataStorage::getSourceNode ( const OverlayKey key,
uint32_t  kind,
uint32_t  id 
) [virtual]

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

Parameters:
key The key of the data item
kind The kind of the data item
id A random integer to identify multiple items with same key and kind
Returns:
The source node of the data item with the given key

Definition at line 112 of file DHTDataStorage.cc.

Referenced by DHT::handlePutRequest(), and CBRDHT::handlePutRequest().

00114 {
00115     DhtDataEntry* entry = getDataEntry(key, kind, id);
00116 
00117     if (entry == NULL)
00118         return NodeHandle::UNSPECIFIED_NODE;
00119     else
00120         return entry->sourceNode;
00121 }

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

Definition at line 52 of file DHTDataStorage.cc.

00053 {
00054     error("This module doesn't handle messages!");
00055 }

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

Definition at line 44 of file DHTDataStorage.cc.

00045 {
00046     if (stage != MIN_STAGE_APP)
00047         return;
00048 
00049     WATCH_MULTIMAP(dataMap);
00050 }

const bool DHTDataStorage::isModifiable ( const OverlayKey key,
uint32_t  kind,
uint32_t  id 
) [virtual]

Returns a boolean telling if this data if modifiable.

Parameters:
key The key of the data item
kind The kind of the data item
id A random integer to identify multiple items with same key and kind
Returns:
The value of the is_modifiable value

Definition at line 123 of file DHTDataStorage.cc.

Referenced by DHT::handlePutRequest(), and CBRDHT::handlePutRequest().

00125 {
00126     DhtDataEntry* entry = getDataEntry(key, kind, id);
00127 
00128     if (entry == NULL)
00129         return true;
00130     else
00131         return entry->is_modifiable;
00132 }

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

Definition at line 70 of file DHTDataStorage.h.

00071     {
00072         return MAX_STAGE_APP + 1;
00073     }

void DHTDataStorage::removeData ( const OverlayKey key,
uint32_t  kind,
uint32_t  id 
) [virtual]

Removes a certain data item from the map.

Parameters:
key The key of the data item to be removed
kind The kind of the data item
id A random integer to identify multiple items with same key and kind

Definition at line 176 of file DHTDataStorage.cc.

Referenced by DHT::handlePutRequest(), CBRDHT::handlePutRequest(), DHT::handleTimerEvent(), and CBRDHT::handleTimerEvent().

00178 {
00179     pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
00180         dataMap.equal_range(key);
00181 
00182     while (pos.first != pos.second) {
00183 
00184         if (((kind == 0) || (pos.first->second.kind == kind)) &&
00185                 ((id == 0) || (pos.first->second.id == id))) {
00186             cancelAndDelete(pos.first->second.ttlMessage);
00187             dataMap.erase(pos.first++);
00188         } else {
00189             ++pos.first;
00190         }
00191     }
00192 }

void DHTDataStorage::updateDisplayString (  )  [protected]

Displays the current number of successors in the list.

Definition at line 232 of file DHTDataStorage.cc.

00233 {
00234     if (ev.isGUI()) {
00235         char buf[80];
00236 
00237         if (dataMap.size() == 1) {
00238             sprintf(buf, "1 data item");
00239         } else {
00240             sprintf(buf, "%zi data items", dataMap.size());
00241         }
00242 
00243         getDisplayString().setTagArg("t", 0, buf);
00244         getDisplayString().setTagArg("t", 2, "blue");
00245     }
00246 
00247 }

void DHTDataStorage::updateTooltip (  )  [protected]

Displays the first 4 successor nodes as tooltip.

Definition at line 250 of file DHTDataStorage.cc.

00251 {
00252     if (ev.isGUI()) {
00253         std::stringstream str;
00254 
00255         for (DhtDataMap::iterator it = dataMap.begin();
00256              it != dataMap.end(); it++) {
00257             str << it->second.value;
00258         }
00259 
00260         str << endl;
00261 
00262         char buf[1024];
00263         sprintf(buf, "%s", str.str().c_str());
00264         getDisplayString().setTagArg("tt", 0, buf);
00265     }
00266 }


Member Data Documentation

internal representation of the data storage

Definition at line 188 of file DHTDataStorage.h.

Referenced by addData(), begin(), clear(), display(), dumpDht(), getDataEntry(), getDataVector(), getSize(), initialize(), removeData(), updateDisplayString(), and updateTooltip().


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

Generated on Tue Sep 8 17:26:58 2009 for OverSim by  doxygen 1.5.8