GlobalDhtTestMap Class Reference

Module with a global view on all currently stored DHT records (used by DHTTestApp). More...

#include <GlobalDhtTestMap.h>

List of all members.

Public Member Functions

 GlobalDhtTestMap ()
 ~GlobalDhtTestMap ()
void insertEntry (const OverlayKey &key, const DHTEntry &entry)
const DHTEntryfindEntry (const OverlayKey &key)
void eraseEntry (const OverlayKey &key)
const OverlayKeygetRandomKey ()
size_t size ()

Public Attributes

uint32_t p2pnsNameCount

Private Member Functions

void initialize ()
void handleMessage (cMessage *msg)
void finish ()

Private Attributes

GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
std::map< OverlayKey, DHTEntrydataMap
 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

Detailed Description

Module with a global view on all currently stored DHT records (used by DHTTestApp).

Author:
Ingmar Baumgart

Definition at line 49 of file GlobalDhtTestMap.h.


Constructor & Destructor Documentation

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 }


Member Function Documentation

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().

00105 {
00106     std::map<OverlayKey, DHTEntry>::iterator it = dataMap.find(key);
00107 
00108     if (it == dataMap.end()) {
00109         return NULL;
00110     } else {
00111         return &(it->second);
00112     }
00113 }

void GlobalDhtTestMap::finish (  )  [private]

Definition at line 64 of file GlobalDhtTestMap.cc.

00065 {
00066 }

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().

00087 {
00088     Enter_Method_Silent();
00089 
00090     dataMap.erase(key);
00091     dataMap.insert(make_pair(key, entry));
00092 
00093     DhtTestEntryTimer* msg = new DhtTestEntryTimer("dhtEntryTimer");
00094     msg->setKey(key);
00095 
00096     scheduleAt(entry.endtime, msg);
00097 }

size_t GlobalDhtTestMap::size (  )  [inline]

Definition at line 90 of file GlobalDhtTestMap.h.

00090 { return dataMap.size(); };


Member Data Documentation

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().

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().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:17 2010 for OverSim by  doxygen 1.6.3