Class: MessagePack::RPC::Client

Inherits:
Session
  • Object
show all
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

#loop

Attributes inherited from Session

#address, #loop, #timeout

Class Method Summary collapse

Instance Method Summary collapse

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

  1. initialize(builder, address, loop = Loop.new)

  2. 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|  }
  1. open(builder, address, loop = Loop.new) {|client }

  2. 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

#closeObject



63
64
65
66
# File 'lib/msgpack/rpc/client.rb', line 63

def close
	@timer.detach if @timer.attached?
	super
end