Parent

BrB::EventMachine

Public Class Methods

open(uri, klass, opts = {}) click to toggle source
# File lib/brb/event_machine.rb, line 29
def open(uri, klass, opts = {})
  host, port = parse_uri(uri)
  begin
    ensure_em_is_started!

    q = Queue.new
    EM.schedule do
      q << EM::connect(host, port, klass, opts.merge(:uri => "brb://#{host}:#{port}"))
    end
    
    # Wait for socket connection with the q.pop

    return q.pop

  rescue Exception => e
    BrB.logger.error e.backtrace.join("\n")
    raise "#{e} - #{uri}"
  end
end
open_server(uri, klass, opts = {}) click to toggle source
# File lib/brb/event_machine.rb, line 48
def open_server(uri, klass, opts = {})
  host, port = parse_uri(uri)
  max = 80 # Nb try before giving up

  begin
    uri = "brb://#{host}:#{port}"
    ensure_em_is_started!

    # Schedule server creation for thread safety

    q = Queue.new
    EM.schedule do
      q << EM::start_server(host, port, klass, opts.merge(:uri => uri))
    end

    # Wait for server creation with the q.pop

    return uri, q.pop

  rescue Exception => e
    max -= 1
    port += 1
    retry if max > 0
    BrB.logger.error e.backtrace.join("\n")
    raise "#{e} - BrB Tcp Event machine Can not bind on #{host}:#{port}"
  end

end

[Validate]

Generated with the Darkfish Rdoc Generator 2.