# encoding: utf-8 require 'forwardable' require 'socket' require 'zmachine' require 'zoomq/zookeeper' require 'zoomq/server/worker' module ZooMQ class Server extend Forwardable def_delegators :@zk, :globals, :locals, :announce attr_reader :fqdn, :port def initialize $log.info("#{service_name}:initialize #{RUBY_DESCRIPTION}") $log.info("#{service_name}:initialize", { env: Env.mode, }) Signal.register_shutdown_handler { shutdown } @fqdn = ::Socket.gethostbyname(::Socket.gethostname).first @zk = Zookeeper.new(service_name) end def run # TODO: make it multi-threaded $log.info("#{service_name}:run", workers: 1) Worker.new(self).run end def shutdown @zk.close if @zk ZMachine.stop_event_loop end end end