Class: Corosync::CPG::MemberList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/corosync/cpg/member_list.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*list) ⇒ MemberList

Returns a new instance of MemberList.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/corosync/cpg/member_list.rb', line 15

def initialize(*list)
	@list = {}

	list = list[0] if list.size <= 1

	if list.is_a?(Array) then
		list.each do |recipient|
			self << recipient
		end
	elsif list.is_a?(Corosync::CPG::Member) then
		self << list
	elsif list.nil? then
		# nothing
	else
		raise ArgumentError, "Invalid recipient type: #{list.class}"
	end
end

Class Method Details

.new(*list) ⇒ Object



10
11
12
13
14
# File 'lib/corosync/cpg/member_list.rb', line 10

def self.new(*list)
	# return the input list if we were passed a MemberList
	return list[0] if list.size == 1 and list[0].is_a?(self)
	super
end

Instance Method Details

#&(list) ⇒ Corosync::CPG::MemberList

Get a list of all members also present in another list



60
61
62
# File 'lib/corosync/cpg/member_list.rb', line 60

def &(list)
	@list.keys & list.to_a
end

#<<(member) ⇒ Object

Add a member to the list

Parameters:



35
36
37
38
39
40
41
42
# File 'lib/corosync/cpg/member_list.rb', line 35

def << (member)
	if member.is_a?(FFI::Pointer) then
		cpgaddress = Corosync::CpgAddress.new(member)
		@list[Corosync::CPG::Member.new(cpgaddress)] = cpgaddress[:reason]
	else
		@list[member] = nil
	end
end

#delete(member) ⇒ void

This method returns an undefined value.

Delete member from list

Parameters:



67
68
69
# File 'lib/corosync/cpg/member_list.rb', line 67

def delete(member)
	@list.delete(member)
end

#dupCorosync::CPG::MemberList

Duplicate



73
74
75
76
77
78
79
# File 'lib/corosync/cpg/member_list.rb', line 73

def dup
	new = self.class.new
	self.each do |member|
		new << member.dup
	end
	new
end

#each(&block) {|member| ... } ⇒ Object

Iterate over all the member objects in the list.

Parameters:

  • block (Proc)

Yield Parameters:



53
54
55
# File 'lib/corosync/cpg/member_list.rb', line 53

def each(&block)
	@list.each_key &block
end

#freezeCorosync::CPG::MemberList



95
96
97
98
# File 'lib/corosync/cpg/member_list.rb', line 95

def freeze
	@list.freeze
	self
end

#reason(member) ⇒ Symbol, ...

In the case of join/leave lists, this gets the reason a member is in the list.

Parameters:

Returns:

  • (Symbol, Integer, NilClass)

    Reason for the membership.

    • :join => The member joined the group normally.

    • :leave => The member left the group normally.

    • :nodedown => The member left the group because the node left the cluster.

    • :nodeup => The member joined the group because it was already a member of a group on a node that just joined the cluster.

    • :procdown => The member left the group uncleanly (without calling Corosync::CPG#leave)



89
90
91
92
# File 'lib/corosync/cpg/member_list.rb', line 89

def reason(member)
	member = Corosync::CPG::Member.new if !member.is_a?(Corosync::CPG::Member)
	@list[member]
end

#sizeInteger

Number of members in list

Returns:

  • (Integer)


46
47
48
# File 'lib/corosync/cpg/member_list.rb', line 46

def size
	@list.size
end