OverSim
PubSubLobby.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef __PUBSUBLOBBY_H_
25 #define __PUBSUBLOBBY_H_
26 
27 #include <deque>
28 #include <algorithm>
29 #include <omnetpp.h>
30 #include <NodeHandle.h>
31 #include <BaseOverlay.h>
32 
33 #include "PubSubMessage_m.h"
34 #include "PubSubSubspace.h"
35 
36 class PubSubLobby : public BaseOverlay
37 {
38  public:
39  // OMNeT++
40  virtual ~PubSubLobby();
41  virtual void initializeOverlay(int stage);
42  virtual void finishOverlay();
43  virtual void handleUDPMessage(BaseOverlayMessage* msg);
44  virtual void handleTimerEvent(cMessage* msg);
45 
46  virtual bool handleRpcCall(BaseCallMessage* msg);
47  virtual void handleRpcResponse(BaseResponseMessage *msg,
48  cPolymorphic* context,
49  int rpcId, simtime_t rtt);
50  virtual void handleRpcTimeout(BaseCallMessage *msg,
51  const TransportAddress &dest,
52  cPolymorphic* context, int rpcId,
53  const OverlayKey &destKey);
54 
55  protected:
56  class ChildEntry {
57  public:
60  std::set<int> dutySet;
61  bool operator< (const ChildEntry c) const { return ressources < c.ressources; }
62  bool operator== (const ChildEntry c) const { return handle == c.handle; }
63  bool operator== (const NodeHandle n) const { return handle == n; }
64  bool operator== (const TransportAddress n) const { return (TransportAddress) handle == n; }
65  };
66 
69  std::vector<std::vector<PubSubSubspaceLobby> > subspaces;
70  std::list<PubSubHelpCall*> waitingForHelp;
71 
72 // typedef std::map<NodeHandle, ChildEntry> PlayerMap;
73  typedef std::map<TransportAddress, ChildEntry> PlayerMap;
75  typedef std::multimap<int, ChildEntry*, std::greater<int> > PlayerRessourceMap;
77 
78  virtual void handleJoin( PubSubJoinCall* joinMsg );
79  virtual void handleHelpCall( PubSubHelpCall* helpMsg );
80  virtual void handleRespCall( PubSubResponsibleNodeCall* respCall );
81  virtual void handleTakeOverResponse( PubSubTakeOverSubspaceResponse* takeOverResp );
82  virtual void handleTakeOverTimeout( PubSubTakeOverSubspaceCall* takeOverCall, const TransportAddress& oldNode );
84  void replaceResponsibleNode( int subspaceId, NodeHandle respNode );
85  void replaceResponsibleNode( PubSubSubspaceId subspaceId, NodeHandle respNode );
86 // void failedNode(const NodeHandle& node);
87  void failedNode(const TransportAddress& node);
88 
89  // statistics
92 
93  public:
94  friend std::ostream& operator<< (std::ostream& o, const ChildEntry& entry);
95 
96 };
97 
98 #endif