1 /*------------------------------------------------------------------------------
2 Name: NodeInfo.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Holding information about the current node.
6 ------------------------------------------------------------------------------*/
7 #ifndef _UTIL_CLUSTER_NODEINFO_H
8 #define _UTIL_CLUSTER_NODEINFO_H
9
10 #include <util/xmlBlasterDef.h>
11 #include <string>
12 #include <map>
13
14 #include <util/qos/address/CallbackAddress.h>
15 #include <util/qos/address/Address.h>
16 #include <util/cluster/NodeId.h>
17
18 namespace org { namespace xmlBlaster { namespace util { namespace cluster {
19
20 /**
21 * This class holds the address informations about an
22 * xmlBlaster server instance (=cluster node).
23 */
24 typedef std::map<std::string, org::xmlBlaster::util::qos::address::AddressBaseRef> AddressMap;
25 typedef std::map<std::string, org::xmlBlaster::util::cluster::NodeId> NodeMap;
26
27 class Dll_Export NodeInfo
28 {
29 private:
30 std::string ME;
31 org::xmlBlaster::util::Global& global_;
32 org::xmlBlaster::util::cluster::NodeId nodeId_;
33 org::xmlBlaster::util::qos::address::Address tmpAddress_; // = null; // Helper for SAX parsing
34 org::xmlBlaster::util::qos::address::CallbackAddress tmpCbAddress_; // = null; // Helper for SAX parsing
35 AddressMap cbAddressMap_; // = null;
36 AddressMap addressMap_; // = null;
37 NodeMap backupNodeMap_; // = null;
38 bool nameService_; // = false;
39 bool inAddress_; // = false; // parsing inside <address> ?
40 bool inCallback_; // = false; // parsing inside <callback> ?
41 bool inBackupnode_; // = false; // parsing inside <backupnode> ?
42
43 void init()
44 {
45 nameService_ = false;
46 inAddress_ = false;
47 inCallback_ = false;
48 inBackupnode_ = false;
49 }
50
51 void copy(const NodeInfo& info)
52 {
53 tmpAddress_ = info.tmpAddress_;
54 tmpCbAddress_ = info.tmpCbAddress_;
55 nameService_ = info.nameService_;
56 inAddress_ = info.inAddress_;
57 inCallback_ = info.inCallback_;
58 inBackupnode_ = info.inBackupnode_;
59 }
60
61
62 /**
63 * Holds the addresses of a node.
64 */
65 public:
66 NodeInfo(org::xmlBlaster::util::Global& global, org::xmlBlaster::util::cluster::NodeId nodeId);
67
68 NodeInfo(const NodeInfo& info);
69
70 NodeInfo& operator=(const NodeInfo& info);
71
72 /**
73 * @return The unique name of the managed xmlBlaster instance e.g. "bilbo.mycompany.com"
74 */
75 std::string getId() const;
76
77 /**
78 * @return The unique name of the managed xmlBlaster instance.
79 */
80 org::xmlBlaster::util::cluster::NodeId getNodeId() const;
81
82 /**
83 * @param The unique name of the managed xmlBlaster instance
84 */
85 void setNodeId(org::xmlBlaster::util::cluster::NodeId nodeId);
86
87 /**
88 * Access the currently used address to access the node
89 * @return null if not specified
90 */
91 org::xmlBlaster::util::qos::address::AddressBaseRef getAddress() const;
92
93 /**
94 * Add another address for this cluster node.
95 * <p />
96 * The std::map is sorted with the same sequence as the given XML sequence
97 */
98 void addAddress(const org::xmlBlaster::util::qos::address::AddressBaseRef& address);
99
100 /**
101 * Access all addresses of a node, please handle as readonly.
102 */
103 AddressMap getAddressMap() const;
104
105 /**
106 * Does the given address belong to this node?
107 */
108 bool contains(const org::xmlBlaster::util::qos::address::AddressBaseRef& other);
109
110 /**
111 * Access the currently used callback address for this node
112 * @return Never null, returns a default if none specified
113 */
114 org::xmlBlaster::util::qos::address::AddressBaseRef getCbAddress();
115
116 /**
117 * Currently not used.
118 */
119 AddressMap getCbAddressMap() const;
120
121 /**
122 * Add another callback address for this cluster node.
123 */
124 void addCbAddress(const org::xmlBlaster::util::qos::address::AddressBaseRef& cbAddress);
125
126 /**
127 * Is the node acting as a preferred cluster naming service.
128 * <p />
129 * NOTE: This mode is currently not supported
130 */
131 bool isNameService() const;
132
133 /**
134 * Tag this node as a cluster naming service.
135 * <p />
136 * NOTE: This mode is currently not supported
137 */
138 void setNameService(bool nameService);
139
140 /**
141 * If this node is not accessible, we can use its backup nodes.
142 * @return a Map containing org::xmlBlaster::util::cluster::NodeId objects
143 */
144 NodeMap getBackupnodeMap() const;
145
146 /**
147 * Set backup nodes.
148 */
149 void addBackupnode(const org::xmlBlaster::util::cluster::NodeId& backupId);
150
151 /**
152 * Dump state of this object into a XML ASCII std::string.
153 * @param extraOffset indenting of tags for nice output
154 */
155 std::string toXml(const std::string& extraOffset="");
156 };
157
158 }}}}
159
160 #endif
syntax highlighted by Code2HTML, v. 0.9.1