lib/zoomq/server.rb in zoomq-0.1.1 vs lib/zoomq/server.rb in zoomq-0.2.0
- old
+ new
@@ -1,38 +1,41 @@
# encoding: utf-8
-require 'zoomq/jeromq-0.3.0-20130721.175323-20.jar'
-java_import org.zeromq.ZMQ
-
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
- def_delegators :@ctx, :create_socket
- attr_reader :log, :fqdn, :port
+ attr_reader :fqdn, :port
- def initialize(service_name, zookeeper_uri, log)
+ def initialize
+ $log.info("#{service_name}:initialize #{RUBY_DESCRIPTION}")
+ $log.info("#{service_name}:initialize", {
+ env: Env.mode,
+ })
+
Signal.register_shutdown_handler { shutdown }
- @log = log
- @zk = Zookeeper.new("#{zookeeper_uri}/#{service_name}")
- @ctx = ZContext.new
- @fqdn = Socket.gethostbyname(Socket.gethostname).first
+ @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
- @ctx.destroy if @ctx
@zk.close if @zk
+ ZMachine.stop_event_loop
end
end
end