Class: MessagePack::RPC::ClientSession

Inherits:
Object
  • Object
show all
Defined in:
lib/msgpack/rpc.rb

Defined Under Namespace

Classes: BasicRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loop) ⇒ ClientSession

Returns a new instance of ClientSession.



200
201
202
203
204
205
206
# File 'lib/msgpack/rpc.rb', line 200

def initialize(loop)
	@sock = nil
	@reqtable = {}
	@seqid = 0
	@loop = loop
	@timeout = 60    # FIXME default timeout time
end

Instance Attribute Details

#timeoutObject

Returns the value of attribute timeout.



207
208
209
# File 'lib/msgpack/rpc.rb', line 207

def timeout
  @timeout
end

Instance Method Details

#add_socket(sock) ⇒ Object



209
210
211
# File 'lib/msgpack/rpc.rb', line 209

def add_socket(sock)
	@sock = sock
end

#call(method, *args) ⇒ Object



221
222
223
224
225
226
227
228
229
# File 'lib/msgpack/rpc.rb', line 221

def call(method, *args)
	req = send(method, *args)
	req.join
	if req.error
		raise TimeoutError.new if req.error == :TimeoutError
		raise RemoteError.new(req.error, req.result)
	end
	req.result
end

#callback(method, *args, &block) ⇒ Object



217
218
219
# File 'lib/msgpack/rpc.rb', line 217

def callback(method, *args, &block)
	send_real(method, args, block)
end

#closeObject



254
255
256
# File 'lib/msgpack/rpc.rb', line 254

def close
	@sock.close if @sock
end

#notify(method, *args) ⇒ Object



231
232
233
# File 'lib/msgpack/rpc.rb', line 231

def notify(method, *args)
	notify_real(method, args)
end

#on_close(sock) ⇒ Object



250
251
252
# File 'lib/msgpack/rpc.rb', line 250

def on_close(sock)
	@sock = nil
end

#on_notify(method, param) ⇒ Object

Raises:



242
243
244
# File 'lib/msgpack/rpc.rb', line 242

def on_notify(method, param)
	raise RPCError.new("unexpected notify message")
end

#on_request(method, param, res) ⇒ Object

Raises:



246
247
248
# File 'lib/msgpack/rpc.rb', line 246

def on_request(method, param, res)
	raise RPCError.new("unexpected request message")
end

#on_response(msgid, result, error) ⇒ Object



236
237
238
239
240
# File 'lib/msgpack/rpc.rb', line 236

def on_response(msgid, result, error)
	if req = @reqtable.delete(msgid)
		req.call error, result
	end
end

#send(method, *args) ⇒ Object



213
214
215
# File 'lib/msgpack/rpc.rb', line 213

def send(method, *args)
	send_real(method, args, BasicRequest.new(self,@loop))
end

#step_timeoutObject



259
260
261
262
263
264
265
266
267
# File 'lib/msgpack/rpc.rb', line 259

def step_timeout
	reqs = []
	@reqtable.reject! {|msgid, req|
		if req.step_timeout
			reqs.push req
		end
	}
	reqs.each {|req| req.call :TimeoutError, nil }
end