PubSubLobby.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef __PUBSUBLOBBY_H_
00025 #define __PUBSUBLOBBY_H_
00026
00027 #include <deque>
00028 #include <algorithm>
00029 #include <omnetpp.h>
00030 #include <NodeHandle.h>
00031 #include <BaseOverlay.h>
00032
00033 #include "PubSubMessage_m.h"
00034 #include "PubSubSubspace.h"
00035
00036 class PubSubLobby : public BaseOverlay
00037 {
00038 public:
00039
00040 virtual ~PubSubLobby();
00041 virtual void initializeOverlay(int stage);
00042 virtual void finishOverlay();
00043 virtual void handleUDPMessage(BaseOverlayMessage* msg);
00044 virtual void handleTimerEvent(cMessage* msg);
00045
00046 virtual bool handleRpcCall(BaseCallMessage* msg);
00047 virtual void handleRpcResponse(BaseResponseMessage *msg,
00048 cPolymorphic* context,
00049 int rpcId, simtime_t rtt);
00050 virtual void handleRpcTimeout(BaseCallMessage *msg,
00051 const TransportAddress &dest,
00052 cPolymorphic* context, int rpcId,
00053 const OverlayKey &destKey);
00054
00055 protected:
00056 class ChildEntry {
00057 public:
00058 NodeHandle handle;
00059 int ressources;
00060 std::set<int> dutySet;
00061 bool operator< (const ChildEntry c) const { return ressources < c.ressources; }
00062 bool operator== (const ChildEntry c) const { return handle == c.handle; }
00063 bool operator== (const NodeHandle n) const { return handle == n; }
00064 bool operator== (const TransportAddress n) const { return (TransportAddress) handle == n; }
00065 };
00066
00067 int subspaceSize;
00068 int numSubspaces;
00069 std::vector<std::vector<PubSubSubspaceLobby> > subspaces;
00070 std::list<PubSubHelpCall*> waitingForHelp;
00071
00072
00073 typedef std::map<TransportAddress, ChildEntry> PlayerMap;
00074 PlayerMap playerMap;
00075 typedef std::multimap<int, ChildEntry*, std::greater<int> > PlayerRessourceMap;
00076 PlayerRessourceMap playerRessourceMap;
00077
00078 virtual void handleJoin( PubSubJoinCall* joinMsg );
00079 virtual void handleHelpCall( PubSubHelpCall* helpMsg );
00080 virtual void handleRespCall( PubSubResponsibleNodeCall* respCall );
00081 virtual void handleTakeOverResponse( PubSubTakeOverSubspaceResponse* takeOverResp );
00082 virtual void handleTakeOverTimeout( PubSubTakeOverSubspaceCall* takeOverCall, const TransportAddress& oldNode );
00083 void handleHelpReleaseMessage( PubSubHelpReleaseMessage* helpRMsg );
00084 void replaceResponsibleNode( int subspaceId, NodeHandle respNode );
00085 void replaceResponsibleNode( PubSubSubspaceId subspaceId, NodeHandle respNode );
00086
00087 void failedNode(const TransportAddress& node);
00088
00089
00090 int numPubSubSignalingMessages;
00091 int pubSubSignalingMessagesSize;
00092
00093 public:
00094 friend std::ostream& operator<< (std::ostream& o, const ChildEntry& entry);
00095
00096 };
00097
00098 #endif