#include <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 | ( | ) |
void GlobalDhtTestMap::insertEntry | ( | const OverlayKey & | key, | |
const DHTEntry & | entry | |||
) |
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 | ) |
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 | ) |
const OverlayKey & GlobalDhtTestMap::getRandomKey | ( | ) |
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] |
00054 { 00055 globalStatistics = GlobalStatisticsAccess().get(); 00056 WATCH_MAP(dataMap); 00057 00058 periodicTimer = new cMessage("dhtTestMapTimer"); 00059 00060 scheduleAt(simulation.simTime(), periodicTimer); 00061 }
void GlobalDhtTestMap::handleMessage | ( | cMessage * | msg | ) | [private] |
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(simulation.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 new cRuntimeError("GlobalDhtTestMap::handleMessage(): " 00081 "Unknown message type!"); 00082 } 00083 }
const int GlobalDhtTestMap::TEST_MAP_INTERVAL = 10 [static, private] |
std::map<OverlayKey, DHTEntry> GlobalDhtTestMap::dataMap [private] |
The map contains all currently stored DHT records.
Referenced by eraseEntry(), findEntry(), getRandomKey(), handleMessage(), initialize(), insertEntry(), and ~GlobalDhtTestMap().
cMessage* GlobalDhtTestMap::periodicTimer [private] |
timer self-message for writing periodic statistical information
Referenced by GlobalDhtTestMap(), handleMessage(), initialize(), and ~GlobalDhtTestMap().