upfluence-thrift 2.6.1 → 2.7.4

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.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/benchmark/benchmark_constants.rb +11 -0
  3. data/benchmark/benchmark_service.rb +152 -0
  4. data/benchmark/benchmark_types.rb +10 -0
  5. data/ext/struct.c +5 -1
  6. data/lib/thrift/base_stream.rb +85 -0
  7. data/lib/thrift/bidi_stream.rb +183 -0
  8. data/lib/thrift/client.rb +84 -17
  9. data/lib/thrift/definition.rb +4 -0
  10. data/lib/thrift/inbound_stream.rb +72 -0
  11. data/lib/thrift/middleware.rb +42 -0
  12. data/lib/thrift/outbound_stream.rb +52 -0
  13. data/lib/thrift/processor.rb +287 -47
  14. data/lib/thrift/protocol/base_protocol.rb +35 -33
  15. data/lib/thrift/protocol/binary_protocol.rb +8 -1
  16. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  17. data/lib/thrift/protocol/compact_protocol.rb +8 -0
  18. data/lib/thrift/protocol/json_protocol.rb +21 -4
  19. data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
  20. data/lib/thrift/server/base_server.rb +8 -2
  21. data/lib/thrift/server/nonblocking_server.rb +5 -4
  22. data/lib/thrift/server/simple_server.rb +5 -1
  23. data/lib/thrift/server/thread_pool_server.rb +5 -1
  24. data/lib/thrift/server/threaded_server.rb +5 -1
  25. data/lib/thrift/transport/base_server_transport.rb +1 -1
  26. data/lib/thrift/transport/base_transport.rb +8 -0
  27. data/lib/thrift/transport/buffered_transport.rb +9 -1
  28. data/lib/thrift/transport/framed_transport.rb +9 -1
  29. data/lib/thrift/transport/http_client_transport.rb +4 -0
  30. data/lib/thrift/transport/io_stream_transport.rb +4 -1
  31. data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
  32. data/lib/thrift/transport/server_socket.rb +5 -0
  33. data/lib/thrift/transport/socket.rb +21 -17
  34. data/lib/thrift/transport/ssl_server_socket.rb +41 -0
  35. data/lib/thrift/transport/ssl_socket.rb +51 -0
  36. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  37. data/lib/thrift/transport/unix_socket.rb +5 -1
  38. data/lib/thrift/types/annotation/deprecation/deprecation_constants.rb +1 -1
  39. data/lib/thrift/types/annotation/deprecation/deprecation_types.rb +2 -2
  40. data/lib/thrift/types/annotation/exception/exception_constants.rb +17 -0
  41. data/lib/thrift/types/annotation/exception/exception_types.rb +44 -0
  42. data/lib/thrift/types/annotation/naming/naming_constants.rb +1 -1
  43. data/lib/thrift/types/annotation/naming/naming_types.rb +2 -2
  44. data/lib/thrift/types/annotation/rpc/rpc_constants.rb +17 -0
  45. data/lib/thrift/types/annotation/rpc/rpc_types.rb +74 -0
  46. data/lib/thrift/types/annotation_definition/annotation_definition_constants.rb +15 -0
  47. data/lib/thrift/types/annotation_definition/annotation_definition_types.rb +116 -0
  48. data/lib/thrift/types/constant_definition/constant_definition_constants.rb +15 -0
  49. data/lib/thrift/types/constant_definition/constant_definition_types.rb +292 -0
  50. data/lib/thrift/types/core/core_constants.rb +15 -0
  51. data/lib/thrift/types/core/core_types.rb +58 -0
  52. data/lib/thrift/types/enum_definition/enum_definition_constants.rb +15 -0
  53. data/lib/thrift/types/enum_definition/enum_definition_types.rb +106 -0
  54. data/lib/thrift/types/known/any/any_constants.rb +1 -1
  55. data/lib/thrift/types/known/any/any_types.rb +2 -2
  56. data/lib/thrift/types/known/duration/duration_constants.rb +1 -1
  57. data/lib/thrift/types/known/duration/duration_types.rb +2 -2
  58. data/lib/thrift/types/known/timestamp/timestamp_constants.rb +1 -1
  59. data/lib/thrift/types/known/timestamp/timestamp_types.rb +2 -2
  60. data/lib/thrift/types/plugin/plugin.rb +139 -0
  61. data/lib/thrift/types/plugin/plugin_constants.rb +15 -0
  62. data/lib/thrift/types/plugin/plugin_types.rb +106 -0
  63. data/lib/thrift/types/program_definition/program_definition_constants.rb +15 -0
  64. data/lib/thrift/types/program_definition/program_definition_types.rb +137 -0
  65. data/lib/thrift/types/service_definition/service_definition_constants.rb +15 -0
  66. data/lib/thrift/types/service_definition/service_definition_types.rb +160 -0
  67. data/lib/thrift/types/struct_definition/struct_definition_constants.rb +15 -0
  68. data/lib/thrift/types/struct_definition/struct_definition_types.rb +157 -0
  69. data/lib/thrift/types/type_definition/type_definition_constants.rb +15 -0
  70. data/lib/thrift/types/type_definition/type_definition_types.rb +242 -0
  71. data/lib/thrift/types/value/value_constants.rb +1 -1
  72. data/lib/thrift/types/value/value_types.rb +50 -51
  73. data/lib/thrift/types.rb +11 -3
  74. data/lib/thrift/union.rb +3 -6
  75. data/lib/thrift.rb +6 -0
  76. data/lib/types/annotation/deprecation/deprecation_constants.rb +16 -0
  77. data/lib/types/annotation/deprecation/deprecation_types.rb +42 -0
  78. data/lib/types/annotation/naming/naming_constants.rb +16 -0
  79. data/lib/types/annotation/naming/naming_types.rb +57 -0
  80. data/lib/types/annotation_definition/annotation_definition_constants.rb +14 -0
  81. data/lib/types/annotation_definition/annotation_definition_types.rb +114 -0
  82. data/lib/types/constant_definition/constant_definition_constants.rb +14 -0
  83. data/lib/types/constant_definition/constant_definition_types.rb +290 -0
  84. data/lib/types/core/core_constants.rb +14 -0
  85. data/lib/types/core/core_types.rb +56 -0
  86. data/lib/types/enum_definition/enum_definition_constants.rb +14 -0
  87. data/lib/types/enum_definition/enum_definition_types.rb +104 -0
  88. data/lib/types/known/any/any_constants.rb +16 -0
  89. data/lib/types/known/any/any_types.rb +59 -0
  90. data/lib/types/known/duration/duration_constants.rb +16 -0
  91. data/lib/types/known/duration/duration_types.rb +59 -0
  92. data/lib/types/known/timestamp/timestamp_constants.rb +16 -0
  93. data/lib/types/known/timestamp/timestamp_types.rb +59 -0
  94. data/lib/types/plugin/plugin.rb +137 -0
  95. data/lib/types/plugin/plugin_constants.rb +14 -0
  96. data/lib/types/plugin/plugin_types.rb +104 -0
  97. data/lib/types/program_definition/program_definition_constants.rb +14 -0
  98. data/lib/types/program_definition/program_definition_types.rb +135 -0
  99. data/lib/types/service_definition/service_definition_constants.rb +14 -0
  100. data/lib/types/service_definition/service_definition_types.rb +158 -0
  101. data/lib/types/struct_definition/struct_definition_constants.rb +14 -0
  102. data/lib/types/struct_definition/struct_definition_types.rb +155 -0
  103. data/lib/types/type_definition/type_definition_constants.rb +14 -0
  104. data/lib/types/type_definition/type_definition_types.rb +240 -0
  105. data/lib/types/value/value_constants.rb +14 -0
  106. data/lib/types/value/value_types.rb +330 -0
  107. data/spec/base/base_service.rb +152 -0
  108. data/spec/base/base_service_constants.rb +11 -0
  109. data/spec/base/base_service_types.rb +45 -0
  110. data/spec/base_protocol_spec.rb +79 -71
  111. data/spec/base_transport_spec.rb +155 -117
  112. data/spec/binary_protocol_accelerated_spec.rb +6 -2
  113. data/spec/binary_protocol_spec.rb +16 -8
  114. data/spec/binary_protocol_spec_shared.rb +77 -77
  115. data/spec/bytes_spec.rb +38 -38
  116. data/spec/client_spec.rb +48 -50
  117. data/spec/compact_protocol_spec.rb +59 -46
  118. data/spec/exception_spec.rb +54 -54
  119. data/spec/extended/extended_service.rb +137 -0
  120. data/spec/extended/extended_service_constants.rb +11 -0
  121. data/spec/extended/extended_service_types.rb +12 -0
  122. data/spec/flat_spec.rb +5 -5
  123. data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +507 -0
  124. data/spec/gen-rb/flat/referenced_constants.rb +11 -0
  125. data/spec/gen-rb/flat/referenced_types.rb +17 -0
  126. data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +11 -0
  127. data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +47 -0
  128. data/spec/http_client_spec.rb +96 -43
  129. data/spec/json_protocol_spec.rb +170 -131
  130. data/spec/namespaced_spec.rb +24 -27
  131. data/spec/namespaced_spec_namespace/namespaced_nonblocking_service.rb +507 -0
  132. data/spec/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +11 -0
  133. data/spec/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +47 -0
  134. data/spec/nonblocking_server_spec.rb +16 -16
  135. data/spec/nonblocking_service.rb +507 -0
  136. data/spec/other_namespace/referenced_constants.rb +11 -0
  137. data/spec/other_namespace/referenced_types.rb +17 -0
  138. data/spec/processor_spec.rb +42 -31
  139. data/spec/rack_application_spec.rb +22 -26
  140. data/spec/serializer_spec.rb +20 -20
  141. data/spec/server_socket_spec.rb +27 -22
  142. data/spec/server_spec.rb +91 -51
  143. data/spec/socket_spec.rb +23 -16
  144. data/spec/socket_spec_shared.rb +31 -31
  145. data/spec/spec_helper.rb +17 -17
  146. data/spec/ssl_server_socket_spec.rb +34 -0
  147. data/spec/ssl_socket_spec.rb +78 -0
  148. data/spec/streaming_spec.rb +442 -0
  149. data/spec/struct_nested_containers_spec.rb +24 -24
  150. data/spec/struct_spec.rb +120 -120
  151. data/spec/thin_http_server_spec.rb +71 -28
  152. data/spec/thrift_spec_constants.rb +11 -0
  153. data/spec/thrift_spec_types.rb +1173 -0
  154. data/spec/types/known/any_spec.rb +2 -2
  155. data/spec/types/known/duration_spec.rb +1 -1
  156. data/spec/types/known/timestamp_spec.rb +1 -1
  157. data/spec/types/value_spec.rb +2 -1
  158. data/spec/types_spec.rb +56 -53
  159. data/spec/union_spec.rb +51 -40
  160. data/spec/unix_socket_spec.rb +43 -34
  161. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +281 -0
  162. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +2033 -0
  163. data/test/debug_proto/gen-rb/empty_service.rb +52 -0
  164. data/test/debug_proto/gen-rb/inherited.rb +155 -0
  165. data/test/debug_proto/gen-rb/reverse_order_service.rb +169 -0
  166. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +150 -0
  167. data/test/debug_proto/gen-rb/srv.rb +718 -0
  168. metadata +202 -7
@@ -8,6 +8,18 @@ module Thrift
8
8
  def handle_unary(_mth, args = {}, &block)
9
9
  block.call(args)
10
10
  end
11
+
12
+ def handle_bidi_stream(_mth, args, istream, ostream, &block)
13
+ block.call(args, istream, ostream)
14
+ end
15
+
16
+ def handle_inbound_stream(_mth, args, istream, &block)
17
+ block.call(args, istream)
18
+ end
19
+
20
+ def handle_outbound_stream(_mth, args, ostream, &block)
21
+ block.call(args, ostream)
22
+ end
11
23
  end
12
24
 
13
25
  class MultiMiddleware
@@ -30,6 +42,36 @@ module Thrift
30
42
  end
31
43
  end.call(args)
32
44
  end
45
+
46
+ def handle_bidi_stream(_mth, args, istream, ostream, &block)
47
+ @middlewares.reverse.reduce(block) do |acc, m|
48
+ Proc.new do |args, istream, ostream|
49
+ m.handle_bidi_stream(mth, args, istream, ostream) do |args, istream, ostream|
50
+ acc.call(args, istream, ostream)
51
+ end
52
+ end
53
+ end.call(args, istream, ostream)
54
+ end
55
+
56
+ def handle_inbound_stream(_mth, args, istream, &block)
57
+ @middlewares.reverse.reduce(block) do |acc, m|
58
+ Proc.new do |args, istream|
59
+ m.handle_bidi_stream(mth, args, istream) do |args, istream|
60
+ acc.call(args, istream)
61
+ end
62
+ end
63
+ end.call(args, istream)
64
+ end
65
+
66
+ def handle_outbound_stream(_mth, args, ostream, &block)
67
+ @middlewares.reverse.reduce(block) do |acc, m|
68
+ Proc.new do |args, ostream|
69
+ m.handle_bidi_stream(mth, args, ostream) do |args, ostream|
70
+ acc.call(args, ostream)
71
+ end
72
+ end
73
+ end.call(args, ostream)
74
+ end
33
75
  end
34
76
 
35
77
  NOP_MIDDLEWARE = NopMiddleware.new
@@ -0,0 +1,52 @@
1
+ module Thrift
2
+ class TOutboundStream < TBaseStream
3
+ def initialize(iprot, oprot, name, seqid, klass, message_type, unlock = nil)
4
+ @message_type = message_type
5
+ @klass = klass
6
+ @unlock = unlock
7
+ super(iprot, oprot, name, seqid)
8
+ end
9
+
10
+ def ready
11
+ Thread.new { read_goaway }
12
+ super
13
+ end
14
+
15
+ def close
16
+ wait_ready
17
+
18
+ write_shell @message_type + 1
19
+
20
+ @mutex.synchronize do
21
+ loop do
22
+ @cond.wait(@mutex)
23
+
24
+ return nil if @closed
25
+ end
26
+ end
27
+ end
28
+
29
+ def send(arg)
30
+ raise EOFError if @closed
31
+
32
+ unless @oprot.trans.open?
33
+ mark_as_closed
34
+ raise EOFError
35
+ end
36
+
37
+ wait_ready
38
+ write @message_type, @klass.new(arg: arg)
39
+ end
40
+
41
+ private
42
+
43
+ def read_goaway
44
+ mtype = read_shell
45
+
46
+ write_shell @message_type + 2 if mtype == (@message_type + 1)
47
+ ensure
48
+ mark_as_closed
49
+ @unlock&.call
50
+ end
51
+ end
52
+ end
@@ -17,6 +17,8 @@
17
17
  # under the License.
18
18
  #
19
19
 
20
+ require 'logger'
21
+
20
22
  module Thrift
21
23
  module Processor
22
24
  class BaseProcessorFunction
@@ -95,83 +97,321 @@ module Thrift
95
97
  end
96
98
  end
97
99
 
98
- def initialize(handler, middlewares = [])
100
+ def initialize(handler, middlewares = [], logger=nil)
99
101
  @handler = handler
102
+ if logger.nil?
103
+ @logger = Logger.new(STDERR)
104
+ @logger.level = Logger::WARN
105
+ else
106
+ @logger = logger
107
+ end
100
108
  @middleware = Middleware.wrap(middlewares)
101
109
 
102
- @functions = if self.class.const_defined?(:METHODS)
103
- self.class::METHODS.reduce({}) do |acc, (key, args)|
104
- klass = args[:oneway] ? UnaryProcessorFunction : BinaryProcessorFunction
110
+ @processors = if self.class.const_defined? :METHODS
111
+ self.class::METHODS.reduce({}) do |acc, (name, info)|
112
+ acc.merge(name => build_processor(name, info))
113
+ end
114
+ else
115
+ {}
116
+ end
117
+ end
105
118
 
106
- acc.merge key => klass.new(
107
- key,
108
- @middleware,
109
- args[:args_klass],
110
- method("execute_#{key}")
111
- )
112
- end
113
- end || {}
119
+ def read_args(iprot, args_class)
120
+ args = args_class.new
121
+ args.read(iprot)
122
+ iprot.read_message_end
123
+ args
124
+ end
125
+
126
+ def write_result(result, oprot, name, seqid)
127
+ oprot.write_message_begin(name, MessageTypes::REPLY, seqid)
128
+ result.write(oprot)
129
+ oprot.write_message_end
130
+ oprot.trans.flush
114
131
  end
115
132
 
116
133
  def process(iprot, oprot)
117
134
  name, _type, seqid = iprot.read_message_begin
118
135
 
119
- func = @functions[name]
136
+ mth = "process_#{name}"
137
+ if respond_to?(mth)
138
+ send(mth, seqid, iprot, oprot)
139
+ return true
140
+ end
120
141
 
121
- return func.process(seqid, iprot, oprot) if func
142
+ (
143
+ @processors[name] || UnkwonFunctionProcessor.new(name)
144
+ ).process(seqid, iprot, oprot)
145
+ end
122
146
 
123
- # TODO: once all the stubs will be generated w thrift >=2.5 the next lines
124
- # can be deleted
125
- if respond_to?("process_#{name}")
126
- begin
127
- send("process_#{name}", seqid, iprot, oprot)
128
- rescue => e
129
- write_exception(e, oprot, name, seqid)
130
- end
131
- true
147
+ def build_processor(name, info)
148
+ if info[:result_klass].nil?
149
+ UnaryProcessor
150
+ elsif info[:stream_klass].nil? && info[:sink_klass].nil?
151
+ BinaryProcessor
152
+ elsif info[:sink_klass].nil?
153
+ OutboundStreamProcessor
154
+ elsif info[:stream_klass].nil?
155
+ InboundStreamProcessor
132
156
  else
133
- iprot.skip(Types::STRUCT)
157
+ BidiStreamProcessor
158
+ end.new(name, info, @middleware, @handler)
159
+ end
160
+
161
+ class BaseProcessor
162
+ def initialize(name, args_class)
163
+ @name = name
164
+ @args_class = args_class
165
+ end
166
+
167
+ protected
168
+
169
+ def read_args(iprot)
170
+ args = @args_class.new
171
+ args.read(iprot)
134
172
  iprot.read_message_end
173
+ args
174
+ end
175
+
176
+ def write_exception(exception, oprot, name, seqid)
177
+ oprot.write_message_begin(name, MessageTypes::EXCEPTION, seqid)
178
+
179
+ unless exception.is_a? ApplicationException
180
+ exception = ApplicationException.new(
181
+ ApplicationException::INTERNAL_ERROR,
182
+ "Internal error processing #{name}: #{exception.class}: #{exception}"
183
+ )
184
+ end
185
+
186
+ exception.write(oprot)
187
+ oprot.write_message_end
188
+ oprot.trans.flush
189
+ end
190
+
191
+ def write_result(result, oprot, seqid)
192
+ oprot.write_message_begin(@name, MessageTypes::REPLY, seqid)
193
+ result.write(oprot)
194
+ oprot.write_message_end
195
+ oprot.trans.flush
196
+ end
197
+ end
198
+
199
+ class UnaryProcessor < BaseProcessor
200
+ def initialize(name, info, middleware, handler)
201
+ @middleware = middleware
202
+ @handler = handler
203
+ @arg_keys = info[:args]
204
+
205
+ super name, info[:args_klass]
206
+ end
207
+
208
+ def process(_seqid, iprot, _oprot)
209
+ @middleware.handle_unary(@name, read_args(iprot)) do |args|
210
+ @handler.send(@name, *@arg_keys.map { |k| args.send k })
211
+ nil
212
+ end
213
+
214
+ true
215
+ end
216
+ end
217
+
218
+ class BinaryProcessor < BaseProcessor
219
+ def initialize(name, info, middleware, handler)
220
+ @middleware = middleware
221
+ @handler = handler
222
+ @arg_keys = info[:args]
223
+ @void_result = info[:void_result]
224
+ @result_klass = info[:result_klass]
225
+ @exceptions = info[:exceptions]
226
+
227
+ super name, info[:args_klass]
228
+ end
229
+
230
+ def process(seqid, iprot, oprot)
231
+ res = @middleware.handle_binary(@name, read_args(iprot)) do |args|
232
+ execute(args)
233
+ end
234
+
235
+ write_result(res, oprot, seqid)
236
+
237
+ true
238
+ rescue ApplicationException => e
239
+ write_exception(e, oprot, @name, seqid)
240
+ true
241
+ rescue StandardError => e
135
242
  write_exception(
136
243
  ApplicationException.new(
137
- ApplicationException::UNKNOWN_METHOD,
138
- 'Unknown function ' + name,
244
+ ApplicationException::INTERNAL_ERROR,
245
+ "Internal error processing #{@name}: #{e.class}: #{e}"
139
246
  ),
140
247
  oprot,
141
- name,
248
+ @name,
142
249
  seqid
143
250
  )
144
- false
251
+ true
252
+ end
253
+
254
+ protected
255
+
256
+ def execute(args, *extra_args)
257
+ res = @result_klass.new
258
+
259
+ begin
260
+ s = @handler.send(
261
+ @name,
262
+ *@arg_keys.map { |k| args.send k },
263
+ *extra_args
264
+ )
265
+
266
+ res.success = s unless @void_result
267
+ rescue => e
268
+ k, = @exceptions.find { |(_, klass)| e.is_a? klass }
269
+
270
+ raise e unless k
271
+
272
+ res.send "#{k}=", e
273
+ end
274
+
275
+ res
145
276
  end
146
277
  end
147
278
 
148
- def read_args(iprot, args_class)
149
- args = args_class.new
150
- args.read(iprot)
151
- iprot.read_message_end
152
- args
279
+ class BaseStreamProcessor < BinaryProcessor
280
+ def initialize(name, info, middleware, handler)
281
+ @mutex = Mutex.new
282
+ @cond = ConditionVariable.new
283
+ @closed = false
284
+
285
+ super name, info, middleware, handler
286
+ end
287
+
288
+ protected
289
+
290
+ def close
291
+ @mutex.synchronize do
292
+ @closed = true
293
+ @cond.broadcast
294
+ end
295
+ end
296
+
297
+ def wait
298
+ @mutex.synchronize do
299
+ @cond.wait(@mutex) unless @closed
300
+ end
301
+ end
153
302
  end
154
303
 
155
- def write_exception(exception, oprot, name, seqid)
156
- oprot.write_message_begin(name, MessageTypes::EXCEPTION, seqid)
304
+ class OutboundStreamProcessor < BaseStreamProcessor
305
+ def initialize(name, info, middleware, handler)
306
+ @stream_klass = info[:stream_klass]
307
+
308
+ super name, info, middleware, handler
309
+ end
157
310
 
158
- unless exception.is_a? ApplicationException
159
- exception = ApplicationException.new(
160
- ApplicationException::INTERNAL_ERROR,
161
- "Internal error processing #{name}: #{exception.class}: #{exception}"
311
+ def process(seqid, iprot, oprot)
312
+ @closed = false
313
+ stream = TOutboundStream.new(
314
+ iprot, oprot, @name, seqid, @stream_klass,
315
+ MessageTypes::SERVER_STREAM_MESSAGE,
316
+ method(:close)
162
317
  )
318
+ res = @middleware.handle_outbound_stream(
319
+ @name, read_args(iprot), stream
320
+ ) { |args, stream| execute(args, stream) }
321
+
322
+ write_result(res, oprot, seqid)
323
+ stream.ready
324
+
325
+ wait
326
+
327
+ true
163
328
  end
329
+ end
164
330
 
165
- exception.write(oprot)
166
- oprot.write_message_end
167
- oprot.trans.flush
331
+ class InboundStreamProcessor < BaseStreamProcessor
332
+ def initialize(name, info, middleware, handler)
333
+ @sink_klass = info[:sink_klass]
334
+
335
+ super name, info, middleware, handler
336
+ end
337
+
338
+ def process(seqid, iprot, oprot)
339
+ @closed = false
340
+ stream = TInboundStream.new(
341
+ iprot, oprot, @name, seqid, @sink_klass,
342
+ MessageTypes::CLIENT_STREAM_MESSAGE,
343
+ method(:close)
344
+ )
345
+
346
+ res = @middleware.handle_inbound_stream(
347
+ @name, read_args(iprot), stream
348
+ ) { |args, sink| execute(args, sink) }
349
+
350
+
351
+ write_result(res, oprot, seqid)
352
+ stream.ready
353
+
354
+ wait
355
+
356
+ true
357
+ end
168
358
  end
169
359
 
170
- def write_result(result, oprot, name, seqid)
171
- oprot.write_message_begin(name, MessageTypes::REPLY, seqid)
172
- result.write(oprot)
173
- oprot.write_message_end
174
- oprot.trans.flush
360
+ class BidiStreamProcessor < BaseStreamProcessor
361
+ def initialize(name, info, middleware, handler)
362
+ @sink_klass = info[:sink_klass]
363
+ @stream_klass = info[:stream_klass]
364
+
365
+ super name, info, middleware, handler
366
+ end
367
+
368
+ def process(seqid, iprot, oprot)
369
+ @closed = false
370
+
371
+ bidi_stream = TBidiStream.new(
372
+ iprot, oprot, @name, seqid, @sink_klass, @stream_klass,
373
+ MessageTypes::CLIENT_STREAM_MESSAGE,
374
+ MessageTypes::SERVER_STREAM_MESSAGE,
375
+ method(:close)
376
+ )
377
+
378
+ res = @middleware.handle_bidi_stream(
379
+ @name, read_args(iprot),
380
+ TBidiInboundStream.new(bidi_stream),
381
+ TBidiOutboundStream.new(bidi_stream)
382
+ ) do |args, sink, stream|
383
+ execute(args, stream, sink)
384
+ end
385
+
386
+ write_result(res, oprot, seqid)
387
+ bidi_stream.ready
388
+
389
+ wait
390
+
391
+ true
392
+ end
393
+ end
394
+
395
+ class UnkwonFunctionProcessor < BaseProcessor
396
+ def initialize(name)
397
+ super name, nil
398
+ end
399
+
400
+ def process(seqid, iprot, oprot)
401
+ iprot.skip(Types::STRUCT)
402
+ iprot.read_message_end
403
+ write_exception(
404
+ ApplicationException.new(
405
+ ApplicationException::UNKNOWN_METHOD,
406
+ 'Unknown function ' + @name,
407
+ ),
408
+ oprot,
409
+ @name,
410
+ seqid
411
+ )
412
+
413
+ false
414
+ end
175
415
  end
176
416
  end
177
417
  end
@@ -1,4 +1,4 @@
1
- #
1
+ #
2
2
  # Licensed to the Apache Software Foundation (ASF) under one
3
3
  # or more contributor license agreements. See the NOTICE file
4
4
  # distributed with this work for additional information
@@ -6,23 +6,21 @@
6
6
  # to you under the Apache License, Version 2.0 (the
7
7
  # "License"); you may not use this file except in compliance
8
8
  # with the License. You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing,
13
13
  # software distributed under the License is distributed on an
14
14
  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
15
  # KIND, either express or implied. See the License for the
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
- #
18
+ #
19
19
 
20
20
  # this require is to make generated struct definitions happy
21
- require 'set'
22
21
 
23
22
  module Thrift
24
23
  class ProtocolException < Exception
25
-
26
24
  UNKNOWN = 0
27
25
  INVALID_DATA = 1
28
26
  NEGATIVE_SIZE = 2
@@ -33,14 +31,13 @@ module Thrift
33
31
 
34
32
  attr_reader :type
35
33
 
36
- def initialize(type=UNKNOWN, message=nil)
34
+ def initialize(type = UNKNOWN, message = nil)
37
35
  super(message)
38
36
  @type = type
39
37
  end
40
38
  end
41
39
 
42
40
  class BaseProtocol
43
-
44
41
  attr_reader :trans
45
42
 
46
43
  def initialize(trans)
@@ -48,7 +45,7 @@ module Thrift
48
45
  end
49
46
 
50
47
  def native?
51
- puts "wrong method is being called!"
48
+ puts 'wrong method is being called!'
52
49
  false
53
50
  end
54
51
 
@@ -56,19 +53,19 @@ module Thrift
56
53
  raise NotImplementedError
57
54
  end
58
55
 
59
- def write_message_end; nil; end
56
+ def write_message_end = nil
60
57
 
61
58
  def write_struct_begin(name)
62
59
  raise NotImplementedError
63
60
  end
64
61
 
65
- def write_struct_end; nil; end
62
+ def write_struct_end = nil
66
63
 
67
64
  def write_field_begin(name, type, id)
68
65
  raise NotImplementedError
69
66
  end
70
67
 
71
- def write_field_end; nil; end
68
+ def write_field_end = nil
72
69
 
73
70
  def write_field_stop
74
71
  raise NotImplementedError
@@ -78,19 +75,19 @@ module Thrift
78
75
  raise NotImplementedError
79
76
  end
80
77
 
81
- def write_map_end; nil; end
78
+ def write_map_end = nil
82
79
 
83
80
  def write_list_begin(etype, size)
84
81
  raise NotImplementedError
85
82
  end
86
83
 
87
- def write_list_end; nil; end
84
+ def write_list_end = nil
88
85
 
89
86
  def write_set_begin(etype, size)
90
87
  raise NotImplementedError
91
88
  end
92
89
 
93
- def write_set_end; nil; end
90
+ def write_set_end = nil
94
91
 
95
92
  def write_bool(bool)
96
93
  raise NotImplementedError
@@ -141,37 +138,37 @@ module Thrift
141
138
  raise NotImplementedError
142
139
  end
143
140
 
144
- def read_message_end; nil; end
141
+ def read_message_end = nil
145
142
 
146
143
  def read_struct_begin
147
144
  raise NotImplementedError
148
145
  end
149
146
 
150
- def read_struct_end; nil; end
147
+ def read_struct_end = nil
151
148
 
152
149
  def read_field_begin
153
150
  raise NotImplementedError
154
151
  end
155
152
 
156
- def read_field_end; nil; end
153
+ def read_field_end = nil
157
154
 
158
155
  def read_map_begin
159
156
  raise NotImplementedError
160
157
  end
161
158
 
162
- def read_map_end; nil; end
159
+ def read_map_end = nil
163
160
 
164
161
  def read_list_begin
165
162
  raise NotImplementedError
166
163
  end
167
164
 
168
- def read_list_end; nil; end
165
+ def read_list_end = nil
169
166
 
170
167
  def read_set_begin
171
168
  raise NotImplementedError
172
169
  end
173
170
 
174
- def read_set_end; nil; end
171
+ def read_set_end = nil
175
172
 
176
173
  def read_bool
177
174
  raise NotImplementedError
@@ -230,7 +227,7 @@ module Thrift
230
227
  value = args[2]
231
228
  elsif args.size == 4
232
229
  # handles the deprecated method signature - write_field(name, type, fid, value)
233
- field_info = {:name => args[0], :type => args[1]}
230
+ field_info = { name: args[0], type: args[1] }
234
231
  fid = args[2]
235
232
  value = args[3]
236
233
  else
@@ -253,9 +250,7 @@ module Thrift
253
250
  def write_type(field_info, value)
254
251
  # if field_info is a Fixnum, assume it is a Thrift::Types constant
255
252
  # convert it into a field_info Hash for backwards compatibility
256
- if field_info.is_a? Fixnum
257
- field_info = {:type => field_info}
258
- end
253
+ field_info = { type: field_info } if field_info.is_a? Integer
259
254
 
260
255
  case field_info[:type]
261
256
  when Types::BOOL
@@ -291,11 +286,9 @@ module Thrift
291
286
  #
292
287
  # Returns the value read; object type varies based on field_info[:type].
293
288
  def read_type(field_info)
294
- # if field_info is a Fixnum, assume it is a Thrift::Types constant
289
+ # if field_info is an Integer, assume it is a Thrift::Types constant
295
290
  # convert it into a field_info Hash for backwards compatibility
296
- if field_info.is_a? Fixnum
297
- field_info = {:type => field_info}
298
- end
291
+ field_info = { type: field_info } if field_info.is_a? Integer
299
292
 
300
293
  case field_info[:type]
301
294
  when Types::BOOL
@@ -323,8 +316,6 @@ module Thrift
323
316
 
324
317
  def skip(type)
325
318
  case type
326
- when Types::STOP
327
- nil
328
319
  when Types::BOOL
329
320
  read_bool
330
321
  when Types::BYTE
@@ -342,8 +333,9 @@ module Thrift
342
333
  when Types::STRUCT
343
334
  read_struct_begin
344
335
  while true
345
- name, type, id = read_field_begin
336
+ _, type, = read_field_begin
346
337
  break if type == Types::STOP
338
+
347
339
  skip(type)
348
340
  read_field_end
349
341
  end
@@ -367,13 +359,23 @@ module Thrift
367
359
  skip(etype)
368
360
  end
369
361
  read_list_end
362
+ else
363
+ raise ProtocolException.new(ProtocolException::INVALID_DATA, 'Invalid data')
370
364
  end
371
365
  end
366
+
367
+ def to_s
368
+ "#{trans}"
369
+ end
372
370
  end
373
371
 
374
372
  class BaseProtocolFactory
375
373
  def get_protocol(trans)
376
374
  raise NotImplementedError
377
375
  end
376
+
377
+ def to_s
378
+ 'base'
379
+ end
378
380
  end
379
- end
381
+ end