Class: Riemann::Client::UDP

Inherits:
Riemann::Client show all
Defined in:
lib/riemann/client/udp.rb

Constant Summary collapse

MAX_SIZE =
16384

Constants inherited from Riemann::Client

HOST, PORT, TIMEOUT

Instance Attribute Summary collapse

Attributes inherited from Riemann::Client

#tcp, #udp

Instance Method Summary collapse

Methods inherited from Riemann::Client

#<<, #[], #connect, #query, #timeout

Constructor Details

#initialize(opts = {}) ⇒ UDP

Returns a new instance of UDP.



8
9
10
11
12
# 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
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/riemann/client/udp.rb', line 6

def host
  @host
end

#max_sizeObject

Returns the value of attribute max_size.



6
7
8
# File 'lib/riemann/client/udp.rb', line 6

def max_size
  @max_size
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/riemann/client/udp.rb', line 6

def port
  @port
end

Instance Method Details

#closeObject



19
20
21
22
# File 'lib/riemann/client/udp.rb', line 19

def close
  @socket.close if connected?
  @socket = nil
end

#connected?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/riemann/client/udp.rb', line 24

def connected?
  @socket && !@socket.closed?
end

#read_message(s) ⇒ Object

Read a message from a stream

Raises:



29
30
31
# File 'lib/riemann/client/udp.rb', line 29

def read_message(s)
  raise Unsupported
end

#send_maybe_recv(message) ⇒ Object

Raises:



37
38
39
40
41
42
# File 'lib/riemann/client/udp.rb', line 37

def send_maybe_recv(message)
  encoded_string = message.encode.to_s
  raise TooBig unless encoded_string.length < @max_size
  socket.send(encoded_string, 0, @host, @port)
  nil
end

#send_recv(*a) ⇒ Object

Raises:



33
34
35
# File 'lib/riemann/client/udp.rb', line 33

def send_recv(*a)
  raise Unsupported
end

#socketObject



14
15
16
17
# File 'lib/riemann/client/udp.rb', line 14

def socket
  return @socket if connected?
  @socket = UDPSocket.new
end