Class: Listener
- Inherits:
-
Object
- Object
- Listener
- Defined in:
- lib/listener.rb
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Listener
constructor
A new instance of Listener.
- #start ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Listener
Returns a new instance of Listener.
9 10 11 12 13 14 15 |
# File 'lib/listener.rb', line 9 def initialize(params = {}) @controller_uri = params[:controller_uri] logfile = STDOUT @log = Logger.new(logfile, 'daily') @log.level = Logger::DEBUG @log.datetime_format = "%Y-%m-%d %H:%M:%S " end |
Instance Method Details
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/listener.rb', line 17 def start DRb.start_service ring_server = DRbObject.new(nil, @controller_uri) service = ring_server.read([:WatirGrid, nil, nil, nil, nil, nil, nil, nil]) observers = [] observers << ring_server.notify('write',[:WatirGrid, nil, nil, nil, nil, nil, nil, nil], nil) observers << ring_server.notify('take', [:WatirGrid, nil, nil, nil, nil, nil, nil, nil], nil) observers << ring_server.notify('delete', [:WatirGrid, nil, nil, nil, nil, nil, nil, nil], nil) @log.debug("Listener started on : #{@controller_uri}") threads = [] observers.each do |observer| threads << Thread.new do observer.each do |event| @log.debug(event.inspect) end end end # abort all threads on an exception Thread.abort_on_exception = true # wait for explicit stop via ctrl-c DRb.thread.join if __FILE__ == $0 end |