class Riemann::Babbler::Client
Constants
- CONNECT_TIMEOUT
- RIEMANN_PORT
- SEND_TIMEOUT
Attributes
host[RW]
port[RW]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/riemann/babbler/client.rb, line 17 def initialize(opts = {}) @host = opts[:host] @port = opts[:port] || RIEMANN_PORT @mutex = Mutex.new end
Public Instance Methods
<<(events)
click to toggle source
# File lib/riemann/babbler/client.rb, line 23 def <<(events) events = [events] if events.kind_of?(Hash) events = events.map {|e| Riemann::Babbler::Event.new(e) } message = Riemann::Babbler::Message.new(:events => events) with_connection do |socket| x = message.encode_with_length Timeout::timeout(SEND_TIMEOUT) { socket.write(x) socket.flush } end end
connect()
click to toggle source
# File lib/riemann/babbler/client.rb, line 42 def connect Timeout::timeout(CONNECT_TIMEOUT) { @socket = TCPSocket.new(@host, @port) } end
with_connection() { |socket || connect| ... }
click to toggle source
# File lib/riemann/babbler/client.rb, line 36 def with_connection @mutex.synchronize do yield(@socket || connect) end end