Branch data Line data Source code
1 : : /*
2 : : *
3 : : * Copyright 2006 Savarese Software Research Corporation
4 : : *
5 : : * Licensed under the Apache License, Version 2.0 (the "License");
6 : : * you may not use this file except in compliance with the License.
7 : : * You may obtain a copy of the License at
8 : : *
9 : : * http://www.savarese.com/software/ApacheLicense-2.0
10 : : *
11 : : * Unless required by applicable law or agreed to in writing, software
12 : : * distributed under the License is distributed on an "AS IS" BASIS,
13 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : : * See the License for the specific language governing permissions and
15 : : * limitations under the License.
16 : : */
17 : :
18 : : /**
19 : : * @file
20 : : * This header defines the MembershipInfo class.
21 : : */
22 : :
23 : : #ifndef __SSRC_SPREAD_MEMBERSHIP_INFO_H
24 : : #define __SSRC_SPREAD_MEMBERSHIP_INFO_H
25 : :
26 : : #include <ssrc/spread/BaseMessage.h>
27 : :
28 : : __BEGIN_NS_SSRC_SPREAD
29 : :
30 : : #ifdef LIBSSRCSPREAD_ENABLE_MEMBERSHIP_INFO
31 : :
32 : : /**
33 : : * MembershipInfo stores information about group membership messages.
34 : : * You can populate a MembershipInfo instance with information about a
35 : : * membership message by invoking BaseMessage::get_membership_info on
36 : : * a Message or ScatterMessage containing a membership message.
37 : : *
38 : : * <b>Warning:</b> This class is available only when compiled against
39 : : * %Spread 4.x and greater.
40 : : */
41 [ + - ]: 4 : class MembershipInfo {
42 : : friend void BaseMessage::get_membership_info(MembershipInfo & info) const;
43 : :
44 : : BaseMessage::service_type _service_type;
45 : : Spread::membership_info _info;
46 : : GroupList _local_members, _non_local_members;
47 : :
48 : 3 : void set_service(const BaseMessage::service_type service) {
49 : 3 : _service_type = service;
50 : 3 : }
51 : :
52 : : public:
53 : :
54 : : /**
55 : : * Returns the service type of the message.
56 : : * @return The service type of the message.
57 : : */
58 : 6 : BaseMessage::service_type service() const {
59 : 6 : return _service_type;
60 : : }
61 : :
62 : : /**
63 : : * Returns a list of the private group names from the local segment
64 : : * that remained in the group after a change in membership caused by
65 : : * a network partition. For join/leave/disconnect changes, the list
66 : : * contains only the changed member (you should call
67 : : * changed_member() instead). This is the equivalent of the group
68 : : * information from the my_vs_set vs_set_info member from the
69 : : * membership_info struct in the C API.
70 : : *
71 : : * @param members A reference to the GroupList that should store the
72 : : * local members.
73 : : */
74 : 1 : void get_local_members(GroupList & members) const {
75 : 1 : members = _local_members;
76 : 1 : }
77 : : /**
78 : : * Returns a list of the private group names from all the segments
79 : : * except the local segment that belong to the group after a change
80 : : * in membership caused by a network partition. For
81 : : * join/leave/disconnect changes, the list will be empty.
82 : : *
83 : : * @param members A reference to the GroupList that should store the
84 : : * non-local members.
85 : : */
86 : 1 : void get_non_local_members(GroupList & members) const {
87 : 1 : members = _non_local_members;
88 : 1 : }
89 : :
90 : : /**
91 : : * Returns a list of the private group names from all the segments
92 : : * that belong to the group after a change in membership caused by a
93 : : * network partition. For join/leave/disconnect changes, the list
94 : : * contains only the changed member (you should call
95 : : * changed_member() instead). This is the equivalent of the group
96 : : * information from the C API vs_set_info data structure, but
97 : : * the group ordering may differ.
98 : : *
99 : : * @param members A reference to the GroupList that should store all
100 : : * of the members.
101 : : */
102 : 1 : void get_all_members(GroupList & members) const {
103 : 1 : members.clear();
104 : 1 : members.add(_local_members);
105 : 1 : members.add(_non_local_members);
106 : 1 : }
107 : :
108 : : /**
109 : : * Tests if the group ids of the MembrshipInfo objects are the same.
110 : : *
111 : : * @param info The MembershipInfo object whose group id is to to compare.
112 : : * @return true if the group ids are equal, false if not.
113 : : */
114 : : bool equal_group_ids(const MembershipInfo & info) const {
115 : : return (Spread::SP_equal_group_ids(_info.gid, info._info.gid) != 0);
116 : : }
117 : :
118 : : /**
119 : : * Returns the private group name of member who joined, left, or
120 : : * disconnected. Only valid if caused_by_join, leave, or disconnect
121 : : * are true.
122 : : * @return The private group name of member who joined, left, or
123 : : * disconnected.
124 : : */
125 : 1 : string changed_member() const {
126 [ + - ]: 1 : return _info.changed_member;
127 : : }
128 : :
129 : : /**
130 : : * Returns true if the message is a regular membership message, false if not.
131 : : * @return true if the message is a regular membership message, false if not.
132 : : */
133 : 1 : bool is_regular_membership() const {
134 : 1 : return Is_reg_memb_mess(service());
135 : : }
136 : :
137 : : /**
138 : : * Returns true if the message is a transitional membership message,
139 : : * false if not.
140 : : * @return true if the message is a transitional membership message,
141 : : * false if not.
142 : : */
143 : : bool is_transition() const {
144 : : return Is_transition_mess(service());
145 : : }
146 : :
147 : : /**
148 : : * Returns true if the message is a self-leave membership message,
149 : : * false if not.
150 : : * @return true if the message is a self-leave membership message,
151 : : * false if not.
152 : : */
153 : 1 : bool is_self_leave() const {
154 [ + - + - ]: 1 : return Is_self_leave(service());
155 : : }
156 : :
157 : : /**
158 : : * Returns true if the membership message was caused by a group
159 : : * join, false if not.
160 : : * @return true if the membership message was caused by a group
161 : : * join, false if not.
162 : : */
163 : 1 : bool caused_by_join() const {
164 : 1 : return Is_caused_join_mess(service());
165 : : }
166 : :
167 : : /**
168 : : * Returns true if the membership message was caused by a group
169 : : * leave, false if not.
170 : : * @return true if the membership message was caused by a group
171 : : * leave, false if not.
172 : : */
173 : 2 : bool caused_by_leave() const {
174 : 2 : return Is_caused_leave_mess(service());
175 : : }
176 : :
177 : : /**
178 : : * Returns true if the membership message was caused by a client
179 : : * disconnect, false if not.
180 : : * @return true if the membership message was caused by a client
181 : : * disconnect, false if not.
182 : : */
183 : : bool caused_by_disconnect() const {
184 : : return Is_caused_disconnect_mess(service());
185 : : }
186 : :
187 : : /**
188 : : * Returns true if the membership message was caused by a network
189 : : * partition, false if not.
190 : : * @return true if the membership message was caused by a network
191 : : * partition, false if not.
192 : : */
193 : : bool caused_by_network() const {
194 : : return Is_caused_network_mess(service());
195 : : }
196 : : };
197 : :
198 : : #endif
199 : :
200 : : __END_NS_SSRC_SPREAD
201 : :
202 : : #endif
|