Class: LS4::NodeList

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

Instance Method Summary collapse

Methods inherited from TSVData

#close, #get_hash, #open

Constructor Details

#initializeNodeList

Returns a new instance of NodeList.



22
23
24
25
26
# File 'lib/ls4/logic/membership.rb', line 22

def initialize
  @path = nil
  @map = {}  # {nid => Node}
  super()
end

Instance Method Details

#add(node) ⇒ Object



32
33
34
35
36
# File 'lib/ls4/logic/membership.rb', line 32

def add(node)
  @map[node.nid] = node
  on_change
  true
end

#delete(nid) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/ls4/logic/membership.rb', line 38

def delete(nid)
  if node = @map.delete(nid)
    on_change
    node
  else
    false
  end
end

#each(&block) ⇒ Object



73
74
75
# File 'lib/ls4/logic/membership.rb', line 73

def each(&block)
  @map.each_value(&block)
end

#from_msgpack(obj) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/ls4/logic/membership.rb', line 89

def from_msgpack(obj)
  map = {}
  obj.each {|n|
    node = Node.new.from_msgpack(n)
    map[node.nid] = node
  }
  @map = map
  on_change
  self
end

#get(nid) ⇒ Object



28
29
30
# File 'lib/ls4/logic/membership.rb', line 28

def get(nid)
  @map[nid]
end

#get_all_nidsObject



81
82
83
# File 'lib/ls4/logic/membership.rb', line 81

def get_all_nids
  @map.map {|nid,node| nid }
end

#get_all_nodesObject



77
78
79
# File 'lib/ls4/logic/membership.rb', line 77

def get_all_nodes
  @map.values
end

#include?(nid) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/ls4/logic/membership.rb', line 47

def include?(nid)
  @map.has_key?(nid)
end

#to_msgpack(out = '') ⇒ Object



85
86
87
# File 'lib/ls4/logic/membership.rb', line 85

def to_msgpack(out = '')
  @map.values.sort_by {|node| node.nid }.to_msgpack(out)
end

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



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ls4/logic/membership.rb', line 51

def update(nid, address, name, rsids, location)
  node = @map[nid]
  if node
    if address
      node.address = address
    end
    if name
      node.name = name
    end
    if rsids
      node.rsids = rsids
    end
    if location
      node.location = location
    end
    on_change
    true
  else
    false
  end
end