protobuf 3.3.6 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +48 -0
  3. data/.rubocop_todo.yml +79 -0
  4. data/.travis.yml +12 -4
  5. data/Rakefile +14 -11
  6. data/bin/protoc-gen-ruby +0 -1
  7. data/bin/rpc_server +1 -0
  8. data/install-protobuf.sh +8 -0
  9. data/lib/protobuf.rb +30 -24
  10. data/lib/protobuf/cli.rb +35 -35
  11. data/lib/protobuf/code_generator.rb +11 -8
  12. data/lib/protobuf/decoder.rb +4 -5
  13. data/lib/protobuf/deprecation.rb +20 -0
  14. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +2 -0
  15. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +2 -0
  16. data/lib/protobuf/encoder.rb +9 -4
  17. data/lib/protobuf/enum.rb +38 -54
  18. data/lib/protobuf/field.rb +2 -2
  19. data/lib/protobuf/field/base_field.rb +28 -32
  20. data/lib/protobuf/field/bool_field.rb +4 -4
  21. data/lib/protobuf/field/bytes_field.rb +5 -4
  22. data/lib/protobuf/field/double_field.rb +0 -1
  23. data/lib/protobuf/field/enum_field.rb +4 -7
  24. data/lib/protobuf/field/field_array.rb +3 -4
  25. data/lib/protobuf/field/fixed32_field.rb +1 -1
  26. data/lib/protobuf/field/fixed64_field.rb +0 -1
  27. data/lib/protobuf/field/float_field.rb +0 -1
  28. data/lib/protobuf/field/int32_field.rb +0 -1
  29. data/lib/protobuf/field/int64_field.rb +0 -1
  30. data/lib/protobuf/field/integer_field.rb +0 -1
  31. data/lib/protobuf/field/message_field.rb +2 -3
  32. data/lib/protobuf/field/sfixed32_field.rb +0 -1
  33. data/lib/protobuf/field/sfixed64_field.rb +0 -1
  34. data/lib/protobuf/field/signed_integer_field.rb +0 -1
  35. data/lib/protobuf/field/sint32_field.rb +0 -1
  36. data/lib/protobuf/field/sint64_field.rb +0 -1
  37. data/lib/protobuf/field/string_field.rb +0 -1
  38. data/lib/protobuf/field/uint32_field.rb +0 -1
  39. data/lib/protobuf/field/uint64_field.rb +0 -1
  40. data/lib/protobuf/field/varint_field.rb +0 -1
  41. data/lib/protobuf/generators/base.rb +1 -2
  42. data/lib/protobuf/generators/enum_generator.rb +1 -2
  43. data/lib/protobuf/generators/extension_generator.rb +1 -2
  44. data/lib/protobuf/generators/field_generator.rb +4 -5
  45. data/lib/protobuf/generators/file_generator.rb +22 -27
  46. data/lib/protobuf/generators/group_generator.rb +15 -16
  47. data/lib/protobuf/generators/message_generator.rb +13 -14
  48. data/lib/protobuf/generators/printable.rb +9 -10
  49. data/lib/protobuf/generators/service_generator.rb +1 -2
  50. data/lib/protobuf/lifecycle.rb +20 -33
  51. data/lib/protobuf/logging.rb +4 -6
  52. data/lib/protobuf/message.rb +22 -16
  53. data/lib/protobuf/message/fields.rb +14 -17
  54. data/lib/protobuf/message/serialization.rb +6 -5
  55. data/lib/protobuf/rpc/buffer.rb +10 -12
  56. data/lib/protobuf/rpc/client.rb +12 -12
  57. data/lib/protobuf/rpc/connectors/base.rb +4 -3
  58. data/lib/protobuf/rpc/connectors/common.rb +15 -17
  59. data/lib/protobuf/rpc/connectors/socket.rb +2 -2
  60. data/lib/protobuf/rpc/connectors/zmq.rb +118 -108
  61. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +2 -0
  62. data/lib/protobuf/rpc/env.rb +12 -12
  63. data/lib/protobuf/rpc/error.rb +1 -1
  64. data/lib/protobuf/rpc/error/client_error.rb +4 -4
  65. data/lib/protobuf/rpc/error/server_error.rb +6 -6
  66. data/lib/protobuf/rpc/middleware/exception_handler.rb +1 -1
  67. data/lib/protobuf/rpc/middleware/logger.rb +3 -3
  68. data/lib/protobuf/rpc/middleware/request_decoder.rb +5 -5
  69. data/lib/protobuf/rpc/middleware/response_encoder.rb +3 -3
  70. data/lib/protobuf/rpc/rpc.pb.rb +2 -0
  71. data/lib/protobuf/rpc/servers/socket/server.rb +75 -65
  72. data/lib/protobuf/rpc/servers/socket/worker.rb +2 -2
  73. data/lib/protobuf/rpc/servers/socket_runner.rb +12 -6
  74. data/lib/protobuf/rpc/servers/zmq/broker.rb +10 -6
  75. data/lib/protobuf/rpc/servers/zmq/server.rb +20 -26
  76. data/lib/protobuf/rpc/servers/zmq/util.rb +7 -7
  77. data/lib/protobuf/rpc/servers/zmq/worker.rb +5 -7
  78. data/lib/protobuf/rpc/servers/zmq_runner.rb +14 -3
  79. data/lib/protobuf/rpc/service.rb +15 -15
  80. data/lib/protobuf/rpc/service_directory.rb +7 -11
  81. data/lib/protobuf/rpc/service_dispatcher.rb +3 -3
  82. data/lib/protobuf/rpc/service_filters.rb +27 -28
  83. data/lib/protobuf/rpc/stat.rb +4 -7
  84. data/lib/protobuf/socket.rb +0 -1
  85. data/lib/protobuf/tasks/compile.rake +2 -2
  86. data/lib/protobuf/version.rb +1 -1
  87. data/protobuf.gemspec +20 -4
  88. data/spec/benchmark/tasks.rb +49 -23
  89. data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
  90. data/spec/encoding/all_types_spec.rb +91 -77
  91. data/spec/encoding/extreme_values_spec.rb +0 -0
  92. data/spec/functional/socket_server_spec.rb +9 -10
  93. data/spec/functional/zmq_server_spec.rb +21 -19
  94. data/spec/lib/protobuf/cli_spec.rb +20 -20
  95. data/spec/lib/protobuf/code_generator_spec.rb +6 -6
  96. data/spec/lib/protobuf/enum_spec.rb +57 -31
  97. data/spec/lib/protobuf/field/float_field_spec.rb +2 -2
  98. data/spec/lib/protobuf/field/int32_field_spec.rb +1 -1
  99. data/spec/lib/protobuf/field/string_field_spec.rb +7 -8
  100. data/spec/lib/protobuf/field_spec.rb +3 -6
  101. data/spec/lib/protobuf/generators/base_spec.rb +6 -6
  102. data/spec/lib/protobuf/generators/enum_generator_spec.rb +22 -17
  103. data/spec/lib/protobuf/generators/extension_generator_spec.rb +8 -9
  104. data/spec/lib/protobuf/generators/field_generator_spec.rb +14 -11
  105. data/spec/lib/protobuf/generators/file_generator_spec.rb +7 -4
  106. data/spec/lib/protobuf/generators/service_generator_spec.rb +14 -11
  107. data/spec/lib/protobuf/lifecycle_spec.rb +9 -4
  108. data/spec/lib/protobuf/message_spec.rb +63 -35
  109. data/spec/lib/protobuf/optionable_spec.rb +3 -3
  110. data/spec/lib/protobuf/rpc/client_spec.rb +2 -2
  111. data/spec/lib/protobuf/rpc/connector_spec.rb +1 -1
  112. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +6 -6
  113. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +26 -18
  114. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +4 -4
  115. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +11 -9
  116. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +2 -2
  117. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +7 -7
  118. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +14 -14
  119. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +5 -5
  120. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +1 -1
  121. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +9 -7
  122. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +9 -9
  123. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +2 -2
  124. data/spec/lib/protobuf/rpc/service_directory_spec.rb +24 -23
  125. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +4 -4
  126. data/spec/lib/protobuf/rpc/service_filters_spec.rb +84 -51
  127. data/spec/lib/protobuf/rpc/service_spec.rb +15 -14
  128. data/spec/lib/protobuf/rpc/stat_spec.rb +1 -1
  129. data/spec/lib/protobuf_spec.rb +9 -9
  130. data/spec/spec_helper.rb +7 -19
  131. data/spec/support/server.rb +29 -59
  132. data/spec/support/test/defaults.pb.rb +2 -0
  133. data/spec/support/test/enum.pb.rb +2 -0
  134. data/spec/support/test/extended.pb.rb +2 -0
  135. data/spec/support/test/google_unittest_import.pb.rb +2 -0
  136. data/spec/support/test/google_unittest_import_public.pb.rb +2 -0
  137. data/spec/support/test/multi_field_extensions.pb.rb +2 -0
  138. data/spec/support/test/resource.pb.rb +2 -0
  139. data/spec/support/test/resource_service.rb +17 -20
  140. metadata +153 -112
  141. data/lib/protobuf/deprecator.rb +0 -42
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  ##
2
4
  # This file is auto-generated. DO NOT EDIT!
3
5
  #
@@ -16,19 +16,19 @@ module Protobuf
16
16
  #
17
17
  def self.hash_accessor(*names) #:nodoc:
18
18
  names.each do |name|
19
- class_eval <<-METHOD, __FILE__, __LINE__ + 1
20
- def #{name}
21
- self['#{name}']
22
- end
19
+ name_str = name.to_s.freeze
23
20
 
24
- def #{name}=(value)
25
- self['#{name}'] = value
26
- end
21
+ define_method name do
22
+ self[name_str]
23
+ end
27
24
 
28
- def #{name}?
29
- ! self['#{name}'].nil?
30
- end
31
- METHOD
25
+ define_method "#{name}=" do |value|
26
+ self[name_str] = value
27
+ end
28
+
29
+ define_method "#{name}?" do
30
+ !self[name_str].nil?
31
+ end
32
32
  end
33
33
  end
34
34
 
@@ -48,7 +48,7 @@ module Protobuf
48
48
  :service_name,
49
49
  :worker_id
50
50
 
51
- def initialize(options={})
51
+ def initialize(options = {})
52
52
  merge!(options)
53
53
 
54
54
  self['worker_id'] = ::Thread.current.object_id.to_s(16)
@@ -8,7 +8,7 @@ module Protobuf
8
8
  class PbError < StandardError
9
9
  attr_reader :error_type
10
10
 
11
- def initialize(message='An unknown RpcError occurred', error_type='RPC_ERROR')
11
+ def initialize(message = 'An unknown RpcError occurred', error_type = 'RPC_ERROR')
12
12
  @error_type = error_type.is_a?(String) ? Socketrpc::ErrorReason.const_get(error_type) : error_type
13
13
  super message
14
14
  end
@@ -4,25 +4,25 @@ module Protobuf
4
4
  module Rpc
5
5
 
6
6
  class InvalidRequestProto < PbError
7
- def initialize(message='Invalid request type given')
7
+ def initialize(message = 'Invalid request type given')
8
8
  super message, 'INVALID_REQUEST_PROTO'
9
9
  end
10
10
  end
11
11
 
12
12
  class BadResponseProto < PbError
13
- def initialize(message='Bad response type from server')
13
+ def initialize(message = 'Bad response type from server')
14
14
  super message, 'BAD_RESPONSE_PROTO'
15
15
  end
16
16
  end
17
17
 
18
18
  class UnkownHost < PbError
19
- def initialize(message='Unknown host or port')
19
+ def initialize(message = 'Unknown host or port')
20
20
  super message, 'UNKNOWN_HOST'
21
21
  end
22
22
  end
23
23
 
24
24
  class IOError < PbError
25
- def initialize(message='IO Error occurred')
25
+ def initialize(message = 'IO Error occurred')
26
26
  super message, 'IO_ERROR'
27
27
  end
28
28
  end
@@ -4,37 +4,37 @@ module Protobuf
4
4
  module Rpc
5
5
 
6
6
  class BadRequestData < PbError
7
- def initialize message='Unable to parse request'
7
+ def initialize(message = 'Unable to parse request')
8
8
  super message, 'BAD_REQUEST_DATA'
9
9
  end
10
10
  end
11
11
 
12
12
  class BadRequestProto < PbError
13
- def initialize message='Request is of wrong type'
13
+ def initialize(message = 'Request is of wrong type')
14
14
  super message, 'BAD_REQUEST_PROTO'
15
15
  end
16
16
  end
17
17
 
18
18
  class ServiceNotFound < PbError
19
- def initialize message='Service class not found'
19
+ def initialize(message = 'Service class not found')
20
20
  super message, 'SERVICE_NOT_FOUND'
21
21
  end
22
22
  end
23
23
 
24
24
  class MethodNotFound < PbError
25
- def initialize message='Service method not found'
25
+ def initialize(message = 'Service method not found')
26
26
  super message, 'METHOD_NOT_FOUND'
27
27
  end
28
28
  end
29
29
 
30
30
  class RpcError < PbError
31
- def initialize message='RPC exception occurred'
31
+ def initialize(message = 'RPC exception occurred')
32
32
  super message, 'RPC_ERROR'
33
33
  end
34
34
  end
35
35
 
36
36
  class RpcFailed < PbError
37
- def initialize message='RPC failed'
37
+ def initialize(message = 'RPC failed')
38
38
  super message, 'RPC_FAILED'
39
39
  end
40
40
  end
@@ -22,7 +22,7 @@ module Protobuf
22
22
  env
23
23
  end
24
24
 
25
- private
25
+ private
26
26
 
27
27
  # Wrap exceptions in a generic Protobuf errors unless they already are
28
28
  #
@@ -19,7 +19,7 @@ module Protobuf
19
19
  env
20
20
  end
21
21
 
22
- private
22
+ private
23
23
 
24
24
  def instrumenter
25
25
  @instrumenter ||= Instrumenter.new
@@ -63,11 +63,11 @@ module Protobuf
63
63
  rpc,
64
64
  sizes,
65
65
  elapsed_time,
66
- @end_time.try(:iso8601)
66
+ @end_time.try(:iso8601),
67
67
  ].compact.join(' - ')
68
68
  end
69
69
 
70
- private
70
+ private
71
71
 
72
72
  def elapsed_time
73
73
  (@start_time && @end_time ? "#{(@end_time - @start_time).round(4)}s" : nil)
@@ -30,14 +30,14 @@ module Protobuf
30
30
  env.log_signature || super
31
31
  end
32
32
 
33
- private
33
+ private
34
34
 
35
35
  def method_name
36
36
  @method_name ||= begin
37
37
  method_name = request_wrapper.method_name.underscore.to_sym
38
38
 
39
39
  unless service.rpc_method?(method_name)
40
- raise MethodNotFound.new("#{service.name}##{method_name} is not a defined RPC method.")
40
+ fail MethodNotFound, "#{service.name}##{method_name} is not a defined RPC method."
41
41
  end
42
42
 
43
43
  method_name
@@ -50,7 +50,7 @@ module Protobuf
50
50
  rpc_method.request_type.decode(data)
51
51
  end
52
52
  rescue => exception
53
- raise BadRequestData.new("Unable to decode request: #{exception.message}")
53
+ raise BadRequestData, "Unable to decode request: #{exception.message}"
54
54
  end
55
55
 
56
56
  # Decode the incoming request object into our expected request object
@@ -61,7 +61,7 @@ module Protobuf
61
61
  Socketrpc::Request.decode(env.encoded_request)
62
62
  end
63
63
  rescue => exception
64
- raise BadRequestData.new("Unable to decode request: #{exception.message}")
64
+ raise BadRequestData, "Unable to decode request: #{exception.message}"
65
65
  end
66
66
 
67
67
  def rpc_method
@@ -71,7 +71,7 @@ module Protobuf
71
71
  def service
72
72
  @service ||= service_name.constantize
73
73
  rescue NameError
74
- raise ServiceNotFound.new("Service class #{service_name} is not defined.")
74
+ raise ServiceNotFound, "Service class #{service_name} is not defined."
75
75
  end
76
76
 
77
77
  def service_name
@@ -22,7 +22,7 @@ module Protobuf
22
22
  env.log_signature || super
23
23
  end
24
24
 
25
- private
25
+ private
26
26
 
27
27
  # Encode the response wrapper to return to the client
28
28
  #
@@ -35,7 +35,7 @@ module Protobuf
35
35
 
36
36
  # Rescue encoding exceptions, re-wrap them as generic protobuf errors,
37
37
  # and re-raise them
38
- raise PbError.new(exception.message)
38
+ raise PbError, exception.message
39
39
  end
40
40
 
41
41
  # Prod the object to see if we can produce a proto object as a response
@@ -66,7 +66,7 @@ module Protobuf
66
66
  expected = env.response_type
67
67
 
68
68
  if expected != actual
69
- raise BadResponseProto.new("Expected response to be of type #{expected.name} but was #{actual.name}")
69
+ fail BadResponseProto, "Expected response to be of type #{expected.name} but was #{actual.name}"
70
70
  end
71
71
 
72
72
  candidate
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  ##
2
4
  # This file is auto-generated. DO NOT EDIT!
3
5
  #
@@ -1,4 +1,5 @@
1
- require 'protobuf/rpc/server'
1
+ require 'set'
2
+
2
3
  require 'protobuf/rpc/servers/socket/worker'
3
4
 
4
5
  module Protobuf
@@ -9,33 +10,52 @@ module Protobuf
9
10
 
10
11
  AUTO_COLLECT_TIMEOUT = 5 # seconds
11
12
 
13
+ private
14
+
15
+ attr_accessor :threshold, :host, :port, :backlog
16
+ attr_writer :running
17
+
18
+ public
19
+
20
+ attr_reader :running
21
+ alias_method :running?, :running
22
+
12
23
  def initialize(options)
13
- @options = options
24
+ self.running = false
25
+ self.host = options.fetch(:host)
26
+ self.port = options.fetch(:port)
27
+ self.backlog = options.fetch(:backlog, 100)
28
+ self.threshold = options.fetch(:threshold, 100)
29
+ end
30
+
31
+ def threads
32
+ @threads ||= []
33
+ end
34
+
35
+ def working
36
+ @working ||= Set.new
14
37
  end
15
38
 
16
39
  def cleanup?
17
- # every 10 connections run a cleanup routine after closing the response
18
- @threads.size > (@threshold - 1) && (@threads.size % @threshold) == 0
40
+ # every `threshold` connections run a cleanup routine after closing the response
41
+ threads.size > 0 && threads.size % threshold == 0
19
42
  end
20
43
 
21
44
  def cleanup_threads
22
- logger.debug { sign_message("Thread cleanup - #{@threads.size} - start") }
23
-
24
- @threads = @threads.select do |t|
25
- if t[:thread].alive?
26
- true
27
- else
28
- t[:thread].join
29
- @working.delete(t[:socket])
30
- false
45
+ logger.debug { sign_message("Thread cleanup - #{threads.size} - start") }
46
+
47
+ threads.delete_if do |hash|
48
+ unless (thread = hash.fetch(:thread)).alive?
49
+ thread.join
50
+ working.delete(hash.fetch(:socket))
31
51
  end
32
52
  end
33
53
 
34
- logger.debug { sign_message("Thread cleanup - #{@threads.size} - complete") }
54
+ logger.debug { sign_message("Thread cleanup - #{threads.size} - complete") }
35
55
  end
36
56
 
37
57
  def log_signature
38
- @_log_signature ||= "server-#{self.class.name}"
58
+ @_log_signature ||= "[server-#{self.class.name}]"
39
59
  end
40
60
 
41
61
  def new_worker(socket)
@@ -48,64 +68,54 @@ module Protobuf
48
68
 
49
69
  def run
50
70
  logger.debug { sign_message("Run") }
51
- host = @options[:host]
52
- port = @options[:port]
53
- backlog = @options[:backlog]
54
- @threshold = @options[:threshold]
55
-
56
- @threads = []
57
- @server = ::TCPServer.new(host, port)
58
- raise "The server was unable to start properly." if @server.closed?
59
-
60
- @server.listen(backlog)
61
- @working = []
62
- @listen_fds = [@server]
63
- @running = true
64
-
65
- while running?
66
- logger.debug { sign_message("Waiting for connections") }
67
- ready_cnxns = IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) rescue nil
68
-
69
- if ready_cnxns
70
- cnxns = ready_cnxns.first
71
- cnxns.each do |client|
72
- case
73
- when !running? then
74
- # no-op
75
- when client == @server then
76
- logger.debug { sign_message("Accepted new connection") }
77
- client, sockaddr = @server.accept
78
- @listen_fds << client
79
- else
80
- unless @working.include?(client)
81
- @working << @listen_fds.delete(client)
82
- logger.debug { sign_message("Working") }
83
- @threads << { :thread => new_worker(client), :socket => client }
84
-
85
- cleanup_threads if cleanup?
71
+
72
+ server = ::TCPServer.new(host, port)
73
+ fail "The server was unable to start properly." if server.closed?
74
+
75
+ begin
76
+ server.listen(backlog)
77
+ listen_fds = [server]
78
+ self.running = true
79
+
80
+ while running?
81
+ logger.debug { sign_message("Waiting for connections") }
82
+ ready_cnxns = begin
83
+ IO.select(listen_fds, [], [], AUTO_COLLECT_TIMEOUT)
84
+ rescue IOError
85
+ nil
86
+ end
87
+
88
+ if ready_cnxns
89
+ ready_cnxns.first.each do |client|
90
+ case
91
+ when !running?
92
+ # no-op
93
+ when client == server
94
+ logger.debug { sign_message("Accepted new connection") }
95
+ client, _sockaddr = server.accept
96
+ listen_fds << client
97
+ else
98
+ unless working.include?(client)
99
+ working << listen_fds.delete(client)
100
+ logger.debug { sign_message("Working") }
101
+ threads << { :thread => new_worker(client), :socket => client }
102
+
103
+ cleanup_threads if cleanup?
104
+ end
86
105
  end
87
106
  end
107
+ else
108
+ # Run a cleanup if select times out while waiting
109
+ cleanup_threads if threads.size > 1
88
110
  end
89
- else
90
- # Run a cleanup if select times out while waiting
91
- cleanup_threads if @threads.size > 1
92
111
  end
112
+ ensure
113
+ server.close
93
114
  end
94
-
95
- rescue Errno::EADDRINUSE
96
- raise
97
- rescue
98
- # Closing the server causes the loop to raise an exception here
99
- raise #if running?
100
- end
101
-
102
- def running?
103
- !!@running
104
115
  end
105
116
 
106
117
  def stop
107
- @running = false
108
- @server.try(:close)
118
+ self.running = false
109
119
  end
110
120
  end
111
121
  end
@@ -33,7 +33,7 @@ module Protobuf
33
33
  end
34
34
 
35
35
  def send_data(data)
36
- raise 'Socket closed unexpectedly' unless socket_writable?
36
+ fail 'Socket closed unexpectedly' unless socket_writable?
37
37
  response_buffer = Protobuf::Rpc::Buffer.new(:write)
38
38
  response_buffer.set_data(data)
39
39
 
@@ -44,7 +44,7 @@ module Protobuf
44
44
  end
45
45
 
46
46
  def log_signature
47
- @_log_signature ||= "server-#{self.class}-#{object_id}"
47
+ @_log_signature ||= "[server-#{self.class}-#{object_id}]"
48
48
  end
49
49
 
50
50
  def socket_writable?
@@ -2,8 +2,14 @@ module Protobuf
2
2
  module Rpc
3
3
  class SocketRunner
4
4
 
5
+ private
6
+
7
+ attr_accessor :server
8
+
9
+ public
10
+
5
11
  def initialize(options)
6
- @options = case
12
+ options = case
7
13
  when options.is_a?(OpenStruct) then
8
14
  options.marshal_dump
9
15
  when options.is_a?(Hash) then
@@ -11,23 +17,23 @@ module Protobuf
11
17
  when options.respond_to?(:to_hash) then
12
18
  options.to_hash
13
19
  else
14
- raise "Cannot parser Socket Server - server options"
20
+ fail "Cannot parser Socket Server - server options"
15
21
  end
16
22
 
17
- @server = ::Protobuf::Rpc::Socket::Server.new(@options)
23
+ self.server = ::Protobuf::Rpc::Socket::Server.new(options)
18
24
  end
19
25
 
20
26
  def run
21
27
  yield if block_given?
22
- @server.run
28
+ server.run
23
29
  end
24
30
 
25
31
  def running?
26
- @server.running?
32
+ server.running?
27
33
  end
28
34
 
29
35
  def stop
30
- @server.stop
36
+ server.stop
31
37
  end
32
38
  end
33
39
  end