OverSim
DHTDataStorage Class Reference

#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.
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
keyThe key of the data item to be stored
kindThe kind of the data item
idA random integer to identify multiple items with same key and kind
valueThe value of the data item to be stored
ttlMessageThe self-message sent for the ttl expiration
is_modifiableFlag that tell if the data can be change by anyone, or just by the sourceNode
sourceNodeNode which asked to store the value
responsible

Definition at line 155 of file DHTDataStorage.cc.

{
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.

Returns
An iterator

Definition at line 145 of file DHTDataStorage.cc.

{
return dataMap.begin();
}
void DHTDataStorage::clear ( )
virtual

Clears all stored data items.

Definition at line 67 of file DHTDataStorage.cc.

{
map<OverlayKey, DhtDataEntry>::iterator iter;
for( iter = dataMap.begin(); iter != dataMap.end(); iter++ ) {
cancelAndDelete(iter->second.ttlMessage);
}
dataMap.clear();
}
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.

Parameters
keyThe key of the data items to dump
kindThe kind of the data items to dump
idThe id of the data items to dump
Returns
the vector containing all matching data items

Definition at line 209 of file DHTDataStorage.cc.

{
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.

Returns
An iterator

Definition at line 150 of file DHTDataStorage.cc.

{
return dataMap.end();
}
DhtDataEntry * DHTDataStorage::getDataEntry ( const OverlayKey key,
uint32_t  kind,
uint32_t  id 
)

Returns a pointer to the requested stored data item.

Parameters
keyThe key of the data item
kindThe kind of the data item
idA 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.

{
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.

Parameters
keyThe key of the data item
kindThe kind of the data item
idA 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.

{
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.

Returns
number of stored data items

Definition at line 79 of file DHTDataStorage.cc.

{
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.

Parameters
keyThe key of the data item
kindThe kind of the data item
idA 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.

{
DhtDataEntry* entry = getDataEntry(key, kind, id);
if (entry == NULL)
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;
}
const bool DHTDataStorage::isModifiable ( const OverlayKey key,
uint32_t  kind,
uint32_t  id 
)
virtual

Returns a boolean telling if this data if modifiable.

Parameters
keyThe key of the data item
kindThe kind of the data item
idA 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.

{
DhtDataEntry* entry = getDataEntry(key, kind, id);
if (entry == NULL)
return true;
else
return entry->is_modifiable;
}
virtual int DHTDataStorage::numInitStages ( ) const
inlinevirtual

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.

Parameters
keyThe key of the data item to be removed
kindThe kind of the data item
idA random integer to identify multiple items with same key and kind

Definition at line 191 of file DHTDataStorage.cc.

{
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.

{
if (ev.isGUI()) {
char buf[80];
if (dataMap.size() == 1) {
sprintf(buf, "1 data item");
} else {
sprintf(buf, "%zi data items", dataMap.size());
}
getDisplayString().setTagArg("t", 0, buf);
getDisplayString().setTagArg("t", 2, "blue");
}
}
void DHTDataStorage::updateTooltip ( )
protected

Displays the first 4 successor nodes as tooltip.

Definition at line 265 of file DHTDataStorage.cc.

{
if (ev.isGUI()) {
std::stringstream str;
for (DhtDataMap::iterator it = dataMap.begin();
it != dataMap.end(); it++) {
str << it->second.value;
}
str << endl;
char buf[1024];
sprintf(buf, "%s", str.str().c_str());
getDisplayString().setTagArg("tt", 0, buf);
}
}

Member Data Documentation

DhtDataMap DHTDataStorage::dataMap
protected

internal representation of the data storage

Definition at line 199 of file DHTDataStorage.h.


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