upfluence-thrift 2.6.8 → 2.7.5
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 +4 -4
- data/benchmark/{gen-rb/benchmark_constants.rb → benchmark_constants.rb} +1 -1
- data/benchmark/{gen-rb/benchmark_service.rb → benchmark_service.rb} +2 -2
- data/benchmark/{gen-rb/benchmark_types.rb → benchmark_types.rb} +1 -1
- data/ext/struct.c +5 -1
- data/lib/thrift/base_stream.rb +85 -0
- data/lib/thrift/bidi_stream.rb +183 -0
- data/lib/thrift/client.rb +84 -17
- data/lib/thrift/exceptions.rb +4 -1
- data/lib/thrift/inbound_stream.rb +72 -0
- data/lib/thrift/middleware.rb +42 -0
- data/lib/thrift/outbound_stream.rb +52 -0
- data/lib/thrift/processor.rb +287 -47
- data/lib/thrift/protocol/base_protocol.rb +35 -33
- data/lib/thrift/protocol/binary_protocol.rb +8 -1
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
- data/lib/thrift/protocol/compact_protocol.rb +8 -0
- data/lib/thrift/protocol/json_protocol.rb +21 -4
- data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
- data/lib/thrift/server/base_server.rb +8 -2
- data/lib/thrift/server/nonblocking_server.rb +5 -4
- data/lib/thrift/server/simple_server.rb +5 -1
- data/lib/thrift/server/thread_pool_server.rb +5 -1
- data/lib/thrift/server/threaded_server.rb +5 -1
- data/lib/thrift/transport/base_server_transport.rb +1 -1
- data/lib/thrift/transport/base_transport.rb +8 -0
- data/lib/thrift/transport/buffered_transport.rb +9 -1
- data/lib/thrift/transport/framed_transport.rb +9 -1
- data/lib/thrift/transport/http_client_transport.rb +4 -0
- data/lib/thrift/transport/io_stream_transport.rb +4 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
- data/lib/thrift/transport/server_socket.rb +5 -0
- data/lib/thrift/transport/socket.rb +21 -17
- data/lib/thrift/transport/ssl_server_socket.rb +41 -0
- data/lib/thrift/transport/ssl_socket.rb +51 -0
- data/lib/thrift/transport/unix_server_socket.rb +5 -1
- data/lib/thrift/transport/unix_socket.rb +5 -1
- data/lib/thrift/types/annotation/deprecation/deprecation_constants.rb +1 -1
- data/lib/thrift/types/annotation/deprecation/deprecation_types.rb +2 -2
- data/lib/thrift/types/annotation/exception/exception_constants.rb +17 -0
- data/lib/thrift/types/annotation/exception/exception_types.rb +44 -0
- data/lib/thrift/types/annotation/naming/naming_constants.rb +1 -1
- data/lib/thrift/types/annotation/naming/naming_types.rb +2 -2
- data/lib/thrift/types/annotation/rpc/rpc_constants.rb +17 -0
- data/lib/thrift/types/annotation/rpc/rpc_types.rb +74 -0
- data/lib/thrift/types/annotation_definition/annotation_definition_constants.rb +15 -0
- data/lib/thrift/types/annotation_definition/annotation_definition_types.rb +116 -0
- data/lib/thrift/types/constant_definition/constant_definition_constants.rb +15 -0
- data/lib/thrift/types/constant_definition/constant_definition_types.rb +292 -0
- data/lib/thrift/types/core/core_constants.rb +15 -0
- data/lib/thrift/types/core/core_types.rb +58 -0
- data/lib/thrift/types/enum_definition/enum_definition_constants.rb +15 -0
- data/lib/thrift/types/enum_definition/enum_definition_types.rb +106 -0
- data/lib/thrift/types/known/any/any_constants.rb +1 -1
- data/lib/thrift/types/known/any/any_types.rb +2 -2
- data/lib/thrift/types/known/duration/duration_constants.rb +1 -1
- data/lib/thrift/types/known/duration/duration_types.rb +2 -2
- data/lib/thrift/types/known/timestamp/timestamp_constants.rb +1 -1
- data/lib/thrift/types/known/timestamp/timestamp_types.rb +2 -2
- data/lib/thrift/types/plugin/plugin.rb +139 -0
- data/lib/thrift/types/plugin/plugin_constants.rb +15 -0
- data/lib/thrift/types/plugin/plugin_types.rb +106 -0
- data/lib/thrift/types/program_definition/program_definition_constants.rb +15 -0
- data/lib/thrift/types/program_definition/program_definition_types.rb +146 -0
- data/lib/thrift/types/service_definition/service_definition_constants.rb +15 -0
- data/lib/thrift/types/service_definition/service_definition_types.rb +160 -0
- data/lib/thrift/types/struct_definition/struct_definition_constants.rb +15 -0
- data/lib/thrift/types/struct_definition/struct_definition_types.rb +157 -0
- data/lib/thrift/types/type_definition/type_definition_constants.rb +15 -0
- data/lib/thrift/types/type_definition/type_definition_types.rb +242 -0
- data/lib/thrift/types/value/value_constants.rb +1 -1
- data/lib/thrift/types/value/value_types.rb +50 -51
- data/lib/thrift/types.rb +11 -3
- data/lib/thrift/union.rb +3 -6
- data/lib/thrift.rb +6 -0
- data/lib/types/annotation/deprecation/deprecation_constants.rb +16 -0
- data/lib/types/annotation/deprecation/deprecation_types.rb +42 -0
- data/lib/types/annotation/naming/naming_constants.rb +16 -0
- data/lib/types/annotation/naming/naming_types.rb +57 -0
- data/lib/types/annotation_definition/annotation_definition_constants.rb +14 -0
- data/lib/types/annotation_definition/annotation_definition_types.rb +114 -0
- data/lib/types/constant_definition/constant_definition_constants.rb +14 -0
- data/lib/types/constant_definition/constant_definition_types.rb +290 -0
- data/lib/types/core/core_constants.rb +14 -0
- data/lib/types/core/core_types.rb +56 -0
- data/lib/types/enum_definition/enum_definition_constants.rb +14 -0
- data/lib/types/enum_definition/enum_definition_types.rb +104 -0
- data/lib/types/known/any/any_constants.rb +16 -0
- data/lib/types/known/any/any_types.rb +59 -0
- data/lib/types/known/duration/duration_constants.rb +16 -0
- data/lib/types/known/duration/duration_types.rb +59 -0
- data/lib/types/known/timestamp/timestamp_constants.rb +16 -0
- data/lib/types/known/timestamp/timestamp_types.rb +59 -0
- data/lib/types/plugin/plugin.rb +137 -0
- data/lib/types/plugin/plugin_constants.rb +14 -0
- data/lib/types/plugin/plugin_types.rb +104 -0
- data/lib/types/program_definition/program_definition_constants.rb +14 -0
- data/lib/types/program_definition/program_definition_types.rb +135 -0
- data/lib/types/service_definition/service_definition_constants.rb +14 -0
- data/lib/types/service_definition/service_definition_types.rb +158 -0
- data/lib/types/struct_definition/struct_definition_constants.rb +14 -0
- data/lib/types/struct_definition/struct_definition_types.rb +155 -0
- data/lib/types/type_definition/type_definition_constants.rb +14 -0
- data/lib/types/type_definition/type_definition_types.rb +240 -0
- data/lib/types/value/value_constants.rb +14 -0
- data/lib/types/value/value_types.rb +330 -0
- data/spec/{gen-rb/base → base}/base_service.rb +2 -2
- data/spec/{gen-rb/base → base}/base_service_constants.rb +1 -1
- data/spec/{gen-rb/base → base}/base_service_types.rb +1 -1
- data/spec/base_protocol_spec.rb +79 -71
- data/spec/base_transport_spec.rb +155 -117
- data/spec/binary_protocol_accelerated_spec.rb +6 -2
- data/spec/binary_protocol_spec.rb +16 -8
- data/spec/binary_protocol_spec_shared.rb +77 -77
- data/spec/bytes_spec.rb +38 -38
- data/spec/client_spec.rb +48 -50
- data/spec/compact_protocol_spec.rb +59 -46
- data/spec/exception_spec.rb +54 -54
- data/spec/{gen-rb/extended → extended}/extended_service.rb +2 -2
- data/spec/{gen-rb/extended → extended}/extended_service_constants.rb +1 -1
- data/spec/{gen-rb/extended → extended}/extended_service_types.rb +1 -1
- data/spec/flat_spec.rb +5 -5
- data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +4 -4
- data/spec/gen-rb/flat/referenced_constants.rb +1 -1
- data/spec/gen-rb/flat/referenced_types.rb +1 -1
- data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +1 -1
- data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +1 -1
- data/spec/http_client_spec.rb +96 -43
- data/spec/json_protocol_spec.rb +170 -131
- data/spec/namespaced_spec.rb +24 -27
- data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/namespaced_nonblocking_service.rb +4 -4
- data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/thrift_namespaced_spec_constants.rb +1 -1
- data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/thrift_namespaced_spec_types.rb +1 -1
- data/spec/nonblocking_server_spec.rb +16 -16
- data/spec/{gen-rb/nonblocking_service.rb → nonblocking_service.rb} +4 -4
- data/spec/{gen-rb/other_namespace → other_namespace}/referenced_constants.rb +1 -1
- data/spec/{gen-rb/other_namespace → other_namespace}/referenced_types.rb +1 -1
- data/spec/processor_spec.rb +42 -31
- data/spec/rack_application_spec.rb +22 -26
- data/spec/serializer_spec.rb +20 -20
- data/spec/server_socket_spec.rb +27 -22
- data/spec/server_spec.rb +91 -51
- data/spec/socket_spec.rb +23 -16
- data/spec/socket_spec_shared.rb +31 -31
- data/spec/spec_helper.rb +1 -1
- data/spec/ssl_server_socket_spec.rb +34 -0
- data/spec/ssl_socket_spec.rb +78 -0
- data/spec/streaming_spec.rb +442 -0
- data/spec/struct_nested_containers_spec.rb +24 -24
- data/spec/struct_spec.rb +120 -120
- data/spec/thin_http_server_spec.rb +71 -28
- data/spec/{gen-rb/thrift_spec_constants.rb → thrift_spec_constants.rb} +1 -1
- data/spec/{gen-rb/thrift_spec_types.rb → thrift_spec_types.rb} +16 -16
- data/spec/types/known/any_spec.rb +2 -2
- data/spec/types/known/duration_spec.rb +1 -1
- data/spec/types/known/timestamp_spec.rb +1 -1
- data/spec/types/value_spec.rb +2 -1
- data/spec/types_spec.rb +56 -53
- data/spec/union_spec.rb +51 -40
- data/spec/unix_socket_spec.rb +43 -34
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +267 -260
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +1481 -1416
- data/test/debug_proto/gen-rb/empty_service.rb +31 -27
- data/test/debug_proto/gen-rb/inherited.rb +102 -98
- data/test/debug_proto/gen-rb/reverse_order_service.rb +112 -108
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +99 -95
- data/test/debug_proto/gen-rb/srv.rb +525 -406
- metadata +178 -41
data/lib/thrift/processor.rb
CHANGED
|
@@ -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
|
-
@
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
136
|
+
mth = "process_#{name}"
|
|
137
|
+
if respond_to?(mth)
|
|
138
|
+
send(mth, seqid, iprot, oprot)
|
|
139
|
+
return true
|
|
140
|
+
end
|
|
120
141
|
|
|
121
|
-
|
|
142
|
+
(
|
|
143
|
+
@processors[name] || UnkwonFunctionProcessor.new(name)
|
|
144
|
+
).process(seqid, iprot, oprot)
|
|
145
|
+
end
|
|
122
146
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
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::
|
|
138
|
-
|
|
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
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
156
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 = {:
|
|
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?
|
|
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
|
|
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?
|
|
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
|
-
|
|
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
|
|
@@ -226,12 +226,19 @@ module Thrift
|
|
|
226
226
|
size = read_i32
|
|
227
227
|
trans.read_all(size)
|
|
228
228
|
end
|
|
229
|
-
|
|
229
|
+
|
|
230
|
+
def to_s
|
|
231
|
+
"binary(#{super.to_s})"
|
|
232
|
+
end
|
|
230
233
|
end
|
|
231
234
|
|
|
232
235
|
class BinaryProtocolFactory < BaseProtocolFactory
|
|
233
236
|
def get_protocol(trans)
|
|
234
237
|
return Thrift::BinaryProtocol.new(trans)
|
|
235
238
|
end
|
|
239
|
+
|
|
240
|
+
def to_s
|
|
241
|
+
"binary"
|
|
242
|
+
end
|
|
236
243
|
end
|
|
237
244
|
end
|
|
@@ -345,6 +345,10 @@ module Thrift
|
|
|
345
345
|
size = read_varint32()
|
|
346
346
|
trans.read_all(size)
|
|
347
347
|
end
|
|
348
|
+
|
|
349
|
+
def to_s
|
|
350
|
+
"compact(#{super.to_s})"
|
|
351
|
+
end
|
|
348
352
|
|
|
349
353
|
private
|
|
350
354
|
|
|
@@ -431,5 +435,9 @@ module Thrift
|
|
|
431
435
|
def get_protocol(trans)
|
|
432
436
|
CompactProtocol.new(trans)
|
|
433
437
|
end
|
|
438
|
+
|
|
439
|
+
def to_s
|
|
440
|
+
"compact"
|
|
441
|
+
end
|
|
434
442
|
end
|
|
435
443
|
end
|