Class: ZooMQ::Server

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/zoomq/server.rb,
lib/zoomq/server/worker.rb,
lib/zoomq/server/connection.rb

Defined Under Namespace

Classes: Connection, Worker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/zoomq/server.rb', line 18

def initialize
  $log.info("#{service_name}:initialize #{RUBY_DESCRIPTION}")
  $log.info("#{service_name}:initialize", {
    env: Env.mode,
  })

  ZMachine.logger = $log
  Signal.register_shutdown_handler { shutdown }
  @fqdn = ::Socket.gethostbyname(::Socket.gethostname).first
  @zk = Zookeeper.new(service_name)
end

Instance Attribute Details

#fqdnObject (readonly)

Returns the value of attribute fqdn.



16
17
18
# File 'lib/zoomq/server.rb', line 16

def fqdn
  @fqdn
end

#portObject (readonly)

Returns the value of attribute port.



16
17
18
# File 'lib/zoomq/server.rb', line 16

def port
  @port
end

Instance Method Details

#runObject



30
31
32
33
34
# File 'lib/zoomq/server.rb', line 30

def run
  # TODO: make it multi-threaded
  $log.info("#{service_name}:run", workers: 1)
  Worker.new(self).run
end

#shutdownObject



36
37
38
39
# File 'lib/zoomq/server.rb', line 36

def shutdown
  @zk.close if @zk
  ZMachine.stop_event_loop
end