msgpack-rpc-stack 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd76cc71b043173ef94c8f7d21041a9ac2490c03f2cfc936ad3dddb3e0cb40b8
4
- data.tar.gz: b0d2e72657bf2e3bca72870f9f1ca7388178cf33d708080a3f0ec32531aa2a47
3
+ metadata.gz: cf8e71b65201dd61e5b8259ee20d5f628c5a5a3bc3684b3d190ef94908ef5eec
4
+ data.tar.gz: '0289f60792cca6e01901e73e6a3b7cc68571cc7b07f839c533abc9ef2de97a13'
5
5
  SHA512:
6
- metadata.gz: f8ae673b9d04a9ea9ff4baaad08b4d4c1af92df50f93f8f72fcc4941171c1c05eea8a8ff7438a43b92c804f79a3f1a64824ff8225e4a4e22fafc03896a864dc4
7
- data.tar.gz: 74142d315c72fe443f8fcf5aaf952a453ffae01a19208d332a73ad93a662bb7690429f07aa8d73a543962cdf68b532cf3e31b1b13d969f171cfbc2948aa5cdaf
6
+ metadata.gz: d96dac975cdfd57084a1cd95810161f07555154b041cb81c938b7f6231c7463d147fcf2ad02deebc3ea7a4d595e09c162406854eef35fb7bc721a0a6b243d014
7
+ data.tar.gz: e7e52fac2bc255732ce7efe290bab9720482a17efe593c8bd61cc10399d029ece0e8f0205ce77af867aa79b7fd37031b4800a5c4fd0ae3575e2b86503421bce3
@@ -12,6 +12,13 @@ require 'msgpack/rpc'
12
12
 
13
13
  module MessagePack
14
14
  module Rpc
15
+ #
16
+ # Module that implemented client protocol of MessagePack-RPC.
17
+ #
18
+ # @abstract
19
+ # Include from the class that implements the rpc client.
20
+ # If you receive a protocol level error, override the on_error method.
21
+ #
15
22
  module Client
16
23
  class << self
17
24
  def included(klass)
@@ -67,6 +74,27 @@ module MessagePack
67
74
  end
68
75
  private :error_occured
69
76
 
77
+ #
78
+ # call the procedure of peer rpc server
79
+ #
80
+ # @param [Symbol] meth
81
+ # target procedure name.
82
+ #
83
+ # @param [Array] args
84
+ # arguments for procedure.
85
+ #
86
+ # @return [Integer]
87
+ # assigned mesaage id
88
+ #
89
+ # @yield [res, err]
90
+ # callback that is when the procedure call completes.
91
+ #
92
+ # @yieldparam [Object] res
93
+ # responce of procedure when procedure successed.
94
+ #
95
+ # @yieldparam [Object] err
96
+ # error data of procedure when procedure failed.
97
+ #
70
98
  def call(meth, *args, &blk)
71
99
  raise ArgumentError.new("handler is not spcified") if not blk
72
100
 
@@ -78,14 +106,34 @@ module MessagePack
78
106
  return id
79
107
  end
80
108
 
81
- def notify(meth, *args)
82
- send_data([2, meth, args].to_msgpack)
83
- end
84
-
109
+ #
110
+ # cacel the call message
111
+ #
112
+ # @param [Integer] id
113
+ # message id of calling message (return value of
114
+ # MessagePack::Rpc::Client#call())
115
+ #
116
+ # @note
117
+ # When this method is called, the procedure call corresponding to
118
+ # the ID specified in the argument is cancelled.
119
+ #
85
120
  def cancel(id)
86
121
  session_map.delete(id)
87
122
  end
88
123
 
124
+ #
125
+ # send the notification to peer rpc server
126
+ #
127
+ # @param [Symbol] meth
128
+ # notify name
129
+ #
130
+ # @param [Array] args
131
+ # argument for notification
132
+ #
133
+ def notify(meth, *args)
134
+ send_data([2, meth, args].to_msgpack)
135
+ end
136
+
89
137
  def eval_response(resp)
90
138
  if not resp.kind_of?(Array)
91
139
  error_occured("responce is not array")
@@ -128,10 +176,27 @@ module MessagePack
128
176
  end
129
177
  private :eval_response
130
178
 
179
+ #
180
+ # emqueu the received datagram to communication buffer
181
+ #
182
+ # @param [Blob] data
183
+ # recevied data from rpc server.
184
+ #
185
+ # @note
186
+ # Use this method for datagram communication. \
187
+ # Use it when it is guaranteed that data is exchanged \
188
+ # in packets (it works a bit faster).
189
+ #
131
190
  def receive_dgram(data)
132
191
  eval_response(MessagePack.unpack(data, self.class.msgpack_options))
133
192
  end
134
193
 
194
+ #
195
+ # emqueu the received data to communication buffer
196
+ #
197
+ # @param [Blob] data
198
+ # recevied data from rpc server.
199
+ #
135
200
  def receive_stream(data)
136
201
  begin
137
202
  unpacker.feed_each(data) {|resp| eval_response(resp)}
@@ -145,6 +210,16 @@ module MessagePack
145
210
  end
146
211
  end
147
212
 
213
+ #
214
+ # define the notify method
215
+ #
216
+ # @param [Symbol] name
217
+ # notification name
218
+ #
219
+ # @yield [*args]
220
+ # callback that is when received the notification
221
+ # from peer rpc server.
222
+ #
148
223
  def on(name, &blk)
149
224
  raise ArgumentError.new("handler is not spcified") if not blk
150
225
  notify_handler[name] = blk
@@ -12,8 +12,82 @@ require 'msgpack/rpc'
12
12
 
13
13
  module MessagePack
14
14
  module Rpc
15
+
16
+ #
17
+ # Module that implemented server protocol of MessagePack-RPC.
18
+ #
19
+ # @abstract
20
+ # Include from the class that implements the rpc server. You can expose
21
+ # If you receive a protocol level error, override the on_error method.
22
+ # the methods defined in that class as RPC procedures.
23
+ #
15
24
  module Server
16
25
  class << self
26
+ #
27
+ # @!method msgpack_options(**opts)
28
+ # set MessagePack::Unpacker option.
29
+ #
30
+ # @example set :symbolize_keys option
31
+ # class Server
32
+ # include MessagePack::Rpc::Server
33
+ #
34
+ # msgpack_options = {:symbolize_keys => true}
35
+ #
36
+ # def test(data)
37
+ # # data's key are symbolized.
38
+ # return data[:data]
39
+ # end
40
+ # remote_public :test
41
+ # end
42
+
43
+ #
44
+ # @!method remote_public(name)
45
+ # expose syncronous procedure.
46
+ # The return value of the method exposed by this method is the
47
+ # return value of the procedure. If an exception occurs, the
48
+ # exception is returned as an error value.
49
+ #
50
+ # @param [Symbol] name
51
+ # target method name.
52
+ #
53
+ # @example expose syncronous procedure
54
+ # class Server
55
+ # include MessagePack::Rpc::Server
56
+ #
57
+ # def test(id)
58
+ # raise("id isnot defined") if id.nil?
59
+ # return "hello #{id}"
60
+ # end
61
+ # remote_public :test
62
+ # end
63
+ #
64
+
65
+ #
66
+ # @!method remote_async(name)
67
+ # expose asynchronous procedure.
68
+ # The method exposed by this method takes a deferred object as its
69
+ # first argument. Returns the processing result asynchronously
70
+ # through this object.
71
+ #
72
+ # @param [Symbol] name
73
+ # target method name.
74
+ #
75
+ # @example expose asyncronous procedure
76
+ # class Server
77
+ # include MessagePack::Rpc::Server
78
+ #
79
+ # def test(df, id)
80
+ # if id.nil?
81
+ # df.reject("id isnot defined")
82
+ # else
83
+ # df.resolve("hello #{id}")
84
+ # end
85
+ # end
86
+ # remote_async :test
87
+ # end
88
+ #
89
+
90
+ # @!visibility protected
17
91
  def included(klass)
18
92
  m = Module.new {
19
93
  @@error = Class.new(StandardError) {
@@ -197,10 +271,30 @@ module MessagePack
197
271
  end
198
272
  private :eval_message
199
273
 
274
+ #
275
+ # send the notification to peer rpc client
276
+ #
277
+ # @param [Symbol] meth
278
+ # notify name
279
+ #
280
+ # @param [Array] args
281
+ # argument for notification
282
+ #
200
283
  def notify(meth, *args)
201
284
  send_data([2, meth, args].to_msgpack)
202
285
  end
203
286
 
287
+ #
288
+ # emqueu the received datagram to communication buffer
289
+ #
290
+ # @param [Blob] data
291
+ # recevied data from peer rpc client.
292
+ #
293
+ # @note
294
+ # Use this method for datagram communication. \
295
+ # Use it when it is guaranteed that data is exchanged \
296
+ # in packets (it works a bit faster).
297
+ #
204
298
  def receive_dgram(data)
205
299
  msg = MessagePack.unpack(data, self.class.msgpack_options)
206
300
 
@@ -211,6 +305,12 @@ module MessagePack
211
305
  eval_message(msg)
212
306
  end
213
307
 
308
+ #
309
+ # emqueu the received data to communication buffer
310
+ #
311
+ # @param [Blob] data
312
+ # recevied data from peer rpc client.
313
+ #
214
314
  def receive_stream(data)
215
315
  begin
216
316
  unpacker.feed_each(data) {|msg| eval_message(msg)}
@@ -1,5 +1,5 @@
1
1
  module MessagePack
2
2
  module Rpc
3
- VERSION = "0.7.0"
3
+ VERSION = "0.7.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack-rpc-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Kuwagata