protobuf 1.4.2 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Rakefile +7 -7
- data/bin/rpc_server +2 -188
- data/bin/rprotoc +44 -38
- data/examples/addressbook.pb.rb +2 -2
- data/ext/Makefile +11 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +142 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +318 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +99 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +103 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +85 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +167 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +98 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +159 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +170 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +102 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +103 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +104 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +2721 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +303 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +84 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +77 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +108 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +101 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +72 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +213 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +109 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +134 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +113 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +120 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +113 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +434 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +73 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +790 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +156 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +108 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +93 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +1367 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +5223 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +366 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +136 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +904 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +424 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +82 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +1102 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +207 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h +54 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +136 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +313 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +238 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +357 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +340 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/message.h +692 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +239 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +80 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +1295 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/service.h +291 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +1211 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +220 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +119 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +123 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +457 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +170 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +174 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +101 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +83 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +98 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +285 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +11915 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +2895 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +211 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +56 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +188 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +151 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +4752 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +150 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +816 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +197 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +403 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +268 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +304 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +620 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +774 -0
- data/ext/ruby_generator/RubyGenerator.cpp +435 -0
- data/ext/ruby_generator/RubyGenerator.h +180 -0
- data/ext/ruby_generator/extconf.rb +24 -0
- data/lib/protobuf.rb +55 -33
- data/lib/protobuf/cli.rb +176 -0
- data/lib/protobuf/common/logger.rb +11 -11
- data/lib/protobuf/{message/enum.rb → enum.rb} +0 -10
- data/lib/protobuf/evented.rb +22 -0
- data/lib/protobuf/field.rb +57 -0
- data/lib/protobuf/field/base_field.rb +210 -0
- data/lib/protobuf/field/bool_field.rb +24 -0
- data/lib/protobuf/field/bytes_field.rb +38 -0
- data/lib/protobuf/field/double_field.rb +19 -0
- data/lib/protobuf/field/enum_field.rb +58 -0
- data/lib/protobuf/field/extension_fields.rb +24 -0
- data/lib/protobuf/field/field_array.rb +55 -0
- data/lib/protobuf/field/fixed32_field.rb +19 -0
- data/lib/protobuf/field/fixed64_field.rb +22 -0
- data/lib/protobuf/field/float_field.rb +29 -0
- data/lib/protobuf/field/int32_field.rb +10 -0
- data/lib/protobuf/field/int64_field.rb +10 -0
- data/lib/protobuf/field/integer_field.rb +19 -0
- data/lib/protobuf/field/message_field.rb +51 -0
- data/lib/protobuf/field/sfixed32_field.rb +21 -0
- data/lib/protobuf/field/sfixed64_field.rb +24 -0
- data/lib/protobuf/field/signed_integer_field.rb +23 -0
- data/lib/protobuf/field/sint32_field.rb +10 -0
- data/lib/protobuf/field/sint64_field.rb +10 -0
- data/lib/protobuf/field/string_field.rb +14 -0
- data/lib/protobuf/field/uint32_field.rb +10 -0
- data/lib/protobuf/field/uint64_field.rb +10 -0
- data/lib/protobuf/field/varint_field.rb +63 -0
- data/lib/protobuf/message.rb +376 -0
- data/lib/protobuf/message/message.rb +1 -475
- data/lib/protobuf/rpc/buffer.rb +1 -1
- data/lib/protobuf/rpc/client.rb +26 -26
- data/lib/protobuf/rpc/connector.rb +15 -14
- data/lib/protobuf/rpc/connectors/eventmachine.rb +13 -13
- data/lib/protobuf/rpc/rpc.pb.rb +39 -28
- data/lib/protobuf/rpc/server.rb +7 -28
- data/lib/protobuf/rpc/servers/evented_runner.rb +15 -15
- data/lib/protobuf/rpc/servers/socket/server.rb +2 -1
- data/lib/protobuf/rpc/servers/socket_runner.rb +5 -6
- data/lib/protobuf/rpc/servers/zmq_runner.rb +4 -5
- data/lib/protobuf/socket.rb +22 -0
- data/lib/protobuf/version.rb +2 -1
- data/lib/protobuf/zmq.rb +21 -0
- data/proto/rpc.pb.rb +48 -0
- data/protobuf.gemspec +14 -6
- data/spec/benchmark/tasks.rb +42 -23
- data/spec/functional/evented_server_spec.rb +2 -0
- data/spec/functional/socket_server_spec.rb +22 -26
- data/spec/functional/zmq_server_spec.rb +22 -26
- data/spec/lib/protobuf/cli_spec.rb +182 -0
- data/spec/{unit → lib/protobuf}/common/logger_spec.rb +0 -0
- data/spec/{unit → lib/protobuf/message}/enum_spec.rb +0 -0
- data/spec/{unit → lib/protobuf/message}/message_spec.rb +0 -0
- data/spec/{unit → lib/protobuf}/rpc/client_spec.rb +6 -4
- data/spec/lib/protobuf/rpc/connector_spec.rb +41 -0
- data/spec/{unit → lib/protobuf}/rpc/connectors/base_spec.rb +18 -18
- data/spec/{unit → lib/protobuf}/rpc/connectors/common_spec.rb +20 -20
- data/spec/{unit → lib/protobuf}/rpc/connectors/socket_spec.rb +9 -8
- data/spec/{unit → lib/protobuf}/rpc/connectors/zmq_spec.rb +1 -1
- data/spec/{unit → lib/protobuf}/rpc/servers/evented_server_spec.rb +4 -4
- data/spec/{unit → lib/protobuf}/rpc/servers/socket_server_spec.rb +11 -23
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/broker_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/server_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/util_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/servers/zmq/worker_spec.rb +5 -0
- data/spec/{unit → lib/protobuf}/rpc/service_spec.rb +0 -0
- data/spec/proto/test.pb.rb +48 -25
- data/spec/spec_helper.rb +9 -15
- data/spec/support/all.rb +7 -0
- data/spec/{helper → support}/server.rb +5 -7
- data/spec/{helper → support}/silent_constants.rb +4 -0
- data/spec/support/test_app_file.rb +2 -0
- data/spec/{helper → support}/tolerance_matcher.rb +0 -0
- data/test/proto/types.pb.rb +1 -1
- data/test/test_addressbook.rb +1 -1
- data/test/test_enum_value.rb +1 -1
- data/test/test_standard_message.rb +1 -1
- metadata +243 -107
- data/lib/protobuf/common/util.rb +0 -59
- data/lib/protobuf/compiler/compiler.rb +0 -52
- data/lib/protobuf/compiler/nodes.rb +0 -323
- data/lib/protobuf/compiler/proto.y +0 -216
- data/lib/protobuf/compiler/proto2.ebnf +0 -79
- data/lib/protobuf/compiler/proto_parser.rb +0 -1425
- data/lib/protobuf/compiler/template/rpc_service_implementation.erb +0 -42
- data/lib/protobuf/compiler/visitors.rb +0 -282
- data/lib/protobuf/descriptor/descriptor.proto +0 -286
- data/lib/protobuf/descriptor/descriptor.rb +0 -55
- data/lib/protobuf/descriptor/descriptor_builder.rb +0 -143
- data/lib/protobuf/descriptor/descriptor_proto.rb +0 -138
- data/lib/protobuf/descriptor/enum_descriptor.rb +0 -33
- data/lib/protobuf/descriptor/field_descriptor.rb +0 -49
- data/lib/protobuf/descriptor/file_descriptor.rb +0 -37
- data/lib/protobuf/message/field.rb +0 -684
- data/lib/protobuf/message/protoable.rb +0 -38
- data/spec/helper/all.rb +0 -7
- data/spec/unit/common/util_spec.rb +0 -17
- data/spec/unit/rpc/connector_spec.rb +0 -31
- data/spec/unit/rpc/connectors/eventmachine_client_spec.rb +0 -32
- data/spec/unit/rpc/connectors/eventmachine_spec.rb +0 -0
- data/test/check_unbuild.rb +0 -30
- data/test/test_compiler.rb +0 -325
- data/test/test_descriptor.rb +0 -122
data/lib/protobuf/rpc/buffer.rb
CHANGED
data/lib/protobuf/rpc/client.rb
CHANGED
@@ -9,14 +9,14 @@ module Protobuf
|
|
9
9
|
class Client
|
10
10
|
extend Forwardable
|
11
11
|
include Protobuf::Logger::LogMethods
|
12
|
-
|
12
|
+
|
13
13
|
delegate [:options, :complete_cb, :success_cb, :failure_cb, :async?] => :@connector
|
14
14
|
attr_reader :connector
|
15
|
-
|
15
|
+
|
16
16
|
# Create a new client with default options (defined in ClientConnection)
|
17
17
|
# See Service#client for a more convenient way to create a client, as well
|
18
18
|
# as Client#method_missing defined below.
|
19
|
-
#
|
19
|
+
#
|
20
20
|
# request = WidgetFindRequest.new
|
21
21
|
# client = Client.new({
|
22
22
|
# :service => WidgetService,
|
@@ -35,33 +35,33 @@ module Protobuf
|
|
35
35
|
def log_signature
|
36
36
|
@log_signature ||= "client-#{self.class}"
|
37
37
|
end
|
38
|
-
|
39
|
-
# Set a complete callback on the client to return the object (self).
|
38
|
+
|
39
|
+
# Set a complete callback on the client to return the object (self).
|
40
40
|
# Callback is called regardless of :async setting.
|
41
|
-
#
|
41
|
+
#
|
42
42
|
# client = Client.new(:service => WidgetService)
|
43
43
|
# client.on_complete {|obj| ... }
|
44
|
-
#
|
44
|
+
#
|
45
45
|
def on_complete(&complete_cb)
|
46
|
-
@connector.complete_cb = complete_cb
|
46
|
+
@connector.complete_cb = complete_cb
|
47
47
|
end
|
48
48
|
|
49
49
|
def on_complete=(callable)
|
50
50
|
if callable != nil && !callable.respond_to?(:call) && callable.arity != 1
|
51
51
|
raise "callable must take a single argument and respond to :call"
|
52
52
|
end
|
53
|
-
|
54
|
-
@connector.complete_cb = callable
|
53
|
+
|
54
|
+
@connector.complete_cb = callable
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# Set a failure callback on the client to return the
|
58
58
|
# error returned by the service, if any. If this callback
|
59
59
|
# is called, success_cb will NOT be called.
|
60
60
|
# Callback is called regardless of :async setting.
|
61
|
-
#
|
61
|
+
#
|
62
62
|
# client = Client.new(:service => WidgetService)
|
63
63
|
# client.on_failure {|err| ... }
|
64
|
-
#
|
64
|
+
#
|
65
65
|
def on_failure(&failure_cb)
|
66
66
|
@connector.failure_cb = failure_cb
|
67
67
|
end
|
@@ -71,17 +71,17 @@ module Protobuf
|
|
71
71
|
raise "callable must take a single argument and respond to :call"
|
72
72
|
end
|
73
73
|
|
74
|
-
@connector.failure_cb = callable
|
74
|
+
@connector.failure_cb = callable
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
# Set a success callback on the client to return the
|
78
78
|
# successful response from the service when it is returned.
|
79
79
|
# If this callback is called, failure_cb will NOT be called.
|
80
80
|
# Callback is called regardless of :async setting.
|
81
|
-
#
|
81
|
+
#
|
82
82
|
# client = Client.new(:service => WidgetService)
|
83
83
|
# client.on_success {|res| ... }
|
84
|
-
#
|
84
|
+
#
|
85
85
|
def on_success(&success_cb)
|
86
86
|
@connector.success_cb = success_cb
|
87
87
|
end
|
@@ -91,9 +91,9 @@ module Protobuf
|
|
91
91
|
raise "callable must take a single argument and respond to :call"
|
92
92
|
end
|
93
93
|
|
94
|
-
@connector.success_cb = callable
|
94
|
+
@connector.success_cb = callable
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
# Provides a mechanism to call the service method against the client
|
98
98
|
# which will automatically setup the service_class and method_name
|
99
99
|
# in the wrapper protobuf request.
|
@@ -105,7 +105,7 @@ module Protobuf
|
|
105
105
|
# c.on_success {|res| ... }
|
106
106
|
# c.on_failure {|err| ... }
|
107
107
|
# end
|
108
|
-
#
|
108
|
+
#
|
109
109
|
def method_missing(method, *params)
|
110
110
|
service = options[:service]
|
111
111
|
unless service.rpcs[service].keys.include?(method)
|
@@ -121,7 +121,7 @@ module Protobuf
|
|
121
121
|
options[:method] = method.to_s
|
122
122
|
options[:request] = params[0].is_a?(Hash) ? options[:request_type].new(params[0]) : params[0]
|
123
123
|
log_debug { "[#{log_signature}] Request Data: %s" % options[:request].inspect }
|
124
|
-
|
124
|
+
|
125
125
|
# Call client to setup on_success and on_failure event callbacks
|
126
126
|
if block_given?
|
127
127
|
log_debug { "[#{log_signature}] client setup callback given, invoking" }
|
@@ -129,11 +129,11 @@ module Protobuf
|
|
129
129
|
else
|
130
130
|
log_debug { "[#{log_signature}] no block given for callbacks" }
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
send_request
|
134
134
|
end
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
# Send the request to the service through eventmachine.
|
138
138
|
# This method is usually never called directly
|
139
139
|
# but is invoked by method_missing (see docs above).
|
@@ -146,7 +146,7 @@ module Protobuf
|
|
146
146
|
# :response_type => "WidgetList",
|
147
147
|
# :request => request
|
148
148
|
# })
|
149
|
-
#
|
149
|
+
#
|
150
150
|
# client.on_success do |res|
|
151
151
|
# res.widgets.each{|w| puts w.inspect }
|
152
152
|
# end
|
@@ -154,13 +154,13 @@ module Protobuf
|
|
154
154
|
# client.on_failure do |err|
|
155
155
|
# puts err.message
|
156
156
|
# end
|
157
|
-
#
|
157
|
+
#
|
158
158
|
# client.send_request
|
159
159
|
#
|
160
160
|
def send_request
|
161
161
|
@connector.send_request
|
162
162
|
end
|
163
|
-
|
163
|
+
|
164
164
|
end
|
165
165
|
end
|
166
166
|
end
|
@@ -1,22 +1,23 @@
|
|
1
1
|
module Protobuf
|
2
2
|
module Rpc
|
3
3
|
class Connector
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
::Protobuf::Rpc::Connectors::EventMachine
|
4
|
+
|
5
|
+
# Returns a connector class for the pre-defined connector_type.
|
6
|
+
def self.connector_for_client(reload = false)
|
7
|
+
if reload || @_connector.nil?
|
8
|
+
@_connector = case ::Protobuf.connector_type
|
9
|
+
when :evented then
|
10
|
+
::Protobuf::Rpc::Connectors::EventMachine
|
11
|
+
when :zmq then
|
12
|
+
::Protobuf::Rpc::Connectors::Zmq
|
13
|
+
else
|
14
|
+
::Protobuf::Rpc::Connectors::Socket
|
15
|
+
end
|
17
16
|
end
|
17
|
+
|
18
|
+
return @_connector
|
18
19
|
end
|
19
|
-
|
20
|
+
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -7,10 +7,10 @@ module Protobuf
|
|
7
7
|
class EventMachine < Base
|
8
8
|
|
9
9
|
def send_request
|
10
|
-
ensure_em_running do
|
10
|
+
ensure_em_running do
|
11
11
|
f = Fiber.current
|
12
12
|
|
13
|
-
EM.next_tick do
|
13
|
+
::EM.next_tick do
|
14
14
|
log_debug { "[#{log_signature}] Scheduling EventMachine client request to be created on next tick" }
|
15
15
|
cnxn = EMClient.connect(options, &ensure_cb)
|
16
16
|
cnxn.on_success(&success_cb) if success_cb
|
@@ -26,11 +26,11 @@ module Protobuf
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# Returns a callable that ensures any errors will be returned to the client
|
29
|
-
#
|
29
|
+
#
|
30
30
|
# If a failure callback was set, just use that as a direct assignment
|
31
31
|
# otherwise implement one here that simply throws an exception, since we
|
32
32
|
# don't want to swallow the black holes.
|
33
|
-
#
|
33
|
+
#
|
34
34
|
def ensure_cb
|
35
35
|
@ensure_cb ||= (@failure_cb || lambda { |error| raise '%s: %s' % [error.code.name, error.message] } )
|
36
36
|
end
|
@@ -42,42 +42,42 @@ module Protobuf
|
|
42
42
|
private
|
43
43
|
|
44
44
|
def ensure_em_running(&blk)
|
45
|
-
if EM.reactor_running?
|
45
|
+
if ::EM.reactor_running?
|
46
46
|
@using_global_reactor = true
|
47
47
|
yield
|
48
|
-
else
|
48
|
+
else
|
49
49
|
@using_global_reactor = false
|
50
|
-
EM.fiber_run do
|
50
|
+
::EM.fiber_run do
|
51
51
|
blk.call
|
52
|
-
EM.stop
|
52
|
+
::EM.stop
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def resume_fiber(fib)
|
58
|
-
EM::cancel_timer(@timeout_timer)
|
58
|
+
::EM::cancel_timer(@timeout_timer)
|
59
59
|
fib.resume(true)
|
60
|
-
rescue => ex
|
60
|
+
rescue => ex
|
61
61
|
message = 'Synchronous client failed: %s' % ex.message
|
62
62
|
error_stop_reactor(message)
|
63
63
|
end
|
64
64
|
|
65
65
|
def set_timeout_and_validate_fiber
|
66
|
-
@timeout_timer = EM::add_timer(@options[:timeout]) do
|
66
|
+
@timeout_timer = ::EM::add_timer(@options[:timeout]) do
|
67
67
|
message = 'Client timeout of %d seconds expired' % @options[:timeout]
|
68
68
|
error_stop_reactor(message)
|
69
69
|
end
|
70
70
|
|
71
71
|
Fiber.yield
|
72
72
|
rescue FiberError
|
73
|
-
message = "Synchronous calls must be in 'EM.fiber_run' block"
|
73
|
+
message = "Synchronous calls must be in 'EM.fiber_run' block"
|
74
74
|
error_stop_reactor(message)
|
75
75
|
end
|
76
76
|
|
77
77
|
def error_stop_reactor(message)
|
78
78
|
err = Protobuf::Rpc::ClientError.new(Protobuf::Socketrpc::ErrorReason::RPC_ERROR, message)
|
79
79
|
ensure_cb.call(err)
|
80
|
-
EM.stop unless @using_global_reactor
|
80
|
+
::EM.stop unless @using_global_reactor
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
data/lib/protobuf/rpc/rpc.pb.rb
CHANGED
@@ -73,35 +73,46 @@
|
|
73
73
|
# UNKNOWN_HOST = 8; // Could not find supplied host
|
74
74
|
# IO_ERROR = 9; // I/O error while communicating with server
|
75
75
|
# }
|
76
|
-
|
77
|
-
require 'protobuf/message/message'
|
78
|
-
require 'protobuf/message/enum'
|
79
|
-
require 'protobuf/message/extend'
|
76
|
+
require 'protobuf/message'
|
80
77
|
|
81
78
|
module Protobuf
|
82
79
|
module Socketrpc
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
80
|
+
##
|
81
|
+
# Enum Classes
|
82
|
+
#
|
83
|
+
class ErrorReason < ::Protobuf::Enum; end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Message Classes
|
87
|
+
#
|
88
|
+
class Request < ::Protobuf::Message; end
|
89
|
+
class Response < ::Protobuf::Message; end
|
90
|
+
|
91
|
+
##
|
92
|
+
# Enum Values
|
93
|
+
#
|
94
|
+
::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_DATA, 0
|
95
|
+
::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_PROTO, 1
|
96
|
+
::Protobuf::Socketrpc::ErrorReason.define :SERVICE_NOT_FOUND, 2
|
97
|
+
::Protobuf::Socketrpc::ErrorReason.define :METHOD_NOT_FOUND, 3
|
98
|
+
::Protobuf::Socketrpc::ErrorReason.define :RPC_ERROR, 4
|
99
|
+
::Protobuf::Socketrpc::ErrorReason.define :RPC_FAILED, 5
|
100
|
+
::Protobuf::Socketrpc::ErrorReason.define :INVALID_REQUEST_PROTO, 6
|
101
|
+
::Protobuf::Socketrpc::ErrorReason.define :BAD_RESPONSE_PROTO, 7
|
102
|
+
::Protobuf::Socketrpc::ErrorReason.define :UNKNOWN_HOST, 8
|
103
|
+
::Protobuf::Socketrpc::ErrorReason.define :IO_ERROR, 9
|
104
|
+
|
105
|
+
##
|
106
|
+
# Message Fields
|
107
|
+
#
|
108
|
+
::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :service_name, 1)
|
109
|
+
::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :method_name, 2)
|
110
|
+
::Protobuf::Socketrpc::Request.required(::Protobuf::Field::BytesField, :request_proto, 3)
|
111
|
+
|
112
|
+
::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BytesField, :response_proto, 1)
|
113
|
+
::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::StringField, :error, 2)
|
114
|
+
::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BoolField, :callback, 3, :default => false)
|
115
|
+
::Protobuf::Socketrpc::Response.optional(::Protobuf::Socketrpc::ErrorReason, :error_reason, 4)
|
116
|
+
|
106
117
|
end
|
107
|
-
end
|
118
|
+
end
|
data/lib/protobuf/rpc/server.rb
CHANGED
@@ -8,16 +8,6 @@ module Protobuf
|
|
8
8
|
module Rpc
|
9
9
|
module Server
|
10
10
|
|
11
|
-
def _gc_pause_request
|
12
|
-
return @_gc_pause_request unless @_gc_pause_request.nil?
|
13
|
-
@_gc_pause_request ||= (defined?(::Protobuf::Rpc::GC_PAUSE_REQUEST) && ::Protobuf::Rpc::GC_PAUSE_REQUEST)
|
14
|
-
end
|
15
|
-
|
16
|
-
def _gc_pause_serialization
|
17
|
-
return @_gc_pause_serialization unless @_gc_pause_serialization.nil?
|
18
|
-
@_gc_pause_serialization ||= (defined?(::Protobuf::Rpc::GC_PAUSE_SERIALIZATION) && ::Protobuf::Rpc::GC_PAUSE_SERIALIZATION)
|
19
|
-
end
|
20
|
-
|
21
11
|
# Invoke the service method dictated by the proto wrapper request object
|
22
12
|
def handle_client
|
23
13
|
# Parse the protobuf request from the socket
|
@@ -30,7 +20,7 @@ module Protobuf
|
|
30
20
|
|
31
21
|
# Call the service method
|
32
22
|
log_debug { "[#{log_signature}] Dispatching client request to service" }
|
33
|
-
GC.disable if
|
23
|
+
::GC.disable if ::Protobuf.gc_pause_server_request
|
34
24
|
invoke_rpc_method
|
35
25
|
rescue => error
|
36
26
|
# Ensure we're handling any errors that try to slip out the back door
|
@@ -108,11 +98,10 @@ module Protobuf
|
|
108
98
|
log_debug { "[#{log_signature}] response (should/actual): %s/%s" % [expected.name, actual.name] }
|
109
99
|
|
110
100
|
# Determine if the service tried to change response types on us
|
111
|
-
if expected
|
112
|
-
serialize_response(response)
|
113
|
-
else
|
114
|
-
# response types do not match, throw the appropriate error
|
101
|
+
if expected != actual
|
115
102
|
raise ::Protobuf::Rpc::BadResponseProto, 'Response proto changed from %s to %s' % [expected.name, actual.name]
|
103
|
+
else
|
104
|
+
@response.response_proto = response
|
116
105
|
end
|
117
106
|
rescue => error
|
118
107
|
log_error error.message
|
@@ -122,8 +111,8 @@ module Protobuf
|
|
122
111
|
|
123
112
|
# Parses and returns the service and method name from the request wrapper proto
|
124
113
|
def parse_service_info
|
125
|
-
@klass =
|
126
|
-
@method =
|
114
|
+
@klass = @request.service_name.constantize
|
115
|
+
@method = @request.method_name.underscore.to_sym
|
127
116
|
|
128
117
|
unless @klass.instance_methods.include?(@method)
|
129
118
|
raise MethodNotFound, "Service method #{@request.method_name} is not defined by the service"
|
@@ -144,17 +133,7 @@ module Protobuf
|
|
144
133
|
@stats.log_stats
|
145
134
|
@did_respond = true
|
146
135
|
ensure
|
147
|
-
GC.enable if
|
148
|
-
end
|
149
|
-
|
150
|
-
def serialize_response(response)
|
151
|
-
GC.disable if _gc_pause_serialization
|
152
|
-
log_debug { "[#{log_signature}] serializing response: %s" % response.inspect }
|
153
|
-
@response.response_proto = response.serialize_to_string
|
154
|
-
rescue
|
155
|
-
raise BadResponseProto, $!.message
|
156
|
-
ensure
|
157
|
-
GC.enable if _gc_pause_serialization
|
136
|
+
::GC.enable if ::Protobuf.gc_pause_server_request
|
158
137
|
end
|
159
138
|
end
|
160
139
|
end
|
@@ -1,31 +1,31 @@
|
|
1
1
|
module Protobuf
|
2
2
|
module Rpc
|
3
|
-
class EventedRunner
|
3
|
+
class EventedRunner
|
4
4
|
|
5
5
|
def self.stop
|
6
|
-
EventMachine.stop_event_loop if EventMachine.reactor_running?
|
7
|
-
Protobuf::Logger.info 'Shutdown complete'
|
6
|
+
::EventMachine.stop_event_loop if ::EventMachine.reactor_running?
|
8
7
|
end
|
9
8
|
|
10
9
|
def self.run(server)
|
11
10
|
# Ensure errors thrown within EM are caught and logged appropriately
|
12
|
-
EventMachine.error_handler do |error|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
#EventMachine.error_handler do |error|
|
12
|
+
# raise error
|
13
|
+
# if error.message == 'no acceptor'
|
14
|
+
# raise 'Failed binding to %s:%d (%s)' % [server.host, server.port, error.message]
|
15
|
+
# else
|
16
|
+
# Protobuf::Logger.error(error.message)
|
17
|
+
# Protobuf::Logger.error(error.backtrace.join("\n"))
|
18
|
+
# end
|
19
|
+
#end
|
20
20
|
|
21
21
|
# Startup and run the rpc server
|
22
|
-
|
23
|
-
EventMachine.start_server(server.host, server.port, Protobuf::Rpc::Evented::Server)
|
24
|
-
Protobuf::Logger.info('RPC Server listening at %s:%d in %s' % [server.host, server.port, server.env])
|
22
|
+
::EventMachine.schedule do
|
23
|
+
::EventMachine.start_server(server.host, server.port, ::Protobuf::Rpc::Evented::Server)
|
25
24
|
end
|
26
25
|
|
27
26
|
# Join or start the reactor
|
28
|
-
|
27
|
+
yield if block_given?
|
28
|
+
::EM.reactor_running? ? ::EM.reactor_thread.join : ::EM.run
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|