protobuf 2.8.0.beta5-java → 2.8.0.beta6-java

Sign up to get free protection for your applications and to get access to all the features.
data/lib/protobuf/cli.rb CHANGED
@@ -29,7 +29,6 @@ module Protobuf
29
29
  option :evented, :type => :boolean, :aliases => %w(-m), :desc => 'Evented Mode for server and client connections (uses EventMachine).'
30
30
  option :zmq, :type => :boolean, :aliases => %w(-z), :desc => 'ZeroMQ Socket Mode for server and client connections.'
31
31
 
32
- option :beacon_address, :type => :string, :desc => 'Broadcast beacons to this address (defaul: value of ServiceDirectory.address)'
33
32
  option :beacon_interval, :type => :numeric, :desc => 'Broadcast beacons every N seconds. (default: 5)'
34
33
  option :beacon_port, :type => :numeric, :desc => 'Broadcast beacons to this port (default: value of ServiceDirectory.port)'
35
34
  option :broadcast_beacons, :type => :boolean, :desc => 'Broadcast beacons for dynamic discovery (Currently only available with ZeroMQ).'
@@ -68,7 +68,6 @@ module Protobuf
68
68
  @socket.flush
69
69
  log_debug { sign_message("write closed") }
70
70
  end
71
-
72
71
  end
73
72
  end
74
73
  end
@@ -6,6 +6,8 @@ module Protobuf
6
6
  module Connectors
7
7
  class Zmq < Base
8
8
 
9
+ RequestTimeout = Class.new(RuntimeError)
10
+
9
11
  ##
10
12
  # Included Modules
11
13
  #
@@ -23,7 +25,11 @@ module Protobuf
23
25
  # Class Methods
24
26
  #
25
27
  def self.zmq_context
26
- @zmq_context ||= ZMQ::Context.new
28
+ @zmq_contexts ||= Hash.new { |hash, key|
29
+ hash[key] = ZMQ::Context.new
30
+ }
31
+
32
+ @zmq_contexts[Process.pid]
27
33
  end
28
34
 
29
35
  ##
@@ -37,9 +43,7 @@ module Protobuf
37
43
  #
38
44
  def send_request
39
45
  setup_connection
40
- poll_send_data
41
- ensure
42
- close_connection
46
+ send_request_with_lazy_pirate
43
47
  end
44
48
 
45
49
  def log_signature
@@ -53,23 +57,23 @@ module Protobuf
53
57
  #
54
58
 
55
59
  def close_connection
56
- socket_close
60
+ # The socket is automatically closed after every request.
57
61
  end
58
62
 
59
- # Establish a request socket connection to the remote rpc_server.
60
- # Set the socket option LINGER to 0 so that we don't wait
61
- # for queued messages to be accepted when the socket/context are
62
- # asked to close/terminate.
63
- #
64
- def connect_to_rpc_server
65
- return if error?
66
-
63
+ # Create a socket connected to a server that can handle the current
64
+ # service. The LINGER is set to 0 so we can close immediately in
65
+ # the event of a timeout
66
+ def create_socket
67
67
  server_uri = lookup_server_uri
68
- log_debug { sign_message("Establishing connection: #{server_uri}") }
68
+
69
+ socket = zmq_context.socket(::ZMQ::REQ)
69
70
  socket.setsockopt(::ZMQ::LINGER, 0)
71
+
72
+ log_debug { sign_message("Establishing connection: #{server_uri}") }
70
73
  zmq_error_check(socket.connect(server_uri), :socket_connect)
71
- zmq_error_check(poller.register_readable(socket), :poller_register_readable)
72
74
  log_debug { sign_message("Connection established to #{server_uri}") }
75
+
76
+ socket
73
77
  end
74
78
 
75
79
  # Method to determine error state, must be used with Connector API.
@@ -97,53 +101,44 @@ module Protobuf
97
101
  # If we haven't received a legitimate response in the CLIENT_RETRIES number
98
102
  # of retries, fail the request.
99
103
  #
100
- def poll_send_data
101
- return if error?
102
-
103
- poll_timeout = (options[:timeout].to_f / CLIENT_RETRIES.to_f) * 1000
104
-
105
- CLIENT_RETRIES.times do |n|
106
- connect_to_rpc_server
107
- log_debug { sign_message("Sending Request (attempt #{n + 1}, #{socket})") }
108
- send_data
109
- log_debug { sign_message("Request sending complete (attempt #{n + 1}, #{socket})") }
110
-
111
- if poller.poll(poll_timeout) == 1
112
- read_response
113
- return
114
- else
115
- socket_close
116
- end
117
- end
118
-
119
- fail(:RPC_FAILED, "The server took longer than #{options[:timeout]} seconds to respond")
120
- end
104
+ def send_request_with_lazy_pirate
105
+ attempt = 0
106
+ timeout = options[:timeout].to_f
107
+ @stats.request_size = @request_data.size
121
108
 
122
- def poller
123
- @poller ||= ::ZMQ::Poller.new
109
+ begin
110
+ attempt += 1
111
+ send_request_with_timeout(timeout, attempt)
112
+ parse_response
113
+ rescue RequestTimeout
114
+ retry if attempt < CLIENT_RETRIES
115
+ fail(:RPC_FAILED, "The server repeatedly failed to respond within #{timeout} seconds")
116
+ rescue => e
117
+ fail(:RPC_FAILED, "Unexpected error sending request: #{e}")
118
+ end
124
119
  end
125
120
 
126
- # Read the string response from the available readable. This will be
127
- # the current @socket. Calls `parse_response` to invoke the success or
128
- # failed callbacks, depending on the state of the communication
129
- # and response data.
130
- #
131
- def read_response
132
- return if error?
133
-
134
- @response_data = ''
135
- zmq_error_check(socket.recv_string(@response_data), :socket_recv_string)
136
-
137
- parse_response
138
- end
121
+ def send_request_with_timeout(timeout, attempt = 0)
122
+ socket = create_socket
139
123
 
140
- # Send the request data to the remote rpc_server.
141
- #
142
- def send_data
143
- return if error?
124
+ poller = ::ZMQ::Poller.new
125
+ poller.register_readable(socket)
144
126
 
145
- @stats.request_size = @request_data.size
127
+ log_debug { sign_message("Sending Request (attempt #{attempt}, #{socket})") }
146
128
  zmq_error_check(socket.send_string(@request_data), :socket_send_string)
129
+ log_debug { sign_message("Waiting #{timeout} seconds for response (attempt #{attempt}, #{socket})") }
130
+
131
+ if poller.poll(timeout * 1000) == 1
132
+ zmq_error_check(socket.recv_string(@response_data = ""), :socket_recv_string)
133
+ log_debug { sign_message("Response received (attempt #{attempt}, #{socket})") }
134
+ else
135
+ log_debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") }
136
+ raise RequestTimeout
137
+ end
138
+ ensure
139
+ log_debug { sign_message("Closing Socket") }
140
+ zmq_error_check(socket.close, :socket_close)
141
+ log_debug { sign_message("Socket closed") }
147
142
  end
148
143
 
149
144
  # The service we're attempting to connect to
@@ -157,21 +152,6 @@ module Protobuf
157
152
  ::Protobuf::Rpc::ServiceDirectory.instance
158
153
  end
159
154
 
160
- # Setup a ZMQ request socket in the current zmq context.
161
- #
162
- def socket
163
- @socket ||= zmq_context.socket(::ZMQ::REQ)
164
- end
165
-
166
- def socket_close
167
- if socket
168
- log_debug { sign_message("Closing Socket") }
169
- zmq_error_check(socket.close, :socket_close)
170
- log_debug { sign_message("Socket closed") }
171
- @socket = nil
172
- end
173
- end
174
-
175
155
  # Return the ZMQ Context to use for this process.
176
156
  # If the context does not exist, create it, then register
177
157
  # an exit block to ensure the context is terminated correctly.
@@ -189,7 +169,6 @@ module Protobuf
189
169
  ERROR
190
170
  end
191
171
  end
192
-
193
172
  end
194
173
  end
195
174
  end
@@ -50,15 +50,7 @@ module Protobuf
50
50
  end
51
51
 
52
52
  def beacon_ip
53
- unless @beacon_ip
54
- unless address = options[:beacon_address]
55
- address = ::Protobuf::Rpc::ServiceDirectory.address
56
- end
57
-
58
- @beacon_ip = resolve_ip(address)
59
- end
60
-
61
- @beacon_ip
53
+ "255.255.255.255"
62
54
  end
63
55
 
64
56
  def beacon_port
@@ -39,6 +39,10 @@ module Protobuf
39
39
  @server.add_worker
40
40
  log_info { "Increased worker size to: #{@server.total_workers}" }
41
41
  end
42
+
43
+ trap(:TTOU) do
44
+ log_info { "Current worker size: #{@server.workers.size}" }
45
+ end
42
46
  end
43
47
  end
44
48
  end
@@ -1,4 +1,4 @@
1
1
  module Protobuf
2
- VERSION = '2.8.0.beta5'
2
+ VERSION = '2.8.0.beta6'
3
3
  PROTOC_VERSION = '2.4.1'
4
4
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 2.8.0.beta5
5
+ version: 2.8.0.beta6
6
6
  platform: java
7
7
  authors:
8
8
  - BJ Neilsen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-26 00:00:00.000000000 Z
13
+ date: 2013-07-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport