Class: DRbQS::Server::NodeList

Inherits:
Object
  • Object
show all
Defined in:
lib/drbqs/server/node_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNodeList

Returns a new instance of NodeList.



8
9
10
11
12
13
14
# File 'lib/drbqs/server/node_list.rb', line 8

def initialize
  @id = 0
  @list = {}
  @check = []
  @prepare_to_exit = []
  @history = DRbQS::Server::History.new
end

Instance Attribute Details

#historyObject (readonly)

Returns the value of attribute history.



6
7
8
# File 'lib/drbqs/server/node_list.rb', line 6

def history
  @history
end

#listObject (readonly)

Returns the value of attribute list.



6
7
8
# File 'lib/drbqs/server/node_list.rb', line 6

def list
  @list
end

Instance Method Details

#add_to_preparation_to_exit(node_id) ⇒ Object



62
63
64
65
66
67
# File 'lib/drbqs/server/node_list.rb', line 62

def add_to_preparation_to_exit(node_id)
  unless prepare_to_exit?(node_id)
    @history.set(node_id, :set_exitting)
    @prepare_to_exit << node_id
  end
end

#delete(id, history_state) ⇒ Object



31
32
33
34
35
# File 'lib/drbqs/server/node_list.rb', line 31

def delete(id, history_state)
  @list.delete(id)
  @prepare_to_exit.delete(id)
  @history.set(id, history_state)
end

#delete_not_aliveObject



37
38
39
40
41
42
43
44
# File 'lib/drbqs/server/node_list.rb', line 37

def delete_not_alive
  @check.each do |id|
    delete(id, :disconnect)
  end
  deleted = @check
  @check = []
  deleted
end

#each(&block) ⇒ Object



23
24
25
# File 'lib/drbqs/server/node_list.rb', line 23

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

#empty?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/drbqs/server/node_list.rb', line 50

def empty?
  @list.size == 0
end

#exist?(id) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/drbqs/server/node_list.rb', line 54

def exist?(id)
  @list.find { |a| a[0] == id }
end

#get_new_id(id_str) ⇒ Object



16
17
18
19
20
21
# File 'lib/drbqs/server/node_list.rb', line 16

def get_new_id(id_str)
  @id += 1
  @list[@id] = id_str
  @history.set(@id, :connect, @list[@id])
  @id
end

#prepare_to_exit?(node_id) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/drbqs/server/node_list.rb', line 58

def prepare_to_exit?(node_id)
  @prepare_to_exit.include?(node_id)
end

#set_alive(id) ⇒ Object



46
47
48
# File 'lib/drbqs/server/node_list.rb', line 46

def set_alive(id)
  @check.delete(id)
end

#set_check_connectionObject



27
28
29
# File 'lib/drbqs/server/node_list.rb', line 27

def set_check_connection
  @check = @list.keys
end