#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.
|
Detailed Description
Definition at line 68 of file DHTDataStorage.h.
Member Function Documentation
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.
{
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 =
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.
void DHTDataStorage::clear |
( |
| ) |
|
|
virtual |
Clears all stored data items.
Definition at line 67 of file DHTDataStorage.cc.
{
map<OverlayKey, DhtDataEntry>::iterator iter;
cancelAndDelete(iter->second.ttlMessage);
}
}
void DHTDataStorage::display |
( |
| ) |
|
Definition at line 284 of file DHTDataStorage.cc.
{
cout << "Content of DHTDataStorage:" << endl;
for (DhtDataMap::iterator it =
dataMap.begin();
cout << "Key: " << it->first << " Kind: " << it->second.kind
<< " ID: " << it->second.id << " Value: "
<< it->second.value << "End-time: "
<< it->second.ttlMessage->getArrivalTime() << endl;
}
}
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.
{
DhtDataMap::iterator iter,
end;
} else {
}
for (; iter !=
end; iter++) {
if (((kind == 0) || (iter->second.kind == kind)) &&
((id == 0) || (iter->second.id == id))) {
entry.
setId(iter->second.id);
entry.
setTtl((
int)SIMTIME_DBL(
iter->second.ttlMessage->getArrivalTime() - simTime()));
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.
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.
{
pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
while (pos.first != pos.second) {
if ((pos.first->second.kind == kind) &&
(pos.first->second.id == id)) {
return &pos.first->second;
}
++pos.first;
}
return NULL;
}
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.
{
pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
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.
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.
{
if (entry == NULL)
else
}
void DHTDataStorage::handleMessage |
( |
cMessage * |
msg | ) |
|
|
virtual |
void DHTDataStorage::initialize |
( |
int |
stage | ) |
|
|
virtual |
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.
{
if (entry == NULL)
return true;
else
}
virtual int DHTDataStorage::numInitStages |
( |
| ) |
const |
|
inlinevirtual |
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.
{
pair<DhtDataMap::iterator, DhtDataMap::iterator> pos =
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);
} 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];
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();
str << it->second.value;
}
str << endl;
char buf[1024];
sprintf(buf, "%s", str.str().c_str());
getDisplayString().setTagArg("tt", 0, buf);
}
}
Member Data Documentation
The documentation for this class was generated from the following files: