GlobalDhtTestMap Class Reference

#include <GlobalDhtTestMap.h>

List of all members.


Detailed Description

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

Author:
Ingmar Baumgart

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

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

Constructor & Destructor Documentation

GlobalDhtTestMap::GlobalDhtTestMap (  ) 

00043 {
00044     periodicTimer = NULL;
00045 }

GlobalDhtTestMap::~GlobalDhtTestMap (  ) 

00048 {
00049     cancelAndDelete(periodicTimer);
00050     dataMap.clear();
00051 }


Member Function Documentation

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  ) 

Referenced by DHTTestApp::handleGetResponse().

00099 {
00100     dataMap.erase(key);
00101 }

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 }

void GlobalDhtTestMap::finish (  )  [private]

00064 {
00065 }


Member Data Documentation

const int GlobalDhtTestMap::TEST_MAP_INTERVAL = 10 [static, private]

interval in seconds for writing periodic statistical information

Referenced by handleMessage().

pointer to GlobalStatistics module in this node

Referenced by handleMessage(), and initialize().

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


The documentation for this class was generated from the following files:

Generated on Fri Sep 19 13:05:07 2008 for ITM OverSim by  doxygen 1.5.5