ZG  "1.00
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
ZGPeerSettings.h
Go to the documentation of this file.
1 #ifndef ZGPeerSettings_h
2 #define ZGPeerSettings_h
3 
4 #include "zg/ZGNameSpace.h"
5 #include "message/Message.h"
6 
8 namespace zg_private
9 {
10  class PZGHeartbeatThreadState; // forward declaration
11 };
12 
13 namespace zg
14 {
15 
16 enum {
17  PEER_TYPE_FULL_PEER = 0, // a full peer is one that is able to become senior peer if necessary
18  PEER_TYPE_JUNIOR_ONLY, // a junior-only peer is one that wants to follow along as a junior peer but doesn't want to be senior
20 };
21 
26 {
27 public:
35  ZGPeerSettings(const String & systemName, uint8 numDatabases, bool systemIsOnLocalhostOnly, uint16 peerType = PEER_TYPE_FULL_PEER)
36  : _systemName(systemName)
37  , _numDatabases(numDatabases)
38  , _systemIsOnLocalhostOnly(systemIsOnLocalhostOnly)
39  , _peerType(peerType)
40  , _heartbeatsPerSecond(6) // setting this at >5 avoids the great MacOS/X WiFi-PowerSave-on-200mS-idle problem
41  , _heartbeatsBeforeFullyAttached(4)
42  , _maxMissingHeartbeats(4)
43  , _beaconsPerSecond(4)
44  , _outgoingHeartbeatPacketIDCounter(0)
45  {
46  // empty
47  }
48 
50  const String & GetSystemName() const {return _systemName;}
51 
53  uint8 GetNumDatabases() const {return _numDatabases;}
54 
56  bool IsSystemOnLocalhostOnly() const {return _systemIsOnLocalhostOnly;}
57 
61  const ConstMessageRef & GetPeerAttributes() const {return _optPeerAttributes;}
62 
64  uint16 GetPeerType() const {return _peerType;}
65 
67  uint32 GetHeartbeatsPerSecond() const {return _heartbeatsPerSecond;}
68 
70  uint32 GetMaxNumMissingHeartbeats() const {return _maxMissingHeartbeats;}
71 
73  uint32 GetHeartbeatsBeforeFullyAttached() const {return _heartbeatsBeforeFullyAttached;}
74 
76  uint32 GetBeaconsPerSecond() const {return _beaconsPerSecond;}
77 
82  void SetPeerAttributes(const ConstMessageRef & peerAttributes) {_optPeerAttributes = peerAttributes;}
83 
90  void SetHeartbeatsPerSecond(uint32 hps) {_heartbeatsPerSecond = hps;}
91 
99  void SetHeartbeatsBeforeFullyAttached(uint32 hb) {_heartbeatsBeforeFullyAttached = hb;}
100 
106  void SetMaxNumMissingHeartbeats(uint32 hb) {_maxMissingHeartbeats = hb;}
107 
113  void SetBeaconsPerSecond(uint32 bps) {_beaconsPerSecond = bps;}
114 
121  void SetMaximumUpdateLogSizeForDatabase(uint32 whichDB, uint64 maxNumBytes) {(void) _maxUpdateLogSizeBytes.PutOrRemove(whichDB, maxNumBytes);}
122 
126  uint64 GetMaximumUpdateLogSizeForDatabase(uint32 whichDB) const {return _maxUpdateLogSizeBytes.GetWithDefault(whichDB, 2*1024*1024);}
127 
128 private:
129 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
130  friend class zg_private::PZGHeartbeatThreadState;
131 #endif
132 
133  String _systemName; // Name of the ZG system we are to participate in
134  uint8 _numDatabases; // how many databases we want to maintain
135  bool _systemIsOnLocalhostOnly; // true iff we are simulating the system on a single host
136  ConstMessageRef _optPeerAttributes; // optional user-specified descriptive attributes for this peer (should be small)
137  uint16 _peerType; // PEER_TYPE_* value for this peer
138  uint32 _heartbeatsPerSecond; // how many heartbeats we should send per second (and expect to receive per second, from each peer)
139  uint32 _heartbeatsBeforeFullyAttached; // how many heartbeat-periods we should allow to elapse before declaring ourselves fully part of the system.
140  uint32 _maxMissingHeartbeats; // how many heartbeat-periods must go by without receiving a heartbeat from a peer, before we declare him offline
141  uint32 _beaconsPerSecond; // how many beacon-packets we should send out per second if we are the senior peer
142  Hashtable<uint32, uint64> _maxUpdateLogSizeBytes;
143  mutable uint32 _outgoingHeartbeatPacketIDCounter;
144 };
145 
146 }; // end namespace zg
147 
148 #endif
This immutable class holds various read-only settings that will be used to define the peer's behavior...
uint64 GetMaximumUpdateLogSizeForDatabase(uint32 whichDB) const
Returns the maximum number of bytes of RAM we should be allowed to use for the update-log of the spec...
void SetBeaconsPerSecond(uint32 bps)
Set the number of times we should send a "beacon" multicast packet per second, if we are the senior p...
const ConstMessageRef & GetPeerAttributes() const
Returns a reference to this peer's peer-attributes Message (as specified earlier via SetPeerAttribute...
The zg namespace contains the public API of the ZG library.
uint32 GetMaxNumMissingHeartbeats() const
Returns the max-missing-heartbeats-before-a-peer-is-declared-offline value for this peer (currently d...
void SetHeartbeatsPerSecond(uint32 hps)
Set the number of times we should send a "heartbeat" multicast packet per second. ...
uint32 GetBeaconsPerSecond() const
Returns the number-of-beacon-packets-to-send-per-second value for this peer (currently defaults to 4)...
uint8 GetNumDatabases() const
Returns the number of databases that will be present in this ZG system (as specified by our construct...
bool IsSystemOnLocalhostOnly() const
Returns true iff this ZG system is meant to be contained entirely within a single host computer (as s...
void SetHeartbeatsBeforeFullyAttached(uint32 hb)
Sets the number of heartbeat-periods that must elapse after our startup, before we declare ourselves ...
void SetPeerAttributes(const ConstMessageRef &peerAttributes)
Set the peer attributes that should be associated with this peer.
uint32 GetHeartbeatsBeforeFullyAttached() const
Returns the num-heartbeats-before-peer-considers-itself-fully-attached value this peer (currently def...
uint16 GetPeerType() const
Returns the PEER_TYPE_* value of this peer (currently only PEER_TYPE_FULL_PEER is supported) ...
void SetMaxNumMissingHeartbeats(uint32 hb)
Sets the number of heartbeat-periods that must go by without hearing any heartbeats from a source...
uint32 GetHeartbeatsPerSecond() const
Returns the heartbeats-per-second value for htis peer (currently defaults to 6)
The zg_private namespace is an undocumented namespace where the ZG library keeps all of its private i...
Definition: ZGPeerSession.h:17
void SetMaximumUpdateLogSizeForDatabase(uint32 whichDB, uint64 maxNumBytes)
Call this to set the maximum number of bytes of RAM the specified database should be allowed to use f...
ZGPeerSettings(const String &systemName, uint8 numDatabases, bool systemIsOnLocalhostOnly, uint16 peerType=PEER_TYPE_FULL_PEER)
Constructor.
const String & GetSystemName() const
Returns the ZG system's system name (as specified in our constructor)