Class: MessagePack::RPC::ClientSession
- Inherits:
-
Object
- Object
- MessagePack::RPC::ClientSession
- Defined in:
- lib/msgpack/rpc.rb
Defined Under Namespace
Classes: BasicRequest
Instance Attribute Summary collapse
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #add_socket(sock) ⇒ Object
- #call(method, *args) ⇒ Object
- #callback(method, *args, &block) ⇒ Object
- #close ⇒ Object
-
#initialize(loop) ⇒ ClientSession
constructor
A new instance of ClientSession.
- #notify(method, *args) ⇒ Object
- #on_close(sock) ⇒ Object
- #on_notify(method, param) ⇒ Object
- #on_request(method, param, res) ⇒ Object
- #on_response(msgid, result, error) ⇒ Object
- #send(method, *args) ⇒ Object
- #step_timeout ⇒ Object
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
#timeout ⇒ Object
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 |
#close ⇒ Object
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
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
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_timeout ⇒ Object
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 |