Sha256: dbd87f130b3ffdcea0cc181be16bbca216f0f3adbb1a9caed4d0ca2108bf6c8e

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

#!/usr/bin/env ruby
# listener.rb
# Controller Listener (for debugging)

require 'rinda/ring'

class Listener

  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

  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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
watirgrid-1.1.5 lib/listener.rb
watirgrid-1.1.4 lib/listener.rb
watirgrid-1.1.4.pre lib/listener.rb