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 =
16_384
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.
Attributes inherited from Riemann::Client
Instance Method Summary collapse
- #close ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(opts = {}) ⇒ UDP
constructor
rubocop:disable Lint/MissingSuper.
-
#read_message(_socket) ⇒ Object
Read a message from a stream.
- #send_maybe_recv(message) ⇒ Object
- #send_recv(_message) ⇒ Object
- #socket ⇒ Object
Methods inherited from Riemann::Client
#<<, #[], #bulk_send, #connect, #normalize_events, #query, #timeout
Constructor Details
#initialize(opts = {}) ⇒ UDP
rubocop:disable Lint/MissingSuper
10 11 12 13 14 15 |
# File 'lib/riemann/client/udp.rb', line 10 def initialize(opts = {}) # rubocop:disable Lint/MissingSuper @host = opts[:host] || HOST @port = opts[:port] || PORT @max_size = opts[:max_size] || MAX_SIZE @socket = nil end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/riemann/client/udp.rb', line 8 def host @host end |
#max_size ⇒ Object
Returns the value of attribute max_size.
8 9 10 |
# File 'lib/riemann/client/udp.rb', line 8 def max_size @max_size end |
#port ⇒ Object
Returns the value of attribute port.
8 9 10 |
# File 'lib/riemann/client/udp.rb', line 8 def port @port end |
Instance Method Details
#close ⇒ Object
23 24 25 26 |
# File 'lib/riemann/client/udp.rb', line 23 def close @socket.close if connected? @socket = nil end |
#connected? ⇒ Boolean
28 29 30 |
# File 'lib/riemann/client/udp.rb', line 28 def connected? @socket && !@socket.closed? end |
#read_message(_socket) ⇒ Object
Read a message from a stream
33 34 35 |
# File 'lib/riemann/client/udp.rb', line 33 def (_socket) raise Unsupported end |
#send_maybe_recv(message) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/riemann/client/udp.rb', line 41 def send_maybe_recv() encoded_string = .encode.to_s raise TooBig unless encoded_string.length < @max_size socket.send(encoded_string, 0, @host, @port) nil end |
#send_recv(_message) ⇒ Object
37 38 39 |
# File 'lib/riemann/client/udp.rb', line 37 def send_recv() raise Unsupported end |
#socket ⇒ Object
17 18 19 20 21 |
# File 'lib/riemann/client/udp.rb', line 17 def socket return @socket if connected? @socket = UDPSocket.new end |