protobuf 2.7.3-java → 2.7.4-java

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.
@@ -6,50 +6,84 @@ module Protobuf
6
6
  module Zmq
7
7
  class Broker
8
8
  include ::Protobuf::Rpc::Zmq::Util
9
- attr_reader :frontend, :backend, :poller, :context, :available_workers
9
+ attr_reader :frontend, :backend, :poller, :context, :available_workers, :options, :expected_worker_count
10
10
 
11
11
  ##
12
12
  # Constructor
13
13
  #
14
14
  def initialize(options = {})
15
15
  @available_workers = []
16
+ @options = options.deep_dup
17
+ @expected_worker_count = @options[:threads]
16
18
  @context = ::ZMQ::Context.new
17
- @frontend = setup_frontend(options)
18
- @backend = setup_backend(options)
19
19
  @poller = ::ZMQ::Poller.new
20
- @poller.register(frontend, ::ZMQ::POLLIN)
21
- @poller.register(backend, ::ZMQ::POLLIN)
20
+ setup_backend
22
21
  end
23
22
 
24
23
  ##
25
24
  # Instance Methods
26
25
  #
27
26
  def poll
28
- if available_workers.size > 0
29
- poller.register(frontend, ::ZMQ::POLLIN) if poller.size < 2
27
+ if frontend.nil?
28
+ if local_workers_have_started?
29
+ # only open the front end when the workers are done booting
30
+ log_info { "Starting frontend socket in broker, all workers ready!" }
31
+ setup_frontend
32
+ end
30
33
  else
31
- poller.delete(frontend)
34
+ # Start checking the poller after startup
35
+ if available_workers.size > 0
36
+ poller.register(frontend, ::ZMQ::POLLIN) if poller.size < 2
37
+ else
38
+ poller.delete(frontend)
39
+ end
32
40
  end
33
41
 
34
42
  poller.poll(1000)
35
43
  poller.readables.each do |socket|
36
44
  case socket
37
- when frontend then
38
- move_to_backend(socket)
39
45
  when backend then
40
46
  move_to_frontend(socket)
47
+ when frontend then
48
+ move_to_backend(socket)
41
49
  end
42
50
  end
43
51
  end
44
52
 
53
+ def setup_backend
54
+ host = options[:host]
55
+ port = options[:worker_port]
56
+
57
+ zmq_backend = context.socket(::ZMQ::ROUTER)
58
+ zmq_error_check(zmq_backend.bind(bind_address(host, port)))
59
+
60
+ @backend = zmq_backend
61
+ @poller.register(@backend, ::ZMQ::POLLIN)
62
+ end
63
+
64
+ def setup_frontend
65
+ host = options[:host]
66
+ port = options[:port]
67
+
68
+ zmq_frontend = context.socket(::ZMQ::ROUTER)
69
+ zmq_error_check(zmq_frontend.bind(bind_address(host, port)))
70
+
71
+ @frontend = zmq_frontend
72
+ @poller.register(@frontend, ::ZMQ::POLLIN)
73
+ end
74
+
45
75
  def teardown
46
- frontend.close
47
- backend.close
48
- context.terminate
76
+ frontend.try(:close)
77
+ backend.try(:close)
78
+ context.try(:terminate)
49
79
  end
50
80
 
51
81
  private
52
82
 
83
+ def local_workers_have_started?
84
+ @local_workers_have_started ||= available_workers.size >= expected_worker_count
85
+ end
86
+
53
87
  def move_to_backend(socket)
54
88
  message_array = []
55
89
  zmq_error_check(socket.recv_strings(message_array))
@@ -73,7 +107,9 @@ module Protobuf
73
107
  available_workers << message_array[0]
74
108
 
75
109
  # messages should be [ "uuid of socket", "", "READY_MESSAGE || uuid of client socket"]
76
- unless message_array[2] == ::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE
110
+ if message_array[2] == ::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE
111
+ log_info { "Worker #{available_workers.size} of #{expected_worker_count} ready!" }
112
+ else
77
113
  frontend_message_set = [
78
114
  message_array[2], # client UUID
79
115
  "",
@@ -84,24 +120,6 @@ module Protobuf
84
120
  end
85
121
  end
86
122
 
87
- def setup_backend(options = {})
88
- host = options[:host]
89
- port = options[:worker_port]
90
-
91
- zmq_backend = context.socket(::ZMQ::ROUTER)
92
- zmq_error_check(zmq_backend.bind(bind_address(host, port)))
93
- zmq_backend
94
- end
95
-
96
- def setup_frontend(options = {})
97
- host = options[:host]
98
- port = options[:port]
99
-
100
- zmq_frontend = context.socket(::ZMQ::ROUTER)
101
- zmq_error_check(zmq_frontend.bind(bind_address(host, port)))
102
- zmq_frontend
103
- end
104
-
105
123
  def bind_address(host, port)
106
124
  "tcp://#{resolve_ip(host)}:#{port}"
107
125
  end
@@ -62,7 +62,7 @@ module Protobuf
62
62
  @running = false
63
63
 
64
64
  @threads.each do |t|
65
- t.join
65
+ t.join(5) || t.kill
66
66
  end
67
67
  end
68
68
 
@@ -1,4 +1,4 @@
1
1
  module Protobuf
2
- VERSION = '2.7.3'
2
+ VERSION = '2.7.4'
3
3
  PROTOC_VERSION = '2.4.1'
4
4
  end
@@ -17,10 +17,6 @@ describe ::Protobuf::Rpc::Zmq::Broker do
17
17
  subject.context.should be_a(::ZMQ::Context)
18
18
  end
19
19
 
20
- it 'sets up a frontend socket' do
21
- subject.frontend.should be_a(::ZMQ::Socket)
22
- end
23
-
24
20
  it 'sets up a backend socket' do
25
21
  subject.backend.should be_a(::ZMQ::Socket)
26
22
  end
@@ -27,7 +27,7 @@ describe Protobuf::Rpc::Zmq::Server do
27
27
 
28
28
  it 'lets all threads stop' do
29
29
  thread_mock = double(Thread)
30
- thread_mock.should_receive(:join)
30
+ thread_mock.should_receive(:join).and_return(thread_mock)
31
31
  described_class.instance_variable_set(:@threads, [thread_mock])
32
32
  described_class.stop
33
33
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.7.3
5
+ version: 2.7.4
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-03-04 00:00:00.000000000 Z
13
+ date: 2013-03-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport