#include <DHTDataStorage.h>
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. | |
DhtDataEntry * | getDataEntry (const OverlayKey &key, uint32_t kind, uint32_t id) |
Returns a pointer to the requested stored data item. | |
virtual DhtDataVector * | getDataVector (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 NodeHandle & | getSourceNode (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 DhtDataEntry * | 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 () |
DhtDumpVector * | dumpDht (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 |
Definition at line 68 of file DHTDataStorage.h.
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.
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().
{ DhtDataEntry entry; entry.kind = kind; entry.id = id; entry.value = value; entry.ttlMessage = ttlMessage; entry.sourceNode = sourceNode; entry.is_modifiable = is_modifiable; entry.responsible = responsible; if ((kind == 0) || (id == 0)) { throw cRuntimeError("DHTDataStorage::addData(): " "Not allowed to add data with kind = 0 or id = 0!"); } pair<DhtDataMap::iterator, DhtDataMap::iterator> pos = dataMap.equal_range(key); // insert new record in sorted multimap (order: key, kind, id) while ((pos.first != pos.second) && (pos.first->second.kind < kind)) { ++pos.first; } while ((pos.first != pos.second) && (pos.first->second.kind == kind) && (pos.first->second.id < id)) { ++pos.first; } return &(dataMap.insert(pos.first, make_pair(key, entry))->second); }
const DhtDataMap::iterator DHTDataStorage::begin | ( | ) | [virtual] |
Returns an iterator to the beginning of the map.
Definition at line 145 of file DHTDataStorage.cc.
Referenced by DHT::update(), and CBRDHT::update().
{ return dataMap.begin(); }
void DHTDataStorage::clear | ( | ) | [virtual] |
Clears all stored data items.
Definition at line 67 of file DHTDataStorage.cc.
Referenced by CBRDHT::~CBRDHT(), and DHT::~DHT().
void DHTDataStorage::display | ( | ) |
Definition at line 284 of file DHTDataStorage.cc.
{ cout << "Content of DHTDataStorage:" << endl; for (DhtDataMap::iterator it = dataMap.begin(); it != dataMap.end(); it++) { cout << "Key: " << it->first << " Kind: " << it->second.kind << " ID: " << it->second.id << " Value: " << it->second.value << "End-time: " << it->second.ttlMessage->getArrivalTime() << endl; } }
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.
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 |
Definition at line 209 of file DHTDataStorage.cc.
Referenced by DHT::handleDumpDhtRequest(), CBRDHT::handleDumpDhtRequest(), and DHT::handleGetRequest().
{ DhtDumpVector* vect = new DhtDumpVector(); DhtDumpEntry entry; DhtDataMap::iterator iter, end; if (key.isUnspecified()) { iter = dataMap.begin(); end = dataMap.end(); } else { iter = dataMap.lower_bound(key); end = dataMap.upper_bound(key); } for (; iter != end; iter++) { if (((kind == 0) || (iter->second.kind == kind)) && ((id == 0) || (iter->second.id == id))) { entry.setKey(iter->first); entry.setKind(iter->second.kind); entry.setId(iter->second.id); entry.setValue(iter->second.value); entry.setTtl((int)SIMTIME_DBL( iter->second.ttlMessage->getArrivalTime() - simTime())); entry.setOwnerNode(iter->second.sourceNode); entry.setIs_modifiable(iter->second.is_modifiable); entry.setResponsible(iter->second.responsible); vect->push_back(entry); } } return vect; }
const DhtDataMap::iterator DHTDataStorage::end | ( | ) | [virtual] |
Returns an iterator to the end of the map.
Definition at line 150 of file DHTDataStorage.cc.
Referenced by DHT::update().
{ return dataMap.end(); }
DhtDataEntry * DHTDataStorage::getDataEntry | ( | const OverlayKey & | key, | |
uint32_t | kind, | |||
uint32_t | id | |||
) |
Returns a pointer to the requested stored data item.
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 |
Definition at line 84 of file DHTDataStorage.cc.
Referenced by getSourceNode(), CBRDHT::handleGetRequest(), DHT::handlePutRequest(), and isModifiable().
{ pair<DhtDataMap::iterator, DhtDataMap::iterator> pos = dataMap.equal_range(key); while (pos.first != pos.second) { if ((pos.first->second.kind == kind) && (pos.first->second.id == id)) { return &pos.first->second; } ++pos.first; } return NULL; }
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.
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 |
Definition at line 103 of file DHTDataStorage.cc.
{ DhtDataVector* vect = new DhtDataVector(); DhtDataEntry entry; pair<DhtDataMap::iterator, DhtDataMap::iterator> pos = dataMap.equal_range(key); while (pos.first != pos.second) { entry = pos.first->second; vect->push_back(make_pair(key, entry)); ++pos.first; } return vect; }
uint32_t DHTDataStorage::getSize | ( | ) | [virtual] |
Returns number of stored data items in the map.
Definition at line 79 of file DHTDataStorage.cc.
Referenced by CBRDHT::update().
{ return dataMap.size(); }
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.
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 |
Definition at line 122 of file DHTDataStorage.cc.
Referenced by DHT::handlePutRequest(), and CBRDHT::handlePutRequest().
{ DhtDataEntry* entry = getDataEntry(key, kind, id); if (entry == NULL) return NodeHandle::UNSPECIFIED_NODE; else return entry->sourceNode; }
void DHTDataStorage::handleMessage | ( | cMessage * | msg | ) | [virtual] |
Definition at line 62 of file DHTDataStorage.cc.
{ error("This module doesn't handle messages!"); }
void DHTDataStorage::initialize | ( | int | stage | ) | [virtual] |
Definition at line 54 of file DHTDataStorage.cc.
{ if (stage != MIN_STAGE_APP) return; WATCH_MULTIMAP(dataMap); }
const bool DHTDataStorage::isModifiable | ( | const OverlayKey & | key, | |
uint32_t | kind, | |||
uint32_t | id | |||
) | [virtual] |
Returns a boolean telling if this data if modifiable.
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 |
Definition at line 133 of file DHTDataStorage.cc.
Referenced by DHT::handlePutRequest(), and CBRDHT::handlePutRequest().
{ DhtDataEntry* entry = getDataEntry(key, kind, id); if (entry == NULL) return true; else return entry->is_modifiable; }
virtual int DHTDataStorage::numInitStages | ( | ) | const [inline, virtual] |
Definition at line 72 of file DHTDataStorage.h.
{ return MAX_STAGE_APP + 1; }
void DHTDataStorage::removeData | ( | const OverlayKey & | key, | |
uint32_t | kind, | |||
uint32_t | id | |||
) | [virtual] |
Removes a certain data item from the map.
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().
{ pair<DhtDataMap::iterator, DhtDataMap::iterator> pos = dataMap.equal_range(key); while (pos.first != pos.second) { if (((kind == 0) || (pos.first->second.kind == kind)) && ((id == 0) || (pos.first->second.id == id))) { cancelAndDelete(pos.first->second.ttlMessage); dataMap.erase(pos.first++); } else { ++pos.first; } } }
void DHTDataStorage::updateDisplayString | ( | ) | [protected] |
Displays the current number of successors in the list.
Definition at line 247 of file DHTDataStorage.cc.
void DHTDataStorage::updateTooltip | ( | ) | [protected] |
Displays the first 4 successor nodes as tooltip.
Definition at line 265 of file DHTDataStorage.cc.
DhtDataMap DHTDataStorage::dataMap [protected] |
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().