Class: MessagePack::RPC::Session
- Inherits:
-
Object
- Object
- MessagePack::RPC::Session
- Defined in:
- lib/msgpack/rpc/session.rb
Overview
Session is a abstract class corresponds with a remote host. You can call remote method using call, call_async, callback or notify method.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#loop ⇒ Object
readonly
Returns the value of attribute loop.
-
#timeout ⇒ Object
Sets and gets timeout in seconds.
Instance Method Summary collapse
-
#call(method, *args) ⇒ Object
call-seq: call(symbol, *args) -> result of remote method.
-
#call_apply(method, params) ⇒ Object
call-seq: call_apply(symbol, params) -> result of remote method.
-
#call_async(method, *args) ⇒ Object
call-seq: call_async(symbol, *args) -> Future.
-
#call_async_apply(method, params) ⇒ Object
call-seq: call_async_apply(symbol, params) -> Future.
-
#callback(method, *args, &block) ⇒ Object
call-seq: callback(symbol, *args) {|future| }.
-
#callback_apply(method, params, &block) ⇒ Object
call-seq: callback_apply(symbol, params) {|future| }.
-
#close ⇒ Object
Closes underlaying Transport and destroy resources.
-
#host ⇒ Object
backward compatibility.
-
#initialize(builder, address, loop) ⇒ Session
constructor
A new instance of Session.
-
#notify(method, *args) ⇒ Object
call-seq: notify(symbol, *args) -> nil.
-
#notify_apply(method, params) ⇒ Object
call-seq: notify_apply(symbol, params) -> nil.
-
#on_connect_failed ⇒ Object
from ClientTransport.
-
#on_response(sock, msgid, error, result) ⇒ Object
from ClientTransport.
-
#port ⇒ Object
backward compatibility.
- #send(method, *args) ⇒ Object
-
#send_without_call_async ⇒ Object
backward compatibility.
-
#step_timeout ⇒ Object
from Client, SessionPool.
Constructor Details
#initialize(builder, address, loop) ⇒ Session
Returns a new instance of Session.
25 26 27 28 29 30 31 32 |
# File 'lib/msgpack/rpc/session.rb', line 25 def initialize(builder, address, loop) @address = address @loop = loop @reqtable = {} @timeout = 10 # FIXME default timeout time @seqid = 0 @transport = builder.build_transport(self, address) end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
33 34 35 |
# File 'lib/msgpack/rpc/session.rb', line 33 def address @address end |
#loop ⇒ Object (readonly)
Returns the value of attribute loop.
33 34 35 |
# File 'lib/msgpack/rpc/session.rb', line 33 def loop @loop end |
#timeout ⇒ Object
Sets and gets timeout in seconds.
36 37 38 |
# File 'lib/msgpack/rpc/session.rb', line 36 def timeout @timeout end |
Instance Method Details
#call(method, *args) ⇒ Object
call-seq:
call(symbol, *args) -> result of remote method
Calls remote method. This method is same as call_async(method, *args).get
53 54 55 |
# File 'lib/msgpack/rpc/session.rb', line 53 def call(method, *args) send_request(method, args).get end |
#call_apply(method, params) ⇒ Object
call-seq:
call_apply(symbol, params) -> result of remote method
Calls remote method. This method is same as call(method, *args) excepting that the arugment is a array.
63 64 65 |
# File 'lib/msgpack/rpc/session.rb', line 63 def call_apply(method, params) send_request(method, params).get end |
#call_async(method, *args) ⇒ Object
call-seq:
call_async(symbol, *args) -> Future
Calls remote method asynchronously. This method is non-blocking and returns Future.
72 73 74 |
# File 'lib/msgpack/rpc/session.rb', line 72 def call_async(method, *args) future = send_request(method, args) end |
#call_async_apply(method, params) ⇒ Object
call-seq:
call_async_apply(symbol, params) -> Future
Calls remote method asynchronously. This method is same as call_async(method, *args) excepting that the arugment is a array.
82 83 84 |
# File 'lib/msgpack/rpc/session.rb', line 82 def call_async_apply(method, params) future = send_request(method, params) end |
#callback(method, *args, &block) ⇒ Object
call-seq:
callback(symbol, *args) {|future| }
Calls remote method asynchronously. The callback method is called with Future when the result is reached. This method is same as call_async(method, *args).attach_callback {|future| }
102 103 104 105 106 |
# File 'lib/msgpack/rpc/session.rb', line 102 def callback(method, *args, &block) future = send_request(method, args) future.attach_callback(block) future end |
#callback_apply(method, params, &block) ⇒ Object
call-seq:
callback_apply(symbol, params) {|future| }
Calls remote method asynchronously. The callback method is called with Future when the result is reached. This method is same as callback(method, *args).attach_callback {|future| } excepting that the argument is a array.
115 116 117 118 119 |
# File 'lib/msgpack/rpc/session.rb', line 115 def callback_apply(method, params, &block) future = send_request(method, params) future.attach_callback(block) future end |
#close ⇒ Object
Closes underlaying Transport and destroy resources.
146 147 148 149 150 151 |
# File 'lib/msgpack/rpc/session.rb', line 146 def close @transport.close @reqtable = {} @seqid = 0 self end |
#host ⇒ Object
backward compatibility
44 45 46 |
# File 'lib/msgpack/rpc/session.rb', line 44 def host #:nodoc: @address.host end |
#notify(method, *args) ⇒ Object
call-seq:
notify(symbol, *args) -> nil
Calls remote method with NOTIFY protocol. It doesn’t require server to return results. This method is non-blocking and returns nil.
127 128 129 130 |
# File 'lib/msgpack/rpc/session.rb', line 127 def notify(method, *args) send_notify(method, args) nil end |
#notify_apply(method, params) ⇒ Object
call-seq:
notify_apply(symbol, params) -> nil
Calls remote method with NOTIFY protocol. It doesn’t require server to return results. This method is non-blocking and returns nil. This method is same as notify(method, *args) excepting that the argument is a array.
140 141 142 143 |
# File 'lib/msgpack/rpc/session.rb', line 140 def notify_apply(method, params) send_notify(method, params) nil end |
#on_connect_failed ⇒ Object
from ClientTransport
161 162 163 164 165 166 167 |
# File 'lib/msgpack/rpc/session.rb', line 161 def on_connect_failed #:nodoc: @reqtable.reject! {|msgid, future| future.set_result ConnectionTimeoutError::CODE, ["connection timed out"] true } nil end |
#on_response(sock, msgid, error, result) ⇒ Object
from ClientTransport
154 155 156 157 158 |
# File 'lib/msgpack/rpc/session.rb', line 154 def on_response(sock, msgid, error, result) #:nodoc: if future = @reqtable.delete(msgid) future.set_result(error, result) end end |
#port ⇒ Object
backward compatibility
39 40 41 |
# File 'lib/msgpack/rpc/session.rb', line 39 def port #:nodoc: @address.port end |
#send(method, *args) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/msgpack/rpc/session.rb', line 88 def send(method, *args) if caller.first =~ /.*_test.rb/ || caller.first =~ /.*_spec.rb/ then warn "\n Don't use send method. Use 'call_async' method." end call_async(method, *args) end |
#send_without_call_async ⇒ Object
backward compatibility
87 |
# File 'lib/msgpack/rpc/session.rb', line 87 alias_method :send_without_call_async, :send |
#step_timeout ⇒ Object
from Client, SessionPool
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/msgpack/rpc/session.rb', line 170 def step_timeout #:nodoc: timedout = [] @reqtable.reject! {|msgid, future| if future.step_timeout timedout.push(future) true end } timedout.each {|future| future.set_result TimeoutError::CODE, ["request timed out"] } !@reqtable.empty? end |