Class: Thrift::EventMachineTransport
- Inherits:
-
BaseTransport
- Object
- BaseTransport
- Thrift::EventMachineTransport
- Defined in:
- lib/thrift_client/event_machine.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(host, port = 9090, timeout = 5) ⇒ EventMachineTransport
constructor
A new instance of EventMachineTransport.
- #open ⇒ Object
- #open? ⇒ Boolean
- #read(sz) ⇒ Object
- #write(buf) ⇒ Object
Methods inherited from BaseTransport
Constructor Details
#initialize(host, port = 9090, timeout = 5) ⇒ EventMachineTransport
Returns a new instance of EventMachineTransport.
10 11 12 13 |
# 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 |
Instance Method Details
#close ⇒ Object
34 35 36 |
# File 'lib/thrift_client/event_machine.rb', line 34 def close @connection.close end |
#open ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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? ⇒ Boolean
15 16 17 |
# File 'lib/thrift_client/event_machine.rb', line 15 def open? @connection && @connection.connected? end |
#read(sz) ⇒ Object
38 39 40 |
# File 'lib/thrift_client/event_machine.rb', line 38 def read(sz) @connection.blocking_read(sz) end |
#write(buf) ⇒ Object
42 43 44 |
# File 'lib/thrift_client/event_machine.rb', line 42 def write(buf) @connection.send_data(buf) end |