Class: Woodhouse::Watchdog
- Inherits:
-
Object
- Object
- Woodhouse::Watchdog
show all
- Includes:
- Celluloid
- Defined in:
- lib/woodhouse/watchdog.rb
Defined Under Namespace
Classes: Client, Status, Transition
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Watchdog.
4
5
6
7
|
# File 'lib/woodhouse/watchdog.rb', line 4
def initialize
@actors = {}
@listeners = []
end
|
Class Method Details
.client(id = nil) ⇒ Object
52
53
54
|
# File 'lib/woodhouse/watchdog.rb', line 52
def client(id = nil)
Client.new(instance, id)
end
|
.instance ⇒ Object
37
38
39
|
# File 'lib/woodhouse/watchdog.rb', line 37
def instance
Celluloid::Actor[:woodhouse_watchdog]
end
|
.listen(listener = nil, &blk) ⇒ Object
56
57
58
59
60
|
# File 'lib/woodhouse/watchdog.rb', line 56
def listen(listener = nil, &blk)
if instance
instance.listen listener || blk
end
end
|
.start ⇒ Object
41
42
43
|
# File 'lib/woodhouse/watchdog.rb', line 41
def start
@supervisor ||= supervise_as :woodhouse_watchdog
end
|
.stop ⇒ Object
45
46
47
48
49
50
|
# File 'lib/woodhouse/watchdog.rb', line 45
def stop
if @supervisor
supervisor, @supervisor = @supervisor, nil
supervisor.terminate
end
end
|
Instance Method Details
#listen(listener) ⇒ Object
23
24
25
|
# File 'lib/woodhouse/watchdog.rb', line 23
def listen(listener)
@listeners << listener
end
|
#report(id, status) ⇒ Object
9
10
11
12
13
|
# File 'lib/woodhouse/watchdog.rb', line 9
def report(id, status)
last_status = @actors[id]
@actors[id] = status
notify id, Transition.new(last_status, status)
end
|
#status_report ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/woodhouse/watchdog.rb', line 15
def status_report
{}.tap do |hash|
@actors.each do |id, status|
hash[id.to_s] = status.to_h
end
end
end
|