Class: Arpie::RPCClient
Overview
A Client extension which provides a RPC-like interface. Used by ProxyClient.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Client
#connect_retry, #connect_sleep, #protocol
Instance Method Summary collapse
-
#initialize(*protocols) ⇒ RPCClient
constructor
A new instance of RPCClient.
-
#post_call(&handler) ⇒ Object
Callback that gets invoked after receiving an answer.
-
#pre_call(&handler) ⇒ Object
Callback that gets invoked before placing a call to the Server.
-
#request(message) ⇒ Object
Send a message and receive a reply in a synchronous fashion.
Methods inherited from Client
#connect, #io_retry, #on_error, #read_message, #write_message
Constructor Details
#initialize(*protocols) ⇒ RPCClient
Returns a new instance of RPCClient.
148 149 150 151 152 153 |
# File 'lib/arpie/client.rb', line 148 def initialize *protocols super(*protocols) @on_pre_call = lambda {|client, | } @on_post_call = lambda {|client, , reply| } end |
Instance Method Details
#post_call(&handler) ⇒ Object
Callback that gets invoked after receiving an answer. You can raise an exception here; and it will be passed to the caller, instead of returning the value.
166 167 168 169 |
# File 'lib/arpie/client.rb', line 166 def post_call &handler #:yields: client, message, reply @on_post_call = handler self end |
#pre_call(&handler) ⇒ Object
Callback that gets invoked before placing a call to the Server. You can stop the call from happening by raising an exception (which will be passed on to the caller).
158 159 160 161 |
# File 'lib/arpie/client.rb', line 158 def pre_call &handler #:yields: client, message @on_pre_call = handler self end |
#request(message) ⇒ Object
Send a message and receive a reply in a synchronous fashion. Will block until transmitted, or until all reconnect attempts failed.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/arpie/client.rb', line 175 def request reply = nil @on_pre_call.call(self, ) if @on_pre_call io_retry do () reply = end @on_post_call.call(self, , reply) if @on_post_call case reply when Exception raise reply else reply end end |