6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/HeartBeat.rb', line 6
def init_HeartBeat
@heartbeat_thread=Thread.new{
lalive_clients=-1
lalive_client_lists=-1
loop do
begin
sleep 10
to_remove=Array.new
alive_clients=0
@connected_clients.delete_if{|client_id,cdb|
begin
Timeout.timeout(30){
cdb[:object].alive?
alive_clients+=1
false
}
rescue Timeout::Error
ewarn("client timed out, removing a dead client #{client_id}")
true
rescue => err
ewarn("removing a dead client #{client_id}")
@dbs.each_value{|db|
db.remove_client(client_id) unless db.serving?
}
true
end
}
alive_client_lists=0
@dbs.each_value{|db|
next unless db.serving?
db.cache.set("alive",Time.new)
alive_client_lists+=db.remove_dead_clients
}
einfo("#{alive_clients} clients, #{alive_client_lists} subscriptions") unless alive_clients==lalive_clients && alive_client_lists==lalive_client_lists
lalive_clients=alive_clients
lalive_client_lists=alive_client_lists
rescue ECONNREFUSED => err
eerror("HeartBeat: #{err}")
rescue =>err
eexception(err)
end
end
}
einfo("HeartBeat started")
end
|