Module with a global view on all currently stored DHT records (used by DHTTestApp). More...
#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 () |
size_t | size () |
Public Attributes | |
uint32_t | p2pnsNameCount |
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 |
Module with a global view on all currently stored DHT records (used by DHTTestApp).
Definition at line 49 of file GlobalDhtTestMap.h.
GlobalDhtTestMap::GlobalDhtTestMap | ( | ) |
Definition at line 42 of file GlobalDhtTestMap.cc.
00043 { 00044 periodicTimer = NULL; 00045 }
GlobalDhtTestMap::~GlobalDhtTestMap | ( | ) |
Definition at line 47 of file GlobalDhtTestMap.cc.
00048 { 00049 cancelAndDelete(periodicTimer); 00050 dataMap.clear(); 00051 }
void GlobalDhtTestMap::eraseEntry | ( | const OverlayKey & | key | ) |
Definition at line 99 of file GlobalDhtTestMap.cc.
Referenced by DHTTestApp::handleGetResponse().
00100 { 00101 dataMap.erase(key); 00102 }
const DHTEntry * GlobalDhtTestMap::findEntry | ( | const OverlayKey & | key | ) |
Definition at line 104 of file GlobalDhtTestMap.cc.
Referenced by DHTTestApp::handleGetResponse().
void GlobalDhtTestMap::finish | ( | ) | [private] |
Definition at line 64 of file GlobalDhtTestMap.cc.
const OverlayKey & GlobalDhtTestMap::getRandomKey | ( | ) |
Definition at line 115 of file GlobalDhtTestMap.cc.
Referenced by DHTTestApp::handleTimerEvent().
00116 { 00117 if (dataMap.size() == 0) { 00118 return OverlayKey::UNSPECIFIED_KEY; 00119 } 00120 00121 // return random OverlayKey in O(log n) 00122 std::map<OverlayKey, DHTEntry>::iterator it = dataMap.end(); 00123 DHTEntry tempEntry = {BinaryValue::UNSPECIFIED_VALUE, 0}; 00124 00125 OverlayKey randomKey = OverlayKey::random(); 00126 it = dataMap.find(randomKey); 00127 00128 if (it == dataMap.end()) { 00129 it = dataMap.insert(make_pair(randomKey, tempEntry)).first; 00130 dataMap.erase(it++); 00131 } 00132 00133 if (it == dataMap.end()) { 00134 it = dataMap.begin(); 00135 } 00136 00137 return it->first; 00138 }
void GlobalDhtTestMap::handleMessage | ( | cMessage * | msg | ) | [private] |
Definition at line 68 of file GlobalDhtTestMap.cc.
00069 { 00070 //cleanupDataMap(); 00071 DhtTestEntryTimer *entryTimer = NULL; 00072 00073 if (msg == periodicTimer) { 00074 RECORD_STATS(globalStatistics->recordOutVector( 00075 "GlobalDhtTestMap: Number of stored DHT entries", dataMap.size())); 00076 scheduleAt(simTime() + TEST_MAP_INTERVAL, msg); 00077 } else if ((entryTimer = dynamic_cast<DhtTestEntryTimer*>(msg)) != NULL) { 00078 dataMap.erase(entryTimer->getKey()); 00079 delete msg; 00080 } else { 00081 throw cRuntimeError("GlobalDhtTestMap::handleMessage(): " 00082 "Unknown message type!"); 00083 } 00084 }
void GlobalDhtTestMap::initialize | ( | ) | [private] |
Definition at line 53 of file GlobalDhtTestMap.cc.
00054 { 00055 p2pnsNameCount = 0; 00056 globalStatistics = GlobalStatisticsAccess().get(); 00057 WATCH_MAP(dataMap); 00058 00059 periodicTimer = new cMessage("dhtTestMapTimer"); 00060 00061 scheduleAt(simTime(), periodicTimer); 00062 }
void GlobalDhtTestMap::insertEntry | ( | const OverlayKey & | key, | |
const DHTEntry & | entry | |||
) |
Definition at line 86 of file GlobalDhtTestMap.cc.
Referenced by DHTTestApp::handlePutResponse().
size_t GlobalDhtTestMap::size | ( | ) | [inline] |
Definition at line 90 of file GlobalDhtTestMap.h.
00090 { return dataMap.size(); };
std::map<OverlayKey, DHTEntry> GlobalDhtTestMap::dataMap [private] |
The map contains all currently stored DHT records.
Definition at line 101 of file GlobalDhtTestMap.h.
Referenced by eraseEntry(), findEntry(), getRandomKey(), handleMessage(), initialize(), insertEntry(), size(), and ~GlobalDhtTestMap().
pointer to GlobalStatistics module in this node
Definition at line 100 of file GlobalDhtTestMap.h.
Referenced by handleMessage(), and initialize().
uint32_t GlobalDhtTestMap::p2pnsNameCount |
Definition at line 90 of file GlobalDhtTestMap.h.
Referenced by DHTTestApp::handleTimerEvent(), and initialize().
cMessage* GlobalDhtTestMap::periodicTimer [private] |
timer self-message for writing periodic statistical information
Definition at line 102 of file GlobalDhtTestMap.h.
Referenced by GlobalDhtTestMap(), handleMessage(), initialize(), and ~GlobalDhtTestMap().
const int GlobalDhtTestMap::TEST_MAP_INTERVAL = 10 [static, private] |
interval in seconds for writing periodic statistical information
Definition at line 98 of file GlobalDhtTestMap.h.
Referenced by handleMessage().