class Thrift::EventMachineTransport
Public Class Methods
new(host, port=9090, timeout=nil)
click to toggle source
# File lib/thrift_client/thrift/transport.rb, line 9 def initialize(host, port=9090, timeout=nil) @host, @port, @timeout = host, port, timeout @connection = nil end
Public Instance Methods
close()
click to toggle source
# File lib/thrift_client/thrift/transport.rb, line 46 def close @connection.close if @connection && @connection.connected? end
open()
click to toggle source
# File lib/thrift_client/thrift/transport.rb, line 18 def open @connection = EventMachine.connect(@host, @port, EventMachineConnection) do |conn| conn.pending_connect_timeout = @timeout end fiber = Fiber.current @connection.callback { |arg| if fiber == Fiber.current return arg else fiber.resume(arg) end } @connection.errback { |arg| if fiber == Fiber.current return arg else fiber.resume(arg) end } Fiber.yield raise TransportException, TransportException::NOT_OPEN, "Unable to connect to #{@host}:#{@port}" unless @connection.connected? @connection end
open?()
click to toggle source
# File lib/thrift_client/thrift/transport.rb, line 14 def open? @connection && @connection.connected? end
read(sz)
click to toggle source
# File lib/thrift_client/thrift/transport.rb, line 50 def read(sz) raise IOError, "read failed, closed stream." unless open? @connection.read(sz,@timeout) end
write(buf)
click to toggle source
# File lib/thrift_client/thrift/transport.rb, line 55 def write(buf) raise IOError, "write failed, closed stream." unless open? @connection.write(buf,@timeout) end