Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes

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.

{
    periodicTimer = NULL;
}

GlobalDhtTestMap::~GlobalDhtTestMap (  ) 

Definition at line 47 of file GlobalDhtTestMap.cc.

{
    cancelAndDelete(periodicTimer);
    dataMap.clear();
}


Member Function Documentation

void GlobalDhtTestMap::eraseEntry ( const OverlayKey key  ) 

Definition at line 99 of file GlobalDhtTestMap.cc.

Referenced by DHTTestApp::handleGetResponse().

{
    dataMap.erase(key);
}

const DHTEntry * GlobalDhtTestMap::findEntry ( const OverlayKey key  ) 

Definition at line 104 of file GlobalDhtTestMap.cc.

Referenced by DHTTestApp::handleGetResponse().

{
    std::map<OverlayKey, DHTEntry>::iterator it = dataMap.find(key);

    if (it == dataMap.end()) {
        return NULL;
    } else {
        return &(it->second);
    }
}

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

{
    if (dataMap.size() == 0) {
        return OverlayKey::UNSPECIFIED_KEY;
    }

    // return random OverlayKey in O(log n)
    std::map<OverlayKey, DHTEntry>::iterator it = dataMap.end();
    DHTEntry tempEntry = {BinaryValue::UNSPECIFIED_VALUE, 0};

    OverlayKey randomKey = OverlayKey::random();
    it = dataMap.find(randomKey);

    if (it == dataMap.end()) {
        it = dataMap.insert(make_pair(randomKey, tempEntry)).first;
        dataMap.erase(it++);
    }

    if (it == dataMap.end()) {
        it = dataMap.begin();
    }

    return it->first;
}

void GlobalDhtTestMap::handleMessage ( cMessage *  msg  )  [private]

Definition at line 68 of file GlobalDhtTestMap.cc.

{
    //cleanupDataMap();
    DhtTestEntryTimer *entryTimer = NULL;

    if (msg == periodicTimer) {
        RECORD_STATS(globalStatistics->recordOutVector(
           "GlobalDhtTestMap: Number of stored DHT entries", dataMap.size()));
        scheduleAt(simTime() + TEST_MAP_INTERVAL, msg);
    } else if ((entryTimer = dynamic_cast<DhtTestEntryTimer*>(msg)) != NULL) {
        dataMap.erase(entryTimer->getKey());
        delete msg;
    } else {
        throw cRuntimeError("GlobalDhtTestMap::handleMessage(): "
                                "Unknown message type!");
    }
}

void GlobalDhtTestMap::initialize (  )  [private]

Definition at line 53 of file GlobalDhtTestMap.cc.

{
    p2pnsNameCount = 0;
    globalStatistics = GlobalStatisticsAccess().get();
    WATCH_MAP(dataMap);

    periodicTimer = new cMessage("dhtTestMapTimer");

    scheduleAt(simTime(), periodicTimer);
}

void GlobalDhtTestMap::insertEntry ( const OverlayKey key,
const DHTEntry entry 
)

Definition at line 86 of file GlobalDhtTestMap.cc.

Referenced by DHTTestApp::handlePutResponse().

{
    Enter_Method_Silent();

    dataMap.erase(key);
    dataMap.insert(make_pair(key, entry));

    DhtTestEntryTimer* msg = new DhtTestEntryTimer("dhtEntryTimer");
    msg->setKey(key);

    scheduleAt(entry.endtime, msg);
}

size_t GlobalDhtTestMap::size (  )  [inline]

Definition at line 90 of file GlobalDhtTestMap.h.

{ 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: