Module: MessagePack::Rpc::Server Abstract
- Defined in:
- lib/msgpack/rpc/server.rb
Overview
Include from the class that implements the rpc server. You can expose When the client implementation class receives data from the communication line, it must call the receive_data() method and pass received data to the MessagePack::Rpc::Server module. Also, the client implementation class should define a method send_data() to actually send the data. Call this method from within the MessagePack::Rpc::Server module if necessary (Implement send_data() method to accept string objects in arguments). If you receive a protocol level error, override the on_error() method. the methods defined in that class as RPC procedures.
Module that implemented server protocol of MessagePack-RPC.
Class Method Summary collapse
-
.msgpack_options(**opts) ⇒ Object
set MessagePack::Unpacker option.
-
.remote_async(name) ⇒ Object
expose asynchronous procedure.
-
.remote_public(name) ⇒ Object
expose syncronous procedure.
Instance Method Summary collapse
-
#notify(meth, *args) ⇒ Object
send the notification to peer rpc client.
-
#receive_dgram(data) ⇒ Object
emqueu the received datagram to communication buffer.
-
#receive_stream(data) ⇒ Object
emqueu the received data to communication buffer.
- #reset_unpacker ⇒ Object
- #unpacker ⇒ Object
Class Method Details
.msgpack_options(**opts) ⇒ Object
set MessagePack::Unpacker option.
|
# File 'lib/msgpack/rpc/server.rb', line 33
|
.remote_async(name) ⇒ Object
expose asynchronous procedure. The method exposed by this method takes a deferred object as its first argument. Returns the processing result asynchronously through this object.
|
# File 'lib/msgpack/rpc/server.rb', line 72
|
.remote_public(name) ⇒ Object
expose syncronous procedure. The return value of the method exposed by this method is the return value of the procedure. If an exception occurs, the exception is returned as an error value.
|
# File 'lib/msgpack/rpc/server.rb', line 50
|
Instance Method Details
#notify(meth, *args) ⇒ Object
send the notification to peer rpc client
290 291 292 |
# File 'lib/msgpack/rpc/server.rb', line 290 def notify(meth, *args) send_data([2, meth, args].to_msgpack) end |
#receive_dgram(data) ⇒ Object
Use this method for datagram communication. Use it when it is guaranteed that data is exchanged in packets (it works a bit faster).
emqueu the received datagram to communication buffer
305 306 307 308 309 310 311 312 313 |
# File 'lib/msgpack/rpc/server.rb', line 305 def receive_dgram(data) msg = MessagePack.unpack(data, self.class.) if not msg.kind_of?(Array) error_occured(RantimeError.new("not array message is received")) end (msg) end |
#receive_stream(data) ⇒ Object
emqueu the received data to communication buffer
321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/msgpack/rpc/server.rb', line 321 def receive_stream(data) begin unpacker.feed_each(data) {|msg| (msg)} rescue MessagePack::UnpackError => e unpacker.reset error_occured(e) rescue => e error_occured(e) end end |
#reset_unpacker ⇒ Object
179 180 181 |
# File 'lib/msgpack/rpc/server.rb', line 179 def reset_unpacker @unpacker = nil end |
#unpacker ⇒ Object
175 176 177 |
# File 'lib/msgpack/rpc/server.rb', line 175 def unpacker return (@unpacker ||= self.class.new_unpacker) end |