Scribe.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
00025 #ifndef __SCRIBE_H_
00026 #define __SCRIBE_H_
00027
00028 #include <map>
00029 #include <string>
00030
00031 #include "BaseApp.h"
00032 #include "CommonMessages_m.h"
00033 #include "GlobalNodeList.h"
00034 #include "NodeHandle.h"
00035
00036 #include "ScribeGroup.h"
00037 #include "ScribeMessage_m.h"
00038
00039
00040 std::ostream& operator<< (std::ostream& o, std::map<OverlayKey, ScribeGroup> m )
00041 {
00042 for (std::map<OverlayKey, ScribeGroup>::iterator it = m.begin(); it != m.end(); ++it) {
00043 o << it->first << "\n";
00044 o << " Parent: " << it->second.getParent() << "\n";
00045 o << " Status: " << (it->second.getSubscription() ? "Subscriber\n" : "Forwarder\n");
00046 o << " Children (" << it->second.numChildren() << "):\n";
00047 std::set<NodeHandle>::iterator iit = it->second.getChildrenBegin();
00048 for (int i = it->second.numChildren(); i > 0; --i) {
00049 o << " " << *iit << "\n";
00050 ++iit;
00051 }
00052 }
00053 return o;
00054 }
00055
00056
00057 class Scribe : public BaseApp
00058 {
00059 private:
00060 typedef std::map<OverlayKey, ScribeGroup> GroupList;
00061 GroupList groupList;
00062 typedef std::multimap<NodeHandle, ScribeTimer*> ChildTimeoutList;
00063 ChildTimeoutList childTimeoutList;
00064
00065 int childTimeout;
00066 int parentTimeout;
00067
00068 ScribeTimer* subscriptionTimer;
00069
00070
00071 int numJoins;
00072 int numChildTimeout;
00073 int numParentTimeout;
00074 int numForward;
00075 int forwardBytes;
00076 int numReceived;
00077 int receivedBytes;
00078 int numHeartbeat;
00079 int heartbeatBytes;
00080 int numSubscriptionRefresh;
00081 int subscriptionRefreshBytes;
00082
00083 public:
00084 Scribe( );
00085 ~Scribe( );
00086
00087
00088 virtual void initializeApp( int stage );
00089
00090 virtual void handleUpperMessage( cMessage *msg );
00091 virtual void handleReadyMessage( CompReadyMessage* msg );
00092
00093 virtual void handleTimerEvent( cMessage *msg );
00094
00095 virtual bool handleRpcCall( BaseCallMessage* msg );
00096 virtual void handleRpcResponse( BaseResponseMessage* msg,
00097 cPolymorphic* context,
00098 int rpcId, simtime_t rtt );
00099
00100 virtual void forward(OverlayKey* key, cPacket** msg,
00101 NodeHandle* nextHopNode);
00102
00103 virtual void deliver(OverlayKey& key, cMessage* msg);
00104 virtual void update( const NodeHandle& node, bool joined );
00105
00106 virtual void finishApp( );
00107
00108 protected:
00112 void handleJoinResponse( ScribeJoinResponse* joinResponse );
00113
00121 void handleJoinCall( ScribeJoinCall* joinMsg);
00122
00129 void handlePublishCall( ScribePublishCall* publishCall );
00130
00137 void handlePublishResponse( ScribePublishResponse* publishResponse );
00138
00142 void handleJoinMessage( ScribeJoinCall* joinMsg, bool amIRoot);
00143
00147 void handleLeaveMessage( ScribeLeaveMessage* leaveMsg );
00148
00154 void subscribeToGroup( const OverlayKey& groupId );
00155
00161 void leaveGroup( const OverlayKey& group );
00162
00170 void startTimer( ScribeTimer* timer );
00171
00175 void addChildToGroup( const NodeHandle& child, ScribeGroup& group );
00176
00180 void removeChildFromGroup( const NodeHandle& child, ScribeGroup& group );
00181
00188 void removeChildFromGroup( ScribeTimer* timer );
00189
00193 void checkGroupEmpty( ScribeGroup& group );
00194
00201 void refreshChildTimer( NodeHandle& child, OverlayKey& groupId );
00202
00206 void deliverALMDataToGroup( ScribeDataMessage* dataMsg );
00207
00214 void deliverALMDataToRoot( ALMMulticastMessage* mcastMsg );
00215 };
00216
00217 #endif