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 const DhtDataMap::iterator end ()
 Returns an iterator to the end of the map.
virtual DhtDataEntryaddData (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 68 of file DHTDataStorage.h.


Member Function Documentation

DhtDataEntry * 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 155 of file DHTDataStorage.cc.

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

00160 {
00161     DhtDataEntry entry;
00162     entry.kind = kind;
00163     entry.id = id;
00164     entry.value = value;
00165     entry.ttlMessage = ttlMessage;
00166     entry.sourceNode = sourceNode;
00167     entry.is_modifiable = is_modifiable;
00168     entry.responsible = responsible;
00169 
00170     if ((kind == 0) || (id == 0)) {
00171         throw cRuntimeError("DHTDataStorage::addData(): "
00172                             "Not allowed to add data with kind = 0 or id = 0!");
00173     }
00174 
00175     pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
00176         dataMap.equal_range(key);
00177 
00178     // insert new record in sorted multimap (order: key, kind, id)
00179     while ((pos.first != pos.second) && (pos.first->second.kind < kind)) {
00180         ++pos.first;
00181     }
00182 
00183     while ((pos.first != pos.second) && (pos.first->second.kind == kind)
00184             && (pos.first->second.id < id)) {
00185         ++pos.first;
00186     }
00187 
00188     return &(dataMap.insert(pos.first, make_pair(key, entry))->second);
00189 }

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

Returns an iterator to the beginning of the map.

Returns:
An iterator

Definition at line 145 of file DHTDataStorage.cc.

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

00146 {
00147     return dataMap.begin();
00148 }

void DHTDataStorage::clear (  )  [virtual]

Clears all stored data items.

Definition at line 67 of file DHTDataStorage.cc.

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

00068 {
00069     map<OverlayKey, DhtDataEntry>::iterator iter;
00070 
00071     for( iter = dataMap.begin(); iter != dataMap.end(); iter++ ) {
00072         cancelAndDelete(iter->second.ttlMessage);
00073     }
00074 
00075     dataMap.clear();
00076 }

void DHTDataStorage::display (  ) 

Definition at line 284 of file DHTDataStorage.cc.

00285 {
00286     cout << "Content of DHTDataStorage:" << endl;
00287     for (DhtDataMap::iterator it = dataMap.begin();
00288          it != dataMap.end(); it++) {
00289         cout << "Key: " << it->first << " Kind: " << it->second.kind
00290              << " ID: " << it->second.id << " Value: "
00291              << it->second.value << "End-time: "
00292              << it->second.ttlMessage->getArrivalTime() << endl;
00293     }
00294 }

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 209 of file DHTDataStorage.cc.

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

00211 {
00212     DhtDumpVector* vect = new DhtDumpVector();
00213     DhtDumpEntry entry;
00214 
00215     DhtDataMap::iterator iter, end;
00216 
00217     if (key.isUnspecified()) {
00218         iter = dataMap.begin();
00219         end = dataMap.end();
00220     } else {
00221         iter = dataMap.lower_bound(key);
00222         end = dataMap.upper_bound(key);
00223     }
00224 
00225     for (; iter != end; iter++) {
00226         if (((kind == 0) || (iter->second.kind == kind)) &&
00227                 ((id == 0) || (iter->second.id == id))) {
00228 
00229             entry.setKey(iter->first);
00230             entry.setKind(iter->second.kind);
00231             entry.setId(iter->second.id);
00232             entry.setValue(iter->second.value);
00233             entry.setTtl((int)SIMTIME_DBL(
00234                         iter->second.ttlMessage->getArrivalTime() - simTime()));
00235             entry.setOwnerNode(iter->second.sourceNode);
00236             entry.setIs_modifiable(iter->second.is_modifiable);
00237             entry.setResponsible(iter->second.responsible);
00238             vect->push_back(entry);
00239         }
00240     }
00241 
00242     return vect;
00243 }

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

Returns an iterator to the end of the map.

Returns:
An iterator

Definition at line 150 of file DHTDataStorage.cc.

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

00151 {
00152     return dataMap.end();
00153 }

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 84 of file DHTDataStorage.cc.

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

00086 {
00087     pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
00088         dataMap.equal_range(key);
00089 
00090     while (pos.first != pos.second) {
00091         if ((pos.first->second.kind == kind) &&
00092                 (pos.first->second.id == id)) {
00093             return &pos.first->second;
00094         }
00095         ++pos.first;
00096     }
00097 
00098     return NULL;
00099 }

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 103 of file DHTDataStorage.cc.

00105 {
00106     DhtDataVector* vect = new DhtDataVector();
00107     DhtDataEntry entry;
00108 
00109     pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
00110         dataMap.equal_range(key);
00111 
00112     while (pos.first != pos.second) {
00113         entry = pos.first->second;
00114         vect->push_back(make_pair(key, entry));
00115         ++pos.first;
00116     }
00117 
00118     return vect;
00119 }

uint32_t DHTDataStorage::getSize (  )  [virtual]

Returns number of stored data items in the map.

Returns:
number of stored data items

Definition at line 79 of file DHTDataStorage.cc.

Referenced by CBRDHT::update().

00080 {
00081     return dataMap.size();
00082 }

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 122 of file DHTDataStorage.cc.

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

00124 {
00125     DhtDataEntry* entry = getDataEntry(key, kind, id);
00126 
00127     if (entry == NULL)
00128         return NodeHandle::UNSPECIFIED_NODE;
00129     else
00130         return entry->sourceNode;
00131 }

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

Definition at line 62 of file DHTDataStorage.cc.

00063 {
00064     error("This module doesn't handle messages!");
00065 }

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

Definition at line 54 of file DHTDataStorage.cc.

00055 {
00056     if (stage != MIN_STAGE_APP)
00057         return;
00058 
00059     WATCH_MULTIMAP(dataMap);
00060 }

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 133 of file DHTDataStorage.cc.

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

00135 {
00136     DhtDataEntry* entry = getDataEntry(key, kind, id);
00137 
00138     if (entry == NULL)
00139         return true;
00140     else
00141         return entry->is_modifiable;
00142 }

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

Definition at line 72 of file DHTDataStorage.h.

00073     {
00074         return MAX_STAGE_APP + 1;
00075     }

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 191 of file DHTDataStorage.cc.

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

00193 {
00194     pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
00195         dataMap.equal_range(key);
00196 
00197     while (pos.first != pos.second) {
00198 
00199         if (((kind == 0) || (pos.first->second.kind == kind)) &&
00200                 ((id == 0) || (pos.first->second.id == id))) {
00201             cancelAndDelete(pos.first->second.ttlMessage);
00202             dataMap.erase(pos.first++);
00203         } else {
00204             ++pos.first;
00205         }
00206     }
00207 }

void DHTDataStorage::updateDisplayString (  )  [protected]

Displays the current number of successors in the list.

Definition at line 247 of file DHTDataStorage.cc.

00248 {
00249     if (ev.isGUI()) {
00250         char buf[80];
00251 
00252         if (dataMap.size() == 1) {
00253             sprintf(buf, "1 data item");
00254         } else {
00255             sprintf(buf, "%zi data items", dataMap.size());
00256         }
00257 
00258         getDisplayString().setTagArg("t", 0, buf);
00259         getDisplayString().setTagArg("t", 2, "blue");
00260     }
00261 
00262 }

void DHTDataStorage::updateTooltip (  )  [protected]

Displays the first 4 successor nodes as tooltip.

Definition at line 265 of file DHTDataStorage.cc.

00266 {
00267     if (ev.isGUI()) {
00268         std::stringstream str;
00269 
00270         for (DhtDataMap::iterator it = dataMap.begin();
00271              it != dataMap.end(); it++) {
00272             str << it->second.value;
00273         }
00274 
00275         str << endl;
00276 
00277         char buf[1024];
00278         sprintf(buf, "%s", str.str().c_str());
00279         getDisplayString().setTagArg("tt", 0, buf);
00280     }
00281 }


Member Data Documentation

internal representation of the data storage

Definition at line 199 of file DHTDataStorage.h.

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


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