Class: Invoker::CLI::TailWatcher
- Inherits:
-
Object
- Object
- Invoker::CLI::TailWatcher
- Defined in:
- lib/invoker/cli/tail_watcher.rb
Overview
This class defines sockets which are open for watching log files
Instance Attribute Summary collapse
-
#tail_watchers ⇒ Object
Returns the value of attribute tail_watchers.
Instance Method Summary collapse
- #[](process_name) ⇒ Object
- #add(names, socket) ⇒ Object
-
#initialize ⇒ TailWatcher
constructor
A new instance of TailWatcher.
- #purge(name, socket) ⇒ Object
- #remove(name, socket) ⇒ Object
Constructor Details
#initialize ⇒ TailWatcher
Returns a new instance of TailWatcher.
6 7 8 9 |
# File 'lib/invoker/cli/tail_watcher.rb', line 6 def initialize @tail_mutex = Mutex.new @tail_watchers = Hash.new { |h, k| h[k] = [] } end |
Instance Attribute Details
#tail_watchers ⇒ Object
Returns the value of attribute tail_watchers.
4 5 6 |
# File 'lib/invoker/cli/tail_watcher.rb', line 4 def tail_watchers @tail_watchers end |
Instance Method Details
#[](process_name) ⇒ Object
11 12 13 |
# File 'lib/invoker/cli/tail_watcher.rb', line 11 def [](process_name) @tail_mutex.synchronize { tail_watchers[process_name] } end |
#add(names, socket) ⇒ Object
15 16 17 18 19 |
# File 'lib/invoker/cli/tail_watcher.rb', line 15 def add(names, socket) @tail_mutex.synchronize do names.each { |name| tail_watchers[name] << socket } end end |
#purge(name, socket) ⇒ Object
29 30 31 32 |
# File 'lib/invoker/cli/tail_watcher.rb', line 29 def purge(name, socket) tail_watchers.delete(name) Invoker.close_socket(socket) end |
#remove(name, socket) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/invoker/cli/tail_watcher.rb', line 21 def remove(name, socket) @tail_mutex.synchronize do client_list = tail_watchers[name] client_list.delete(socket) purge(name, socket) if client_list.empty? end end |