# encoding: utf-8 require 'zoomq/jeromq-0.3.0-20130721.175323-20.jar' java_import org.zeromq.ZMQ require 'forwardable' require 'zoomq/zookeeper' require 'zoomq/server/worker' module ZooMQ class Server extend Forwardable def_delegators :@zk, :globals, :locals, :announce def_delegators :@ctx, :create_socket attr_reader :log, :fqdn, :port def initialize(service_name, zookeeper_uri, log) Signal.register_shutdown_handler { shutdown } @log = log @zk = Zookeeper.new("#{zookeeper_uri}/#{service_name}") @ctx = ZContext.new @fqdn = Socket.gethostbyname(Socket.gethostname).first end def run Worker.new(self).run end def shutdown @ctx.destroy if @ctx @zk.close if @zk end end end