class Thrift::EventMachineTransport

Public Class Methods

new(host, port=9090, timeout=5) click to toggle source
# File lib/thrift_client/event_machine.rb, line 10
def initialize(host, port=9090, timeout=5)
  @host, @port, @timeout = host, port, timeout
  @connection = nil
end

Public Instance Methods

close() click to toggle source
# File lib/thrift_client/event_machine.rb, line 34
def close
  @connection.close
end
open() click to toggle source
# File lib/thrift_client/event_machine.rb, line 19
def open
  fiber = Fiber.current
  @connection = EventMachineConnection.connect(@host, @port, @timeout)
  @connection.callback do
    fiber.resume
  end
  @connection.errback do
    fiber.resume
  end
  Fiber.yield

  raise Thrift::TransportException, "Unable to connect to #{@host}:#{@port}" unless @connection.connected?
  @connection
end
open?() click to toggle source
# File lib/thrift_client/event_machine.rb, line 15
def open?
  @connection && @connection.connected?
end
read(sz) click to toggle source
# File lib/thrift_client/event_machine.rb, line 38
def read(sz)
  @connection.blocking_read(sz)
end
write(buf) click to toggle source
# File lib/thrift_client/event_machine.rb, line 42
def write(buf)
  @connection.send_data(buf)
end