Class: LS4::Membership

Inherits:
Object
  • Object
show all
Defined in:
lib/ls4/logic/membership.rb

Instance Method Summary collapse

Constructor Details

#initializeMembership

Returns a new instance of Membership.



158
159
160
161
# File 'lib/ls4/logic/membership.rb', line 158

def initialize
	@nodes = NodeList.new
	@active_rsids = []
end

Instance Method Details

#add_node(nid, address, name, rsids, location) ⇒ Object



172
173
174
175
176
177
178
179
180
# File 'lib/ls4/logic/membership.rb', line 172

def add_node(nid, address, name, rsids, location)
	node = Node.new(nid, address, name, rsids, location)
	if @nodes.get(nid)
		raise "nid already exist: #{nid}"
	end
	@nodes.add(node)
	update_active_rsids
	node
end

#closeObject



168
169
170
# File 'lib/ls4/logic/membership.rb', line 168

def close
	@nodes.close
end

#from_msgpack(obj) ⇒ Object



234
235
236
237
238
# File 'lib/ls4/logic/membership.rb', line 234

def from_msgpack(obj)
	@nodes.from_msgpack(obj)
	update_active_rsids
	self
end

#get_active_rsidsObject



218
219
220
# File 'lib/ls4/logic/membership.rb', line 218

def get_active_rsids
	@active_rsids
end

#get_all_nidsObject



214
215
216
# File 'lib/ls4/logic/membership.rb', line 214

def get_all_nids
	@nodes.get_all_nids
end

#get_all_nodesObject



210
211
212
# File 'lib/ls4/logic/membership.rb', line 210

def get_all_nodes
	@nodes.get_all_nodes
end

#get_hashObject



226
227
228
# File 'lib/ls4/logic/membership.rb', line 226

def get_hash
	@nodes.get_hash
end

#get_node(nid) ⇒ Object



202
203
204
205
206
207
208
# File 'lib/ls4/logic/membership.rb', line 202

def get_node(nid)
	node = @nodes.get(nid)
	unless node
		raise "no such node id: #{nid.inspect}"
	end
	node
end

#include?(nid) ⇒ Boolean

Returns:

  • (Boolean)


222
223
224
# File 'lib/ls4/logic/membership.rb', line 222

def include?(nid)
	@nodes.include?(nid)
end

#open(path) ⇒ Object



163
164
165
166
# File 'lib/ls4/logic/membership.rb', line 163

def open(path)
	@nodes.open(path)
	update_active_rsids
end

#remove_node(nid) ⇒ Object



182
183
184
185
186
187
188
189
# File 'lib/ls4/logic/membership.rb', line 182

def remove_node(nid)
	node = @nodes.delete(nid)
	unless node
		raise "nid not exist: #{nid}"
	end
	update_active_rsids
	true
end

#to_msgpack(out = '') ⇒ Object



230
231
232
# File 'lib/ls4/logic/membership.rb', line 230

def to_msgpack(out = '')
	@nodes.to_msgpack(out)
end

#update_node_info(nid, address, name, rsids, location) ⇒ Object



191
192
193
194
195
196
197
198
199
200
# File 'lib/ls4/logic/membership.rb', line 191

def update_node_info(nid, address, name, rsids, location)
	node = get_node(nid)
	if node.address == address && node.name == name &&
			node.rsids == rsids && node.location == location
		return false
	end
	@nodes.update(nid, address, name, rsids, location)
	update_active_rsids
	true
end