class Xhummingbird::Client

Constants

XH_SERVER

Public Class Methods

new() click to toggle source
# File lib/xhummingbird/client.rb, line 7
def initialize
  @pid = nil
  @socket = nil
  @active = false
end

Public Instance Methods

enabled?() click to toggle source
# File lib/xhummingbird/client.rb, line 21
def enabled?
  @enabled ||= !!address
end
send(message) click to toggle source
# File lib/xhummingbird/client.rb, line 13
def send(message)
  if active?
    @socket.send_string(message)
  else
    Xhummingbird.debug("Xhummingbird not started.")
  end
end
start() click to toggle source
# File lib/xhummingbird/client.rb, line 25
def start
  ctx = ZMQ::Context.new
  socket = ctx.socket(ZMQ::PUSH)
  socket.connect(address)
  @socket = socket
  Xhummingbird.debug("Socket created (pid: #{$$})")

  at_exit do
    Xhummingbird.debug("at_exit started.")
    @socket.close
    Xhummingbird.debug("at_exit stopped.")
  end

  @pid = $$
  @active = true
end

Private Instance Methods

active?() click to toggle source
# File lib/xhummingbird/client.rb, line 48
def active?
  @pid == $$ && @socket && @active
end
address() click to toggle source
# File lib/xhummingbird/client.rb, line 44
def address
  ENV[XH_SERVER]
end