Class: Riemann::Client::UDP
- Inherits:
-
Riemann::Client
- Object
- Riemann::Client
- Riemann::Client::UDP
- Defined in:
- lib/riemann/client/udp.rb
Constant Summary collapse
- MAX_SIZE =
16384
Constants inherited from Riemann::Client
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#max_size ⇒ Object
Returns the value of attribute max_size.
-
#port ⇒ Object
Returns the value of attribute port.
-
#socket ⇒ Object
Returns the value of attribute socket.
Attributes inherited from Riemann::Client
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(opts = {}) ⇒ UDP
constructor
A new instance of UDP.
-
#read_message(s) ⇒ Object
Read a message from a stream.
- #send_maybe_recv(message) ⇒ Object
- #send_recv(*a) ⇒ Object
-
#with_connection ⇒ Object
Yields a connection in the block.
Methods inherited from Riemann::Client
Constructor Details
#initialize(opts = {}) ⇒ UDP
Returns a new instance of UDP.
8 9 10 11 12 13 |
# File 'lib/riemann/client/udp.rb', line 8 def initialize(opts = {}) @host = opts[:host] || HOST @port = opts[:port] || PORT @max_size = opts[:max_size] || MAX_SIZE @locket = Mutex.new end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/riemann/client/udp.rb', line 6 def host @host end |
#max_size ⇒ Object
Returns the value of attribute max_size.
6 7 8 |
# File 'lib/riemann/client/udp.rb', line 6 def max_size @max_size end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/riemann/client/udp.rb', line 6 def port @port end |
#socket ⇒ Object
Returns the value of attribute socket.
6 7 8 |
# File 'lib/riemann/client/udp.rb', line 6 def socket @socket end |
Instance Method Details
#close ⇒ Object
19 20 21 22 23 |
# File 'lib/riemann/client/udp.rb', line 19 def close @locket.synchronize do @socket.close end end |
#connect ⇒ Object
15 16 17 |
# File 'lib/riemann/client/udp.rb', line 15 def connect @socket = UDPSocket.new end |
#connected? ⇒ Boolean
25 26 27 |
# File 'lib/riemann/client/udp.rb', line 25 def connected? !!@socket && @socket.closed? end |
#read_message(s) ⇒ Object
Read a message from a stream
30 31 32 |
# File 'lib/riemann/client/udp.rb', line 30 def (s) raise Unsupported end |
#send_maybe_recv(message) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/riemann/client/udp.rb', line 38 def send_maybe_recv() with_connection do |s| x = .encode '' unless x.length < @max_size raise TooBig end s.send(x, 0, @host, @port) nil end end |
#send_recv(*a) ⇒ Object
34 35 36 |
# File 'lib/riemann/client/udp.rb', line 34 def send_recv(*a) raise Unsupported end |
#with_connection ⇒ Object
Yields a connection in the block.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/riemann/client/udp.rb', line 51 def with_connection tries = 0 @locket.synchronize do begin tries += 1 yield(@socket || connect) rescue IOError => e raise if tries > 3 connect and retry rescue Errno::EPIPE => e raise if tries > 3 connect and retry rescue Errno::ECONNREFUSED => e raise if tries > 3 connect and retry rescue Errno::ECONNRESET => e raise if tries > 3 connect and retry rescue InvalidResponse => e raise if tries > 3 connect and retry end end end |