#include <DHTDataStorage.h>
Definition at line 71 of file 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. | |
| virtual bool | isEmpty () |
| Checks if the data storage map is empty. | |
| virtual const BinaryValue & | getData (const OverlayKey &key) |
| Returns the value of a stored data item with a given key. | |
| virtual const NodeHandle & | getSourceNode (const OverlayKey &key) |
| Returns the source node of a stored data item with a given key. | |
| virtual cMessage * | getTtlMessage (const OverlayKey &key) |
| Returns the ttlMessage of a stored data item with a given key. | |
| virtual const bool | isModifiable (const OverlayKey &key) |
| Returns a boolean telling if this data if modifiable. | |
| virtual const BinaryValue & | getDataAtPos (uint32_t pos=0) |
| Returns the value of the data item stored at position pos. | |
| virtual const std::map < OverlayKey, DHTData > ::iterator | begin () |
| Returns an iterator to the beginning of the map. | |
| virtual void | addData (OverlayKey key, 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 (OverlayKey key) |
| Removes a certain data item from the map. | |
| void | display () |
| DhtDataVector * | get_range (const OverlayKey lkey, const OverlayKey rkey) |
| Return a vector containing every keys/values between the two bounds. | |
| DhtDumpVector * | dumpDht () |
| Dump all 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 | |
| std::map< OverlayKey, DHTData > | dataMap |
| internal representation of the data storage | |
| virtual int DHTDataStorage::numInitStages | ( | ) | const [inline, virtual] |
| void DHTDataStorage::initialize | ( | int | stage | ) | [virtual] |
Definition at line 41 of file DHTDataStorage.cc.
00042 { 00043 if (stage != MIN_STAGE_APP) 00044 return; 00045 00046 WATCH_MAP(dataMap); 00047 }
| void DHTDataStorage::handleMessage | ( | cMessage * | msg | ) | [virtual] |
| uint32_t DHTDataStorage::getSize | ( | ) | [virtual] |
Returns number of stored data items in the map.
Definition at line 66 of file DHTDataStorage.cc.
Referenced by DHT::update().
00067 { 00068 return dataMap.size(); 00069 }
| void DHTDataStorage::clear | ( | ) | [virtual] |
Clears all stored data items.
Definition at line 54 of file DHTDataStorage.cc.
Referenced by DHT::~DHT().
00055 { 00056 map<OverlayKey, DHTData>::iterator iter; 00057 00058 for( iter = dataMap.begin(); iter != dataMap.end(); iter++ ) { 00059 cancelAndDelete(iter->second.ttlMessage); 00060 } 00061 00062 dataMap.clear(); 00063 }
| bool DHTDataStorage::isEmpty | ( | ) | [virtual] |
Checks if the data storage map is empty.
Definition at line 71 of file DHTDataStorage.cc.
00072 { 00073 if (dataMap.size() == 0) 00074 return true; 00075 else 00076 return false; 00077 }
| const BinaryValue & DHTDataStorage::getData | ( | const OverlayKey & | key | ) | [virtual] |
Returns the value of a stored data item with a given key.
| key | The key of the data item |
Definition at line 79 of file DHTDataStorage.cc.
Referenced by DHT::handleGetRequest().
00079 { 00080 00081 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00082 00083 if (it == dataMap.end()) 00084 return BinaryValue::UNSPECIFIED_VALUE; 00085 else 00086 return it->second.value; 00087 }
| const NodeHandle & DHTDataStorage::getSourceNode | ( | const OverlayKey & | key | ) | [virtual] |
Returns the source node of a stored data item with a given key.
| key | The key of the data item |
Definition at line 89 of file DHTDataStorage.cc.
Referenced by DHT::handlePutRequest().
00089 { 00090 00091 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00092 00093 if (it == dataMap.end()) 00094 return NodeHandle::UNSPECIFIED_NODE; 00095 else 00096 return it->second.sourceNode; 00097 }
| cMessage * DHTDataStorage::getTtlMessage | ( | const OverlayKey & | key | ) | [virtual] |
Returns the ttlMessage of a stored data item with a given key.
| key | The key of the data item |
Definition at line 99 of file DHTDataStorage.cc.
Referenced by DHT::handlePutRequest().
00099 { 00100 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00101 00102 if (it == dataMap.end()) 00103 return NULL; 00104 else 00105 return it->second.ttlMessage; 00106 }
| const bool DHTDataStorage::isModifiable | ( | const OverlayKey & | key | ) | [virtual] |
Returns a boolean telling if this data if modifiable.
| key | The key of the data item |
Definition at line 108 of file DHTDataStorage.cc.
Referenced by DHT::handlePutRequest().
00108 { 00109 00110 std::map<OverlayKey, DHTData>::iterator it = dataMap.find(key); 00111 00112 if (it == dataMap.end()) 00113 return true; 00114 else 00115 return it->second.is_modifiable; 00116 }
| const BinaryValue & DHTDataStorage::getDataAtPos | ( | uint32_t | pos = 0 |
) | [virtual] |
Returns the value of the data item stored at position pos.
| pos | position in data storage map |
Definition at line 119 of file DHTDataStorage.cc.
Referenced by updateTooltip().
00120 { 00121 if (pos >= dataMap.size()) { 00122 error("Index out of bound (DHTDataStorage, getDataAtPos())"); 00123 } 00124 00125 std::map<OverlayKey, DHTData>::iterator it = dataMap.begin(); 00126 00127 for (uint32_t i= 0; i < pos; i++) { 00128 it++; 00129 if (i == (pos-1)) 00130 return it->second.value; 00131 } 00132 00133 return it->second.value; 00134 }
| const std::map< OverlayKey, DHTData >::iterator DHTDataStorage::begin | ( | ) | [virtual] |
Returns an iterator to the beginning of the map.
Definition at line 136 of file DHTDataStorage.cc.
Referenced by DHT::update().
00137 { 00138 return dataMap.begin(); 00139 }
| void DHTDataStorage::addData | ( | OverlayKey | key, | |
| 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 | |
| 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().
00142 { 00143 DHTData entry; 00144 entry.value = value; 00145 entry.ttlMessage = ttlMessage; 00146 entry.sourceNode = sourceNode; 00147 entry.is_modifiable = is_modifiable; 00148 entry.responsible = responsible; 00149 // replace with new value 00150 dataMap.erase(key); 00151 dataMap.insert(make_pair(key, entry)); 00152 }
| void DHTDataStorage::removeData | ( | OverlayKey | key | ) | [virtual] |
Removes a certain data item from the map.
| key | The key of the data item to be removed |
Definition at line 154 of file DHTDataStorage.cc.
Referenced by DHT::handlePutRequest(), and DHT::handleTimerEvent().
00155 { 00156 dataMap.erase(key); 00157 }
| void DHTDataStorage::display | ( | ) |
Definition at line 240 of file DHTDataStorage.cc.
00241 { 00242 cout << "Content of DHTDataStorage:" << endl; 00243 for (std::map<OverlayKey, DHTData>::iterator it = dataMap.begin(); 00244 it != dataMap.end(); it++) { 00245 cout << "Key: " << it->first << " Value: " << it->second.value << "End-time: " << it->second.ttlMessage->getArrivalTime() << endl; 00246 } 00247 }
| DhtDataVector * DHTDataStorage::get_range | ( | const OverlayKey | lkey, | |
| const OverlayKey | rkey | |||
| ) |
Return a vector containing every keys/values between the two bounds.
| lkey | The beginning of the range | |
| rkey | The end of the range |
Definition at line 159 of file DHTDataStorage.cc.
00160 { 00161 DhtDataVector* vect = new DhtDataVector(); 00162 map<OverlayKey, DHTData>::iterator iter; 00163 if (lkey > rkey) { //the zero key is between this to keys 00164 //we fetch everything after lkey 00165 for( iter = dataMap.lower_bound(lkey); iter != dataMap.end(); iter++ ) { 00166 vect->insert(vect->end(), std::make_pair(iter->first, iter->second)); 00167 } 00168 //and everything before rkey 00169 for( iter = dataMap.upper_bound(rkey); iter != (dataMap.begin()--); iter-- ) { 00170 vect->insert(vect->end(), std::make_pair(iter->first, iter->second)); 00171 } 00172 } 00173 else { 00174 for (iter = dataMap.lower_bound(lkey); iter != (dataMap.upper_bound(rkey) ++); iter++) { 00175 vect->insert(vect->end(), std::make_pair(iter->first, iter->second)); 00176 } 00177 } 00178 00179 return vect; 00180 }
| DhtDumpVector * DHTDataStorage::dumpDht | ( | ) |
Dump all local data records into a vector.
Definition at line 182 of file DHTDataStorage.cc.
Referenced by DHT::handleDumpDhtRequest().
00183 { 00184 DhtDumpVector* vect = new DhtDumpVector(); 00185 DhtDumpEntry entry; 00186 00187 map<OverlayKey, DHTData>::iterator iter; 00188 00189 for (iter = dataMap.begin(); iter != dataMap.end(); iter++) { 00190 entry.key = iter->first; 00191 entry.value = iter->second.value; 00192 entry.ttl = (int)SIMTIME_DBL(iter->second.ttlMessage->getArrivalTime() - simTime()); 00193 entry.owner = iter->second.sourceNode; 00194 entry.is_modifiable = iter->second.is_modifiable; 00195 entry.responsible = iter->second.responsible; 00196 vect->push_back(entry); 00197 } 00198 00199 return vect; 00200 }
| void DHTDataStorage::updateDisplayString | ( | ) | [protected] |
Displays the current number of successors in the list.
Definition at line 203 of file DHTDataStorage.cc.
00204 { 00205 // FIXME: doesn't work without tcl/tk 00206 // if (ev.isGUI()) { 00207 if (ev.isGUI()) { 00208 char buf[80]; 00209 00210 if (dataMap.size() == 1) { 00211 sprintf(buf, "1 data item"); 00212 } else { 00213 sprintf(buf, "%zi data items", dataMap.size()); 00214 } 00215 00216 getDisplayString().setTagArg("t", 0, buf); 00217 getDisplayString().setTagArg("t", 2, "blue"); 00218 } 00219 00220 }
| void DHTDataStorage::updateTooltip | ( | ) | [protected] |
Displays the first 4 successor nodes as tooltip.
Definition at line 222 of file DHTDataStorage.cc.
00223 { 00224 if (ev.isGUI()) { 00225 std::stringstream str; 00226 for (uint32_t i = 0; i < dataMap.size(); i++) { 00227 str << getDataAtPos(i); 00228 00229 if ( i != dataMap.size() - 1 ) 00230 str << endl; 00231 } 00232 00233 00234 char buf[1024]; 00235 sprintf(buf, "%s", str.str().c_str()); 00236 getDisplayString().setTagArg("tt", 0, buf); 00237 } 00238 }
std::map<OverlayKey, DHTData> DHTDataStorage::dataMap [protected] |
internal representation of the data storage
Definition at line 183 of file DHTDataStorage.h.
Referenced by addData(), begin(), clear(), display(), dumpDht(), get_range(), getData(), getDataAtPos(), getSize(), getSourceNode(), getTtlMessage(), initialize(), isEmpty(), isModifiable(), removeData(), updateDisplayString(), and updateTooltip().
1.5.5