Class: OsCtld::Monitor::Master
- Inherits:
-
Object
- Object
- OsCtld::Monitor::Master
- Includes:
- OsCtl::Lib::Utils::Log
- Defined in:
- lib/osctld/monitor/master.rb
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- @@instance =
nil
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.instance ⇒ Object
12 13 14 15 |
# File 'lib/osctld/monitor/master.rb', line 12 def instance @@instance ||= new @@instance end |
Instance Method Details
#demonitor(ct) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/osctld/monitor/master.rb', line 50 def demonitor(ct) stop_entry = sync do k = key(ct) entry = @monitors[k] entry.cts.delete(ct.id) if entry.cts.empty? @monitors.delete(k) entry else false end end graceful_stop(stop_entry, ct) if stop_entry true end |
#monitor(ct) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/osctld/monitor/master.rb', line 33 def monitor(ct) sync do k = key(ct) if @monitors.has_key?(k) @monitors[k].cts << ct.id update_state(ct) next end t = Thread.new { handle_monitor(ct) } @monitors[k] = Entry.new(t, nil, []) end true end |
#stop ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/osctld/monitor/master.rb', line 69 def stop tmp = nil sync do tmp = @monitors.clone @monitors.clear end tmp.each_value do |entry| Process.kill('TERM', entry.pid) if entry.pid end tmp.each_value do |entry| entry.thread.join end end |