#include <GlobalDhtTestMap.h>
Definition at line 49 of file GlobalDhtTestMap.h.
Public Member Functions | |
| GlobalDhtTestMap () | |
| ~GlobalDhtTestMap () | |
| void | insertEntry (const OverlayKey &key, const DHTEntry &entry) |
| const DHTEntry * | findEntry (const OverlayKey &key) |
| void | eraseEntry (const OverlayKey &key) |
| const OverlayKey & | getRandomKey () |
Private Member Functions | |
| void | initialize () |
| void | handleMessage (cMessage *msg) |
| void | finish () |
Private Attributes | |
| GlobalStatistics * | globalStatistics |
| pointer to GlobalStatistics module in this node | |
| std::map< OverlayKey, DHTEntry > | dataMap |
| The map contains all currently stored DHT records. | |
| cMessage * | periodicTimer |
| timer self-message for writing periodic statistical information | |
Static Private Attributes | |
| static const int | TEST_MAP_INTERVAL = 10 |
| interval in seconds for writing periodic statistical information | |
| GlobalDhtTestMap::GlobalDhtTestMap | ( | ) |
| GlobalDhtTestMap::~GlobalDhtTestMap | ( | ) |
Definition at line 47 of file GlobalDhtTestMap.cc.
00048 { 00049 cancelAndDelete(periodicTimer); 00050 dataMap.clear(); 00051 }
| void GlobalDhtTestMap::insertEntry | ( | const OverlayKey & | key, | |
| const DHTEntry & | entry | |||
| ) |
Definition at line 85 of file GlobalDhtTestMap.cc.
Referenced by DHTTestApp::handlePutResponse().
00086 { 00087 Enter_Method_Silent(); 00088 00089 dataMap.erase(key); 00090 dataMap.insert(make_pair(key, entry)); 00091 00092 DhtTestEntryTimer* msg = new DhtTestEntryTimer("dhtEntryTimer"); 00093 msg->setKey(key); 00094 00095 scheduleAt(entry.endtime, msg); 00096 }
| const DHTEntry * GlobalDhtTestMap::findEntry | ( | const OverlayKey & | key | ) |
Definition at line 103 of file GlobalDhtTestMap.cc.
Referenced by DHTTestApp::handleGetResponse().
00104 { 00105 std::map<OverlayKey, DHTEntry>::iterator it = dataMap.find(key); 00106 00107 if (it == dataMap.end()) { 00108 return NULL; 00109 } else { 00110 return &(it->second); 00111 } 00112 }
| void GlobalDhtTestMap::eraseEntry | ( | const OverlayKey & | key | ) |
Definition at line 98 of file GlobalDhtTestMap.cc.
Referenced by DHTTestApp::handleGetResponse().
00099 { 00100 dataMap.erase(key); 00101 }
| const OverlayKey & GlobalDhtTestMap::getRandomKey | ( | ) |
Definition at line 114 of file GlobalDhtTestMap.cc.
Referenced by DHTTestApp::handleTimerEvent().
00115 { 00116 if (dataMap.size() == 0) { 00117 return OverlayKey::UNSPECIFIED_KEY; 00118 } 00119 00120 // return random OverlayKey in O(log n) 00121 std::map<OverlayKey, DHTEntry>::iterator it = dataMap.end(); 00122 DHTEntry tempEntry = {BinaryValue::UNSPECIFIED_VALUE, 0}; 00123 00124 OverlayKey randomKey = OverlayKey::random(); 00125 it = dataMap.find(randomKey); 00126 00127 if (it == dataMap.end()) { 00128 it = dataMap.insert(make_pair(randomKey, tempEntry)).first; 00129 dataMap.erase(it++); 00130 } 00131 00132 if (it == dataMap.end()) { 00133 it = dataMap.begin(); 00134 } 00135 00136 return it->first; 00137 }
| void GlobalDhtTestMap::initialize | ( | ) | [private] |
Definition at line 53 of file GlobalDhtTestMap.cc.
00054 { 00055 globalStatistics = GlobalStatisticsAccess().get(); 00056 WATCH_MAP(dataMap); 00057 00058 periodicTimer = new cMessage("dhtTestMapTimer"); 00059 00060 scheduleAt(simTime(), periodicTimer); 00061 }
| void GlobalDhtTestMap::handleMessage | ( | cMessage * | msg | ) | [private] |
Definition at line 67 of file GlobalDhtTestMap.cc.
00068 { 00069 //cleanupDataMap(); 00070 DhtTestEntryTimer *entryTimer = NULL; 00071 00072 if (msg == periodicTimer) { 00073 RECORD_STATS(globalStatistics->recordOutVector( 00074 "GlobalDhtTestMap: Number of stored DHT entries", dataMap.size())); 00075 scheduleAt(simTime() + TEST_MAP_INTERVAL, msg); 00076 } else if ((entryTimer = dynamic_cast<DhtTestEntryTimer*>(msg)) != NULL) { 00077 dataMap.erase(entryTimer->getKey()); 00078 delete msg; 00079 } else { 00080 throw cRuntimeError("GlobalDhtTestMap::handleMessage(): " 00081 "Unknown message type!"); 00082 } 00083 }
| void GlobalDhtTestMap::finish | ( | ) | [private] |
const int GlobalDhtTestMap::TEST_MAP_INTERVAL = 10 [static, private] |
interval in seconds for writing periodic statistical information
Definition at line 95 of file GlobalDhtTestMap.h.
Referenced by handleMessage().
pointer to GlobalStatistics module in this node
Definition at line 97 of file GlobalDhtTestMap.h.
Referenced by handleMessage(), and initialize().
std::map<OverlayKey, DHTEntry> GlobalDhtTestMap::dataMap [private] |
The map contains all currently stored DHT records.
Definition at line 98 of file GlobalDhtTestMap.h.
Referenced by eraseEntry(), findEntry(), getRandomKey(), handleMessage(), initialize(), insertEntry(), and ~GlobalDhtTestMap().
cMessage* GlobalDhtTestMap::periodicTimer [private] |
timer self-message for writing periodic statistical information
Definition at line 99 of file GlobalDhtTestMap.h.
Referenced by GlobalDhtTestMap(), handleMessage(), initialize(), and ~GlobalDhtTestMap().
1.5.5