Sha256: dbead9c785d6544cc08c2f518b96e532ed41d9ec9a05348d705f25051c06e6bc

Contents?: true

Size: 868 Bytes

Versions: 3

Compression:

Stored size: 868 Bytes

Contents

require 'miu'
require 'ffi-rzmq'

module Miu
  class Server
    attr_reader :options
    attr_reader :forwarder

    def initialize(options = {})
      @options = options
    end

    def run
      Logger.info "Starting Miu #{Miu::VERSION} (ZeroMQ #{ZMQ::LibZMQ.version.values.join('.')})"
      Logger.info "Publish on #{@options[:pub_host]}:#{@options[:pub_port]}"
      Logger.info "Subscribe on #{@options[:sub_host]}:#{@options[:sub_port]}"

      register_signal_handlers

      @forwarder = Forwarder.new @options
      @forwarder.run
    rescue => e
      Miu::Logger.exception e
    end

    def close
      @forwarder.close
    end

    def register_signal_handlers
      %w(INT TERM HUP QUIT).each do |sig|
        trap(sig) do
          close
          exit
        end
      end

      at_exit do
        Logger.info 'Quit...'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
miu-0.2.3 lib/miu/server.rb
miu-0.2.2 lib/miu/server.rb
miu-0.2.1 lib/miu/server.rb