upfluence-thrift 2.6.8 → 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 (167) hide show
  1. checksums.yaml +4 -4
  2. data/benchmark/{gen-rb/benchmark_constants.rb → benchmark_constants.rb} +1 -1
  3. data/benchmark/{gen-rb/benchmark_service.rb → benchmark_service.rb} +2 -2
  4. data/benchmark/{gen-rb/benchmark_types.rb → benchmark_types.rb} +1 -1
  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/inbound_stream.rb +72 -0
  10. data/lib/thrift/middleware.rb +42 -0
  11. data/lib/thrift/outbound_stream.rb +52 -0
  12. data/lib/thrift/processor.rb +287 -47
  13. data/lib/thrift/protocol/base_protocol.rb +35 -33
  14. data/lib/thrift/protocol/binary_protocol.rb +8 -1
  15. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  16. data/lib/thrift/protocol/compact_protocol.rb +8 -0
  17. data/lib/thrift/protocol/json_protocol.rb +21 -4
  18. data/lib/thrift/protocol/multiplexed_protocol.rb +5 -1
  19. data/lib/thrift/server/base_server.rb +8 -2
  20. data/lib/thrift/server/nonblocking_server.rb +5 -4
  21. data/lib/thrift/server/simple_server.rb +5 -1
  22. data/lib/thrift/server/thread_pool_server.rb +5 -1
  23. data/lib/thrift/server/threaded_server.rb +5 -1
  24. data/lib/thrift/transport/base_server_transport.rb +1 -1
  25. data/lib/thrift/transport/base_transport.rb +8 -0
  26. data/lib/thrift/transport/buffered_transport.rb +9 -1
  27. data/lib/thrift/transport/framed_transport.rb +9 -1
  28. data/lib/thrift/transport/http_client_transport.rb +4 -0
  29. data/lib/thrift/transport/io_stream_transport.rb +4 -1
  30. data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
  31. data/lib/thrift/transport/server_socket.rb +5 -0
  32. data/lib/thrift/transport/socket.rb +21 -17
  33. data/lib/thrift/transport/ssl_server_socket.rb +41 -0
  34. data/lib/thrift/transport/ssl_socket.rb +51 -0
  35. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  36. data/lib/thrift/transport/unix_socket.rb +5 -1
  37. data/lib/thrift/types/annotation/deprecation/deprecation_constants.rb +1 -1
  38. data/lib/thrift/types/annotation/deprecation/deprecation_types.rb +2 -2
  39. data/lib/thrift/types/annotation/exception/exception_constants.rb +17 -0
  40. data/lib/thrift/types/annotation/exception/exception_types.rb +44 -0
  41. data/lib/thrift/types/annotation/naming/naming_constants.rb +1 -1
  42. data/lib/thrift/types/annotation/naming/naming_types.rb +2 -2
  43. data/lib/thrift/types/annotation/rpc/rpc_constants.rb +17 -0
  44. data/lib/thrift/types/annotation/rpc/rpc_types.rb +74 -0
  45. data/lib/thrift/types/annotation_definition/annotation_definition_constants.rb +15 -0
  46. data/lib/thrift/types/annotation_definition/annotation_definition_types.rb +116 -0
  47. data/lib/thrift/types/constant_definition/constant_definition_constants.rb +15 -0
  48. data/lib/thrift/types/constant_definition/constant_definition_types.rb +292 -0
  49. data/lib/thrift/types/core/core_constants.rb +15 -0
  50. data/lib/thrift/types/core/core_types.rb +58 -0
  51. data/lib/thrift/types/enum_definition/enum_definition_constants.rb +15 -0
  52. data/lib/thrift/types/enum_definition/enum_definition_types.rb +106 -0
  53. data/lib/thrift/types/known/any/any_constants.rb +1 -1
  54. data/lib/thrift/types/known/any/any_types.rb +2 -2
  55. data/lib/thrift/types/known/duration/duration_constants.rb +1 -1
  56. data/lib/thrift/types/known/duration/duration_types.rb +2 -2
  57. data/lib/thrift/types/known/timestamp/timestamp_constants.rb +1 -1
  58. data/lib/thrift/types/known/timestamp/timestamp_types.rb +2 -2
  59. data/lib/thrift/types/plugin/plugin.rb +139 -0
  60. data/lib/thrift/types/plugin/plugin_constants.rb +15 -0
  61. data/lib/thrift/types/plugin/plugin_types.rb +106 -0
  62. data/lib/thrift/types/program_definition/program_definition_constants.rb +15 -0
  63. data/lib/thrift/types/program_definition/program_definition_types.rb +137 -0
  64. data/lib/thrift/types/service_definition/service_definition_constants.rb +15 -0
  65. data/lib/thrift/types/service_definition/service_definition_types.rb +160 -0
  66. data/lib/thrift/types/struct_definition/struct_definition_constants.rb +15 -0
  67. data/lib/thrift/types/struct_definition/struct_definition_types.rb +157 -0
  68. data/lib/thrift/types/type_definition/type_definition_constants.rb +15 -0
  69. data/lib/thrift/types/type_definition/type_definition_types.rb +242 -0
  70. data/lib/thrift/types/value/value_constants.rb +1 -1
  71. data/lib/thrift/types/value/value_types.rb +50 -51
  72. data/lib/thrift/types.rb +11 -3
  73. data/lib/thrift/union.rb +3 -6
  74. data/lib/thrift.rb +6 -0
  75. data/lib/types/annotation/deprecation/deprecation_constants.rb +16 -0
  76. data/lib/types/annotation/deprecation/deprecation_types.rb +42 -0
  77. data/lib/types/annotation/naming/naming_constants.rb +16 -0
  78. data/lib/types/annotation/naming/naming_types.rb +57 -0
  79. data/lib/types/annotation_definition/annotation_definition_constants.rb +14 -0
  80. data/lib/types/annotation_definition/annotation_definition_types.rb +114 -0
  81. data/lib/types/constant_definition/constant_definition_constants.rb +14 -0
  82. data/lib/types/constant_definition/constant_definition_types.rb +290 -0
  83. data/lib/types/core/core_constants.rb +14 -0
  84. data/lib/types/core/core_types.rb +56 -0
  85. data/lib/types/enum_definition/enum_definition_constants.rb +14 -0
  86. data/lib/types/enum_definition/enum_definition_types.rb +104 -0
  87. data/lib/types/known/any/any_constants.rb +16 -0
  88. data/lib/types/known/any/any_types.rb +59 -0
  89. data/lib/types/known/duration/duration_constants.rb +16 -0
  90. data/lib/types/known/duration/duration_types.rb +59 -0
  91. data/lib/types/known/timestamp/timestamp_constants.rb +16 -0
  92. data/lib/types/known/timestamp/timestamp_types.rb +59 -0
  93. data/lib/types/plugin/plugin.rb +137 -0
  94. data/lib/types/plugin/plugin_constants.rb +14 -0
  95. data/lib/types/plugin/plugin_types.rb +104 -0
  96. data/lib/types/program_definition/program_definition_constants.rb +14 -0
  97. data/lib/types/program_definition/program_definition_types.rb +135 -0
  98. data/lib/types/service_definition/service_definition_constants.rb +14 -0
  99. data/lib/types/service_definition/service_definition_types.rb +158 -0
  100. data/lib/types/struct_definition/struct_definition_constants.rb +14 -0
  101. data/lib/types/struct_definition/struct_definition_types.rb +155 -0
  102. data/lib/types/type_definition/type_definition_constants.rb +14 -0
  103. data/lib/types/type_definition/type_definition_types.rb +240 -0
  104. data/lib/types/value/value_constants.rb +14 -0
  105. data/lib/types/value/value_types.rb +330 -0
  106. data/spec/{gen-rb/base → base}/base_service.rb +2 -2
  107. data/spec/{gen-rb/base → base}/base_service_constants.rb +1 -1
  108. data/spec/{gen-rb/base → base}/base_service_types.rb +1 -1
  109. data/spec/base_protocol_spec.rb +79 -71
  110. data/spec/base_transport_spec.rb +155 -117
  111. data/spec/binary_protocol_accelerated_spec.rb +6 -2
  112. data/spec/binary_protocol_spec.rb +16 -8
  113. data/spec/binary_protocol_spec_shared.rb +77 -77
  114. data/spec/bytes_spec.rb +38 -38
  115. data/spec/client_spec.rb +48 -50
  116. data/spec/compact_protocol_spec.rb +59 -46
  117. data/spec/exception_spec.rb +54 -54
  118. data/spec/{gen-rb/extended → extended}/extended_service.rb +2 -2
  119. data/spec/{gen-rb/extended → extended}/extended_service_constants.rb +1 -1
  120. data/spec/{gen-rb/extended → extended}/extended_service_types.rb +1 -1
  121. data/spec/flat_spec.rb +5 -5
  122. data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +4 -4
  123. data/spec/gen-rb/flat/referenced_constants.rb +1 -1
  124. data/spec/gen-rb/flat/referenced_types.rb +1 -1
  125. data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +1 -1
  126. data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +1 -1
  127. data/spec/http_client_spec.rb +96 -43
  128. data/spec/json_protocol_spec.rb +170 -131
  129. data/spec/namespaced_spec.rb +24 -27
  130. data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/namespaced_nonblocking_service.rb +4 -4
  131. data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/thrift_namespaced_spec_constants.rb +1 -1
  132. data/spec/{gen-rb/namespaced_spec_namespace → namespaced_spec_namespace}/thrift_namespaced_spec_types.rb +1 -1
  133. data/spec/nonblocking_server_spec.rb +16 -16
  134. data/spec/{gen-rb/nonblocking_service.rb → nonblocking_service.rb} +4 -4
  135. data/spec/{gen-rb/other_namespace → other_namespace}/referenced_constants.rb +1 -1
  136. data/spec/{gen-rb/other_namespace → other_namespace}/referenced_types.rb +1 -1
  137. data/spec/processor_spec.rb +42 -31
  138. data/spec/rack_application_spec.rb +22 -26
  139. data/spec/serializer_spec.rb +20 -20
  140. data/spec/server_socket_spec.rb +27 -22
  141. data/spec/server_spec.rb +91 -51
  142. data/spec/socket_spec.rb +23 -16
  143. data/spec/socket_spec_shared.rb +31 -31
  144. data/spec/spec_helper.rb +1 -1
  145. data/spec/ssl_server_socket_spec.rb +34 -0
  146. data/spec/ssl_socket_spec.rb +78 -0
  147. data/spec/streaming_spec.rb +442 -0
  148. data/spec/struct_nested_containers_spec.rb +24 -24
  149. data/spec/struct_spec.rb +120 -120
  150. data/spec/thin_http_server_spec.rb +71 -28
  151. data/spec/{gen-rb/thrift_spec_constants.rb → thrift_spec_constants.rb} +1 -1
  152. data/spec/{gen-rb/thrift_spec_types.rb → thrift_spec_types.rb} +16 -16
  153. data/spec/types/known/any_spec.rb +2 -2
  154. data/spec/types/known/duration_spec.rb +1 -1
  155. data/spec/types/known/timestamp_spec.rb +1 -1
  156. data/spec/types/value_spec.rb +2 -1
  157. data/spec/types_spec.rb +56 -53
  158. data/spec/union_spec.rb +51 -40
  159. data/spec/unix_socket_spec.rb +43 -34
  160. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +267 -260
  161. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +1481 -1416
  162. data/test/debug_proto/gen-rb/empty_service.rb +31 -27
  163. data/test/debug_proto/gen-rb/inherited.rb +102 -98
  164. data/test/debug_proto/gen-rb/reverse_order_service.rb +112 -108
  165. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +99 -95
  166. data/test/debug_proto/gen-rb/srv.rb +525 -406
  167. metadata +178 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 910b976b447406af13cf97d33ef26b0aa3d28cbbc90b6b8df8e5dfbdb7529026
4
- data.tar.gz: a38f2536a472b778aef2083161e93bc973767c2a76ecbe139ecf63eda3d60565
3
+ metadata.gz: 9a0063f65dcbef1241a6a3c5833985d900ec665e136ca644335b9b14b8bdb153
4
+ data.tar.gz: 6c483db58e479281a16c09477699081a21ff3110c698d712ac8156769c795f5e
5
5
  SHA512:
6
- metadata.gz: f70ad188a73e4113379a1f862ff7495b22bd1dd3a970e69326cc21d7cfb069834f7f63ce2b689d9bdf71a4b7033be54de90c8f78bf61eac3ed72519e9f675275
7
- data.tar.gz: 5c41d9170f392877200e283da4a61b332db3c2669617f8ba3dd09fad50a914e4b0175be8271c5998047abc154f4f49d9035aa5f6d618b1768875c0e77733acf1
6
+ metadata.gz: 95d2907344606615a4947fc6c2e9046d557712f14e52b6e546be9d72ea47c86d1d1e60fcd11ab4a08d9182a22f8ee92ee42606a31d025600d6b8e44af6e65560
7
+ data.tar.gz: eb411a032c23bae788deef5da6e2b88b52675d0f52eed9a0d418ef552655779459f03596b4133d75bc6469de40227ba82aa55ba3e838f294244519b7e63d4e70
@@ -1,5 +1,5 @@
1
1
  #
2
- # Autogenerated by Thrift Compiler ()
2
+ # Autogenerated by Thrift Compiler (v0.0.1-upfluence)
3
3
  #
4
4
  # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
5
  #
@@ -1,5 +1,5 @@
1
1
  #
2
- # Autogenerated by Thrift Compiler ()
2
+ # Autogenerated by Thrift Compiler (v0.0.1-upfluence)
3
3
  #
4
4
  # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
5
  #
@@ -123,7 +123,7 @@ module ThriftBenchmark
123
123
  ].freeze
124
124
 
125
125
  METHODS = {
126
- 'fibonacci' => { args_klass: Fibonacci_args, oneway: false, legacy_annotations: THRIFT_METHOD_FIBONACCI_STRUCTURED_ANNOTATIONS, structured_annotations: THRIFT_METHOD_FIBONACCI_STRUCTURED_ANNOTATIONS},
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
127
  }.freeze
128
128
 
129
129
  def execute_fibonacci(args)
@@ -1,5 +1,5 @@
1
1
  #
2
- # Autogenerated by Thrift Compiler ()
2
+ # Autogenerated by Thrift Compiler (v0.0.1-upfluence)
3
3
  #
4
4
  # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
5
  #
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
- @oprot.write_message_begin(name, Thrift::MessageTypes::ONEWAY, @seqid)
102
- send_message_instance(req)
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
@@ -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
@@ -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