Class: Xhummingbird::Client
- Inherits:
-
Object
- Object
- Xhummingbird::Client
- Includes:
- Singleton
- Defined in:
- lib/xhummingbird/client.rb
Constant Summary collapse
- XH_SERVER =
'XH_SERVER'
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #send(message) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 |
# File 'lib/xhummingbird/client.rb', line 7 def initialize @pid = nil @socket = nil @active = false end |
Instance Method Details
#enabled? ⇒ Boolean
21 22 23 |
# File 'lib/xhummingbird/client.rb', line 21 def enabled? @enabled ||= !!address end |
#send(message) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/xhummingbird/client.rb', line 13 def send() if active? @socket.send_string() else Xhummingbird.debug("Xhummingbird not started.") end end |
#start ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/xhummingbird/client.rb', line 25 def start return unless enabled? 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 |