Sha256: b9fb05e953393edce9256f8048e96cf8060494c9af6f93d6f17220c48c6681a6

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 KB

Contents

require 'protobuf/rpc/servers/zmq/broker'
require 'protobuf/rpc/servers/zmq/worker'
require 'protobuf/rpc/servers/zmq/util'

module Protobuf
  module Rpc
    module Zmq
      class Server
        include ::Protobuf::Rpc::Zmq::Util

        ##
        # Class Methods
        #
        def self.run(opts = {})
          log_debug { "[#{log_signature}] initializing broker" }
          @broker = ::Protobuf::Rpc::Zmq::Broker.new(opts)
          local_worker_threads = opts.fetch(:threads, 5)

          worker_options = opts.merge(:port => opts.fetch(:port, 9399) + 1)
          log_debug { "[#{log_signature}] starting server workers" }
          local_worker_threads.times do
            @threads << Thread.new { ::Protobuf::Rpc::Zmq::Worker.new(worker_options).run }
          end
          @running = true

          log_debug { "[#{log_signature}] server started" }
          while self.running? do
            @broker.poll
          end
        ensure
          @broker.teardown if @broker
        end

        def self.running?
          !!@running
        end

        def self.stop
          @running = false

          @threads.each do |t|
            t.join
          end
        end

        @threads ||= []
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
protobuf-2.0.0.rc3 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.0.0.rc2 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.0.0.rc1 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-1.4.2 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-1.4.1 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-1.4.0 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-1.3.0 lib/protobuf/rpc/servers/zmq/server.rb