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.
- checksums.yaml +4 -4
- data/benchmark/benchmark_constants.rb +11 -0
- data/benchmark/benchmark_service.rb +152 -0
- data/benchmark/benchmark_types.rb +10 -0
- 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/definition.rb +4 -0
- 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 +137 -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/base/base_service.rb +152 -0
- data/spec/base/base_service_constants.rb +11 -0
- data/spec/base/base_service_types.rb +45 -0
- 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/extended/extended_service.rb +137 -0
- data/spec/extended/extended_service_constants.rb +11 -0
- data/spec/extended/extended_service_types.rb +12 -0
- data/spec/flat_spec.rb +5 -5
- data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +507 -0
- data/spec/gen-rb/flat/referenced_constants.rb +11 -0
- data/spec/gen-rb/flat/referenced_types.rb +17 -0
- data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +11 -0
- data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +47 -0
- 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/namespaced_spec_namespace/namespaced_nonblocking_service.rb +507 -0
- data/spec/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +11 -0
- data/spec/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +47 -0
- data/spec/nonblocking_server_spec.rb +16 -16
- data/spec/nonblocking_service.rb +507 -0
- data/spec/other_namespace/referenced_constants.rb +11 -0
- data/spec/other_namespace/referenced_types.rb +17 -0
- 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 +17 -17
- 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/thrift_spec_constants.rb +11 -0
- data/spec/thrift_spec_types.rb +1173 -0
- 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 +281 -0
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +2033 -0
- data/test/debug_proto/gen-rb/empty_service.rb +52 -0
- data/test/debug_proto/gen-rb/inherited.rb +155 -0
- data/test/debug_proto/gen-rb/reverse_order_service.rb +169 -0
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +150 -0
- data/test/debug_proto/gen-rb/srv.rb +718 -0
- metadata +202 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a0063f65dcbef1241a6a3c5833985d900ec665e136ca644335b9b14b8bdb153
|
|
4
|
+
data.tar.gz: 6c483db58e479281a16c09477699081a21ff3110c698d712ac8156769c795f5e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 95d2907344606615a4947fc6c2e9046d557712f14e52b6e546be9d72ea47c86d1d1e60fcd11ab4a08d9182a22f8ee92ee42606a31d025600d6b8e44af6e65560
|
|
7
|
+
data.tar.gz: eb411a032c23bae788deef5da6e2b88b52675d0f52eed9a0d418ef552655779459f03596b4133d75bc6469de40227ba82aa55ba3e838f294244519b7e63d4e70
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Autogenerated by Thrift Compiler (v0.0.1-upfluence)
|
|
3
|
+
#
|
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
require 'thrift'
|
|
8
|
+
require 'benchmark_types'
|
|
9
|
+
|
|
10
|
+
module ThriftBenchmark
|
|
11
|
+
module BenchmarkService
|
|
12
|
+
SERVICE = 'BenchmarkService'.freeze
|
|
13
|
+
NAMESPACE = ''.freeze
|
|
14
|
+
|
|
15
|
+
LEGACY_ANNOTATIONS = {
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
STRUCTURED_ANNOTATIONS = [
|
|
19
|
+
].freeze
|
|
20
|
+
|
|
21
|
+
# HELPER FUNCTIONS AND STRUCTURES
|
|
22
|
+
|
|
23
|
+
class Fibonacci_args
|
|
24
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
|
25
|
+
|
|
26
|
+
NAME = 'fibonacci_args'.freeze
|
|
27
|
+
NAMESPACE = ''.freeze
|
|
28
|
+
|
|
29
|
+
LEGACY_ANNOTATIONS = {
|
|
30
|
+
}.freeze
|
|
31
|
+
|
|
32
|
+
STRUCTURED_ANNOTATIONS = [
|
|
33
|
+
].freeze
|
|
34
|
+
|
|
35
|
+
THRIFT_FIELD_INDEX_N = 1
|
|
36
|
+
|
|
37
|
+
THRIFT_FIELD_N_LEGACY_ANNOTATIONS = {
|
|
38
|
+
}.freeze
|
|
39
|
+
|
|
40
|
+
THRIFT_FIELD_N_STRUCTURED_ANNOTATIONS = [
|
|
41
|
+
].freeze
|
|
42
|
+
|
|
43
|
+
FIELDS = {
|
|
44
|
+
THRIFT_FIELD_INDEX_N => {type: ::Thrift::Types::BYTE, name: 'n', legacy_annotations: THRIFT_FIELD_N_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_N_STRUCTURED_ANNOTATIONS}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
def struct_fields; FIELDS; end
|
|
48
|
+
|
|
49
|
+
def validate
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
::Thrift::Struct.generate_accessors self
|
|
53
|
+
::Thrift.register_struct_type self
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class Fibonacci_result
|
|
57
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
|
58
|
+
|
|
59
|
+
NAME = 'fibonacci_result'.freeze
|
|
60
|
+
NAMESPACE = ''.freeze
|
|
61
|
+
|
|
62
|
+
LEGACY_ANNOTATIONS = {
|
|
63
|
+
}.freeze
|
|
64
|
+
|
|
65
|
+
STRUCTURED_ANNOTATIONS = [
|
|
66
|
+
].freeze
|
|
67
|
+
|
|
68
|
+
THRIFT_FIELD_INDEX_SUCCESS = 0
|
|
69
|
+
|
|
70
|
+
THRIFT_FIELD_SUCCESS_LEGACY_ANNOTATIONS = {
|
|
71
|
+
}.freeze
|
|
72
|
+
|
|
73
|
+
THRIFT_FIELD_SUCCESS_STRUCTURED_ANNOTATIONS = [
|
|
74
|
+
].freeze
|
|
75
|
+
|
|
76
|
+
FIELDS = {
|
|
77
|
+
THRIFT_FIELD_INDEX_SUCCESS => {type: ::Thrift::Types::I32, name: 'success', legacy_annotations: THRIFT_FIELD_SUCCESS_LEGACY_ANNOTATIONS, structured_annotations: THRIFT_FIELD_SUCCESS_STRUCTURED_ANNOTATIONS}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
def struct_fields; FIELDS; end
|
|
81
|
+
|
|
82
|
+
def validate
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
::Thrift::Struct.generate_accessors self
|
|
86
|
+
::Thrift.register_struct_type self
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
class Client
|
|
90
|
+
def initialize(client)
|
|
91
|
+
@client = ::Thrift.build_client(client)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def self.from_provider(provider)
|
|
95
|
+
Client.new(provider.build(NAMESPACE, SERVICE))
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def fibonacci(n)
|
|
99
|
+
result = @client.call_binary(
|
|
100
|
+
'fibonacci',
|
|
101
|
+
Fibonacci_args.new(n: n),
|
|
102
|
+
Fibonacci_result
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
return result.success unless result.success.nil?
|
|
106
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'fibonacci failed: unknown result')
|
|
107
|
+
result
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
class Processor
|
|
113
|
+
include ::Thrift::Processor
|
|
114
|
+
|
|
115
|
+
def self.from_provider(handler, provider)
|
|
116
|
+
provider.build(NAMESPACE, SERVICE, Processor, handler)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
THRIFT_METHOD_FIBONACCI_LEGACY_ANNOTATIONS = {
|
|
120
|
+
}.freeze
|
|
121
|
+
|
|
122
|
+
THRIFT_METHOD_FIBONACCI_STRUCTURED_ANNOTATIONS = [
|
|
123
|
+
].freeze
|
|
124
|
+
|
|
125
|
+
METHODS = {
|
|
126
|
+
'fibonacci' => { args_klass: Fibonacci_args, result_klass: Fibonacci_result, oneway: false, legacy_annotations: THRIFT_METHOD_FIBONACCI_STRUCTURED_ANNOTATIONS, structured_annotations: THRIFT_METHOD_FIBONACCI_STRUCTURED_ANNOTATIONS},
|
|
127
|
+
}.freeze
|
|
128
|
+
|
|
129
|
+
def execute_fibonacci(args)
|
|
130
|
+
result = Fibonacci_result.new()
|
|
131
|
+
|
|
132
|
+
result.success = @handler.fibonacci(args.n)
|
|
133
|
+
|
|
134
|
+
result
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def process_fibonacci(seqid, iprot, oprot)
|
|
138
|
+
args = read_args(iprot, Fibonacci_args)
|
|
139
|
+
result = @middleware.handle_binary('fibonacci', args) do |args|
|
|
140
|
+
execute_fibonacci(args)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
write_result(result, oprot, 'fibonacci', seqid)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
::Thrift.register_service_type(self)
|
|
149
|
+
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
end
|
data/ext/struct.c
CHANGED
|
@@ -290,7 +290,7 @@ static void write_container(int ttype, VALUE field_info, VALUE value, VALUE prot
|
|
|
290
290
|
|
|
291
291
|
if (TYPE(value) == T_ARRAY) {
|
|
292
292
|
items = value;
|
|
293
|
-
} else {
|
|
293
|
+
} else {
|
|
294
294
|
if (rb_cSet == CLASS_OF(value)) {
|
|
295
295
|
items = rb_funcall(value, entries_method_id, 0);
|
|
296
296
|
} else {
|
|
@@ -670,6 +670,10 @@ static VALUE rb_thrift_union_write(VALUE self, VALUE protocol) {
|
|
|
670
670
|
|
|
671
671
|
VALUE field_info = rb_hash_aref(struct_fields, field_id);
|
|
672
672
|
|
|
673
|
+
if(NIL_P(field_info)) {
|
|
674
|
+
rb_raise(rb_eRuntimeError, "set_field is not valid for this union!");
|
|
675
|
+
}
|
|
676
|
+
|
|
673
677
|
VALUE ttype_value = rb_hash_aref(field_info, type_sym);
|
|
674
678
|
int ttype = FIX2INT(ttype_value);
|
|
675
679
|
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
module Thrift
|
|
2
|
+
class TBaseStream
|
|
3
|
+
def initialize(iprot, oprot, name, seqid)
|
|
4
|
+
@iprot = iprot
|
|
5
|
+
@oprot = oprot
|
|
6
|
+
@name = name
|
|
7
|
+
@seqid = seqid
|
|
8
|
+
@closed = false
|
|
9
|
+
@ready = false
|
|
10
|
+
@mutex = Mutex.new
|
|
11
|
+
@cond = ConditionVariable.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def ready
|
|
15
|
+
@ready = true
|
|
16
|
+
@cond.broadcast
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
protected
|
|
20
|
+
|
|
21
|
+
def wait_ready
|
|
22
|
+
return if @ready || @closed
|
|
23
|
+
|
|
24
|
+
@mutex.synchronize do
|
|
25
|
+
loop do
|
|
26
|
+
return if @ready || @closed
|
|
27
|
+
|
|
28
|
+
@cond.wait(@mutex)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def read_message_begin
|
|
34
|
+
name, mtype, seqid = @iprot.read_message_begin
|
|
35
|
+
|
|
36
|
+
raise ApplicationException.new(
|
|
37
|
+
ApplicationException::BAD_SEQUENCE_ID,
|
|
38
|
+
'out of seq'
|
|
39
|
+
) if seqid != @seqid
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
raise ApplicationException.new(
|
|
43
|
+
ApplicationException::WRONG_METHOD_NAME,
|
|
44
|
+
'wrong method name'
|
|
45
|
+
) if !name.nil? && name != @name
|
|
46
|
+
|
|
47
|
+
mtype
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def read_shell
|
|
51
|
+
mtype = read_message_begin
|
|
52
|
+
@iprot.read_message_end
|
|
53
|
+
|
|
54
|
+
mtype
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def write_unlocked(mtype, msg)
|
|
58
|
+
@oprot.write_message_begin(@name, mtype, @seqid)
|
|
59
|
+
msg.write(@oprot) if msg
|
|
60
|
+
@oprot.write_message_end
|
|
61
|
+
@oprot.trans.flush
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def write(mtype, msg)
|
|
65
|
+
@mutex.synchronize do
|
|
66
|
+
write_unlocked(mtype, msg) unless @closed
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def write_shell_unlocked(mtype)
|
|
71
|
+
write_unlocked(mtype, nil) unless @closed
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def write_shell(mtype)
|
|
75
|
+
write(mtype, nil)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def mark_as_closed
|
|
79
|
+
@mutex.synchronize do
|
|
80
|
+
@closed = true
|
|
81
|
+
@cond.broadcast
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
module Thrift
|
|
2
|
+
class TBidiInboundStream
|
|
3
|
+
def initialize(bidi_stream)
|
|
4
|
+
@bidi_stream = bidi_stream
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def receive
|
|
8
|
+
@bidi_stream.receive
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def close
|
|
12
|
+
@bidi_stream.inbound_close
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class TBidiOutboundStream
|
|
17
|
+
def initialize(bidi_stream)
|
|
18
|
+
@bidi_stream = bidi_stream
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def send(msg)
|
|
22
|
+
@bidi_stream.send(msg)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def close
|
|
26
|
+
@bidi_stream.outbound_close
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class TBidiStream < TBaseStream
|
|
31
|
+
def initialize(iprot, oprot, name, seqid, inbound_klass, outbound_klass, inbound_message_type, outbound_message_type, unlock = nil)
|
|
32
|
+
@inbound_message_type = inbound_message_type
|
|
33
|
+
@outbound_message_type = outbound_message_type
|
|
34
|
+
@inbound_klass = inbound_klass
|
|
35
|
+
@outbound_klass = outbound_klass
|
|
36
|
+
@inbound_closed = false
|
|
37
|
+
@outbound_closed = false
|
|
38
|
+
@message_queue = Queue.new
|
|
39
|
+
@unlock = unlock
|
|
40
|
+
@closing_inbound = false
|
|
41
|
+
@closing_outbound = false
|
|
42
|
+
super(iprot, oprot, name, seqid)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def ready
|
|
46
|
+
Thread.new { background_read }
|
|
47
|
+
super
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def inbound_close
|
|
51
|
+
wait_ready
|
|
52
|
+
|
|
53
|
+
@mutex.synchronize do
|
|
54
|
+
return if @closed || @inbbound_closed
|
|
55
|
+
|
|
56
|
+
@closing_inbound = true
|
|
57
|
+
write_shell_unlocked @inbound_message_type + 1
|
|
58
|
+
|
|
59
|
+
loop do
|
|
60
|
+
return if @closed || @inbound_closed
|
|
61
|
+
|
|
62
|
+
@cond.wait(@mutex)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def outbound_close
|
|
68
|
+
wait_ready
|
|
69
|
+
|
|
70
|
+
@mutex.synchronize do
|
|
71
|
+
return if @closed || @outbound_closed
|
|
72
|
+
|
|
73
|
+
@closing_outbound = true
|
|
74
|
+
write_shell_unlocked @outbound_message_type + 1
|
|
75
|
+
|
|
76
|
+
loop do
|
|
77
|
+
return nil if @closed || @outbound_closed
|
|
78
|
+
|
|
79
|
+
@cond.wait(@mutex)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def receive
|
|
85
|
+
raise EOFError if @closed || @inbound_closed
|
|
86
|
+
|
|
87
|
+
msg = @message_queue.pop
|
|
88
|
+
|
|
89
|
+
raise EOFError unless msg
|
|
90
|
+
|
|
91
|
+
msg.arg
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def send(msg)
|
|
95
|
+
raise EOFError if @closed || @outbound_closed
|
|
96
|
+
|
|
97
|
+
unless @oprot.trans.open?
|
|
98
|
+
mark_as_closed
|
|
99
|
+
raise EOFError
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
wait_ready
|
|
103
|
+
|
|
104
|
+
write @outbound_message_type, @outbound_klass.new(arg: msg)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def close
|
|
108
|
+
mark_as_closed
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
private
|
|
112
|
+
|
|
113
|
+
def read_message
|
|
114
|
+
msg = @inbound_klass.new
|
|
115
|
+
msg.read(@iprot)
|
|
116
|
+
@iprot.read_message_end
|
|
117
|
+
|
|
118
|
+
@message_queue << msg unless @inbound_closed
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def cleanup_inbound
|
|
122
|
+
@mutex.synchronize do
|
|
123
|
+
@inbound_closed = true
|
|
124
|
+
@message_queue.close unless @message_queue.closed?
|
|
125
|
+
@cond.broadcast
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def cleanup_outbound
|
|
130
|
+
@mutex.synchronize do
|
|
131
|
+
@outbound_closed = true
|
|
132
|
+
@cond.broadcast
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def background_read
|
|
137
|
+
loop do
|
|
138
|
+
begin
|
|
139
|
+
mtype = read_message_begin
|
|
140
|
+
|
|
141
|
+
case mtype
|
|
142
|
+
when @inbound_message_type
|
|
143
|
+
read_message
|
|
144
|
+
when @inbound_message_type + 1
|
|
145
|
+
@mutex.synchronize do
|
|
146
|
+
if !@inbound_closed && !@closing_inbound
|
|
147
|
+
write_shell_unlocked @inbound_message_type + 2
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
cleanup_inbound
|
|
152
|
+
when @inbound_message_type + 2
|
|
153
|
+
cleanup_inbound
|
|
154
|
+
when @outbound_message_type + 1
|
|
155
|
+
@mutex.synchronize do
|
|
156
|
+
if !@outbound_closed && !@closing_outbound
|
|
157
|
+
write_shell_unlocked @outbound_message_type + 2
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
cleanup_outbound
|
|
161
|
+
when @outbound_message_type + 2
|
|
162
|
+
cleanup_outbound
|
|
163
|
+
end
|
|
164
|
+
rescue Exception => e
|
|
165
|
+
mark_as_closed
|
|
166
|
+
@message_queue.close unless @message_queue.closed?
|
|
167
|
+
@cond.broadcast
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
if @outbound_closed && @inbound_closed
|
|
171
|
+
@closed = true
|
|
172
|
+
@cond.broadcast
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
if @closed
|
|
176
|
+
@unlock&.call
|
|
177
|
+
@cond.broadcast
|
|
178
|
+
return
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
data/lib/thrift/client.rb
CHANGED
|
@@ -24,27 +24,16 @@ module Thrift
|
|
|
24
24
|
@iprot = iprot
|
|
25
25
|
@oprot = oprot || iprot
|
|
26
26
|
@seqid = 0
|
|
27
|
+
@mutex = Mutex.new
|
|
28
|
+
@cond = ConditionVariable.new
|
|
29
|
+
@ready = true
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
def send_message(name, args_class, args = {})
|
|
30
33
|
@seqid += 1
|
|
31
34
|
@oprot.write_message_begin(name, MessageTypes::CALL, @seqid)
|
|
32
|
-
send_message_args(args_class, args)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def send_oneway_message(name, args_class, args = {})
|
|
36
|
-
@seqid += 1
|
|
37
|
-
@oprot.write_message_begin(name, MessageTypes::ONEWAY, @seqid)
|
|
38
|
-
send_message_args(args_class, args)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def send_message_args(args_class, args)
|
|
42
35
|
data = args_class.new
|
|
43
|
-
|
|
44
|
-
args.each do |k, v|
|
|
45
|
-
data.send("#{k.to_s}=", v)
|
|
46
|
-
end
|
|
47
|
-
|
|
36
|
+
args.each { |k, v| data.send("#{k}=", v) }
|
|
48
37
|
send_message_instance(data)
|
|
49
38
|
end
|
|
50
39
|
|
|
@@ -98,15 +87,93 @@ module Thrift
|
|
|
98
87
|
include Client
|
|
99
88
|
|
|
100
89
|
def call_unary(name, req)
|
|
101
|
-
@
|
|
102
|
-
|
|
90
|
+
@mutex.synchronize do
|
|
91
|
+
@cond.wait(@mutex) until @ready
|
|
92
|
+
|
|
93
|
+
@seqid += 1
|
|
94
|
+
@oprot.write_message_begin(name, Thrift::MessageTypes::ONEWAY, @seqid)
|
|
95
|
+
send_message_instance(req)
|
|
96
|
+
end
|
|
103
97
|
end
|
|
104
98
|
|
|
105
99
|
def call_binary(name, req, resp_klass)
|
|
100
|
+
@mutex.synchronize do
|
|
101
|
+
@cond.wait(@mutex) until @ready
|
|
102
|
+
|
|
103
|
+
rpc_call(name, req, resp_klass)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def stream_client(name, req, resp_klass, sink_klass)
|
|
108
|
+
resp = stream_call(name, req, resp_klass)
|
|
109
|
+
stream = TOutboundStream.new(
|
|
110
|
+
@iprot, @oprot, name, @seqid, sink_klass,
|
|
111
|
+
MessageTypes::CLIENT_STREAM_MESSAGE,
|
|
112
|
+
method(:finish_call)
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
stream.ready
|
|
116
|
+
|
|
117
|
+
[resp, stream]
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def stream_server(name, req, resp_klass, sink_klass)
|
|
121
|
+
resp = stream_call(name, req, resp_klass)
|
|
122
|
+
stream = TInboundStream.new(
|
|
123
|
+
@iprot, @oprot, name, @seqid, sink_klass,
|
|
124
|
+
MessageTypes::SERVER_STREAM_MESSAGE,
|
|
125
|
+
method(:finish_call)
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
stream.ready
|
|
129
|
+
|
|
130
|
+
[resp, stream]
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def stream_bidi(name, req, resp_klass, stream_klass, sink_klass)
|
|
134
|
+
resp = stream_call(name, req, resp_klass)
|
|
135
|
+
stream = TBidiStream.new(
|
|
136
|
+
@iprot, @oprot, name, @seqid,
|
|
137
|
+
stream_klass, sink_klass,
|
|
138
|
+
MessageTypes::SERVER_STREAM_MESSAGE,
|
|
139
|
+
MessageTypes::CLIENT_STREAM_MESSAGE,
|
|
140
|
+
method(:finish_call)
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
stream.ready
|
|
144
|
+
|
|
145
|
+
[
|
|
146
|
+
resp,
|
|
147
|
+
TBidiInboundStream.new(stream),
|
|
148
|
+
TBidiOutboundStream.new(stream)
|
|
149
|
+
]
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
private
|
|
153
|
+
|
|
154
|
+
def stream_call(name, req, resp_klass)
|
|
155
|
+
@mutex.synchronize do
|
|
156
|
+
@cond.wait(@mutex) until @ready
|
|
157
|
+
|
|
158
|
+
@ready = false
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
rpc_call(name, req, resp_klass)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def rpc_call(name, req, resp_klass)
|
|
165
|
+
@seqid += 1
|
|
106
166
|
@oprot.write_message_begin(name, Thrift::MessageTypes::CALL, @seqid)
|
|
107
167
|
send_message_instance(req)
|
|
108
168
|
receive_message(resp_klass)
|
|
109
169
|
end
|
|
170
|
+
|
|
171
|
+
def finish_call
|
|
172
|
+
@mutex.synchronize do
|
|
173
|
+
@ready = true
|
|
174
|
+
@cond.signal
|
|
175
|
+
end
|
|
176
|
+
end
|
|
110
177
|
end
|
|
111
178
|
|
|
112
179
|
class << self
|
data/lib/thrift/definition.rb
CHANGED
|
@@ -15,10 +15,14 @@ module Thrift
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def structured_annotations
|
|
18
|
+
return [] unless @klass.const_defined? :STRUCTURED_ANNOTATIONS
|
|
19
|
+
|
|
18
20
|
@klass::STRUCTURED_ANNOTATIONS
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def legacy_annotations
|
|
24
|
+
return {} unless @klass.const_defined? :LEGACY_ANNOTATIONS
|
|
25
|
+
|
|
22
26
|
@klass::LEGACY_ANNOTATIONS
|
|
23
27
|
end
|
|
24
28
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
module Thrift
|
|
2
|
+
class TInboundStream < 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
|
+
@closing = false
|
|
8
|
+
super(iprot, oprot, name, seqid)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def close
|
|
12
|
+
wait_ready
|
|
13
|
+
|
|
14
|
+
@mutex.synchronize do
|
|
15
|
+
return nil if @closed
|
|
16
|
+
|
|
17
|
+
begin
|
|
18
|
+
@closing = true
|
|
19
|
+
write_shell_unlocked @message_type + 1
|
|
20
|
+
|
|
21
|
+
loop do
|
|
22
|
+
mtype = read_message_begin
|
|
23
|
+
|
|
24
|
+
case mtype
|
|
25
|
+
when @message_type
|
|
26
|
+
@iprot.skip(Types::STRUCT)
|
|
27
|
+
@iprot.read_message_end
|
|
28
|
+
when @message_type + 2
|
|
29
|
+
@iprot.read_message_end
|
|
30
|
+
return
|
|
31
|
+
else
|
|
32
|
+
raise ApplicationException.new(
|
|
33
|
+
ApplicationException::INVALID_MESSAGE_TYPE,
|
|
34
|
+
'invalid message type'
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
ensure
|
|
39
|
+
@unlock&.call
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def receive
|
|
45
|
+
wait_ready
|
|
46
|
+
|
|
47
|
+
@mutex.synchronize do
|
|
48
|
+
case read_message_begin
|
|
49
|
+
when @message_type
|
|
50
|
+
res = @klass.new
|
|
51
|
+
res.read(@iprot)
|
|
52
|
+
@iprot.read_message_end
|
|
53
|
+
|
|
54
|
+
return res.arg
|
|
55
|
+
when @message_type + 1
|
|
56
|
+
@iprot.read_message_end
|
|
57
|
+
write_shell_unlocked @message_type + 2 unless @closing
|
|
58
|
+
@closed = true
|
|
59
|
+
@cond.broadcast
|
|
60
|
+
@unlock&.call
|
|
61
|
+
|
|
62
|
+
raise EOFError
|
|
63
|
+
else
|
|
64
|
+
raise ApplicationException.new(
|
|
65
|
+
ApplicationException::INVALID_MESSAGE_TYPE,
|
|
66
|
+
'invalid message type'
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|