PubSubSubspace.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00025 #ifndef __PUBSUBSUBSPACE_H_
00026 #define __PUBSUBSUBSPACE_H_
00027 
00028 #include "PubSubSubspaceId.h"
00029 #include "NodeHandle.h"
00030 #include "PubSubMessage_m.h"
00031 #include <deque>
00032 
00033 class PubSubSubspace
00034 {
00035     protected:
00036         PubSubSubspaceId spaceId;
00037         NodeHandle responsibleNode;
00038 
00039         simtime_t lastTimestamp;
00040     public:
00046         PubSubSubspace( PubSubSubspaceId id );
00047         ~PubSubSubspace( );
00048 
00049         const PubSubSubspaceId& getId() { return spaceId; }
00050         void setResponsibleNode( NodeHandle node ) { responsibleNode = node; }
00051         NodeHandle getResponsibleNode() { return responsibleNode; }
00052         
00053         void setTimestamp() { lastTimestamp = simTime(); }
00054         void setTimestamp( simtime_t stamp ) { lastTimestamp = stamp; }
00055         simtime_t getLastTimestamp() { return lastTimestamp; }
00056         simtime_t getTimeSinceLastTimestamp() { return simTime() - lastTimestamp; }
00057         friend std::ostream& operator<< (std::ostream& o, const PubSubSubspace& subspace);
00058 };
00059 
00060 class PubSubSubspaceLobby : public PubSubSubspace
00061 {
00062     public:
00063         std::list<PubSubResponsibleNodeCall*> waitingNodes;
00064         bool waitingForRespNode;
00065         PubSubSubspaceLobby( PubSubSubspaceId id );
00066 };
00067 
00068 class PubSubSubspaceIntermediate : public PubSubSubspace
00069 {
00070     public:
00071         std::set<NodeHandle> children;
00072         PubSubSubspaceIntermediate( PubSubSubspaceId id ) : PubSubSubspace( id ) {}
00073         virtual ~PubSubSubspaceIntermediate( ) {}
00074         virtual bool addChild( NodeHandle node ) { return children.insert( node ).second; }
00075         virtual bool removeChild( NodeHandle node ) { return children.erase( node ); }
00076         virtual int getNumChildren() { return children.size(); }
00077 
00078         friend std::ostream& operator<< (std::ostream& o, const PubSubSubspaceIntermediate& subspace);
00079 };
00080 
00081 class PubSubSubspaceResponsible : public PubSubSubspaceIntermediate
00082 {
00083     public:
00084         class IntermediateNode
00085         {
00086             public:
00087                 NodeHandle node;
00088                 std::set<NodeHandle> children;
00089                 unsigned int waitingChildren;
00090                 IntermediateNode() : waitingChildren(0) {}
00091         };
00092         std::deque<IntermediateNode> intermediateNodes;
00093         std::map<NodeHandle,bool> cachedChildren;
00094 
00095         std::deque<PubSubMoveMessage*> waitingMoveMessages;
00096 
00097         static unsigned int maxChildren;
00098 
00099         PubSubSubspaceResponsible( PubSubSubspaceId id );
00100         void setBackupNode( NodeHandle b ) { backupNode = b; }
00101         const NodeHandle& getBackupNode() { return backupNode; }
00102 
00103         void setHeartbeatTimer( PubSubTimer* t ) { heartbeatTimer = t; }
00104         PubSubTimer* getHeartbeatTimer() { return heartbeatTimer; }
00105 
00106         int getHeartbeatFailCount() { return heartbeatFailCount; }
00107         void incHeartbeatFailCount() { ++heartbeatFailCount; }
00108         void resetHeartbeatFailCount() { heartbeatFailCount = 0; }
00109 
00110         int getTotalChildrenCount() { return totalChildrenCount; }
00111         void fixTotalChildrenCount();
00112         
00113         int getNumIntermediates() { return intermediateNodes.size(); }
00114         IntermediateNode* getNextFreeIntermediate();
00115         
00116         virtual bool addChild( NodeHandle node );
00117         virtual IntermediateNode* removeAnyChild( NodeHandle node );
00118     protected:
00119         int totalChildrenCount;
00120         NodeHandle backupNode;
00121 
00122         PubSubTimer* heartbeatTimer;
00123         int heartbeatFailCount;
00124 
00125         friend std::ostream& operator<< (std::ostream& o, const PubSubSubspaceResponsible& subspace);
00126 };
00127 
00128 #endif
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3