Class: MessagePack::RPC::Client
- Includes:
- LoopUtil
- Defined in:
- lib/msgpack/rpc/client.rb
Overview
Client is usable for RPC client. Note that Client includes LoopUtil.
Defined Under Namespace
Classes: Base
Instance Attribute Summary
Attributes included from LoopUtil
Attributes inherited from Session
Class Method Summary collapse
-
.open(*args, &block) ⇒ Object
call-seq: Client.open(arg1, arg2, arg3=nil) {|client| }.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(arg1, arg2, arg3 = nil) ⇒ Client
constructor
1.
Methods included from LoopUtil
#run, #start_timer, #stop, #submit
Methods inherited from Session
#call, #call_apply, #call_async, #call_async_apply, #callback, #callback_apply, #host, #notify, #notify_apply, #on_connect_failed, #on_response, #port, #send, #send_without_call_async, #step_timeout
Constructor Details
#initialize(arg1, arg2, arg3 = nil) ⇒ Client
-
initialize(builder, address, loop = Loop.new)
-
initialize(host, port, loop = Loop.new)
Creates a client.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/msgpack/rpc/client.rb', line 29 def initialize(arg1, arg2, arg3=nil) if arg1.respond_to?(:build_transport) # 1. builder = arg1 address = arg2 loop = arg3 || Loop.new else # 2. builder = TCPTransport.new address = Address.new(arg1, arg2) loop = arg3 || Loop.new end super(builder, address, loop) @timer = Timer.new(1, true, &method(:step_timeout)) loop.attach(@timer) end |
Class Method Details
.open(*args, &block) ⇒ Object
call-seq:
Client.open(arg1, arg2, arg3=nil) {|client| }
-
open(builder, address, loop = Loop.new) {|client }
-
open(host, port, loop = Loop.new) {|client }
Creates a client, calls the block and closes the client.
54 55 56 57 58 59 60 61 |
# File 'lib/msgpack/rpc/client.rb', line 54 def self.open(*args, &block) c = new(*args) begin block.call(c) ensure c.close end end |
Instance Method Details
#close ⇒ Object
63 64 65 66 |
# File 'lib/msgpack/rpc/client.rb', line 63 def close @timer.detach if @timer.attached? super end |