Sha256: 16b26e1bb4510b1412ddc28faf89223d8d1997c1d3c9a13bd1e4963c343e094f

Contents?: true

Size: 1.2 KB

Versions: 48

Compression:

Stored size: 1.2 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(options = {})
          log_debug { sign_message("initializing broker") }
          @broker = ::Protobuf::Rpc::Zmq::Broker.new(options)
          local_worker_threads = options[:threads]

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

          log_debug { sign_message("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

48 entries across 48 versions & 1 rubygems

Version Path
protobuf-2.5.5-java lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.5.5 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.5.4-java lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.5.4 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.5.3 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.5.2-java lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.5.2 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.5.1 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.5.0-java lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.5.0 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.4.8-java lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.4.8 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.4.7-java lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.4.7 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.4.6 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.4.5-java lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.4.5 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.4.4-java lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.4.4 lib/protobuf/rpc/servers/zmq/server.rb
protobuf-2.4.3-java lib/protobuf/rpc/servers/zmq/server.rb