Class: Metriksd::UdpServer
- Inherits:
-
Object
- Object
- Metriksd::UdpServer
- Defined in:
- lib/metriksd/udp_server.rb
Defined Under Namespace
Classes: Handler
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#initialize(registry, options = {}) ⇒ UdpServer
constructor
A new instance of UdpServer.
- #join ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #unmarshal(data) ⇒ Object
Constructor Details
#initialize(registry, options = {}) ⇒ UdpServer
Returns a new instance of UdpServer.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/metriksd/udp_server.rb', line 24 def initialize(registry, = {}) missing_keys = %w(port) - .keys.map(&:to_s) unless missing_keys.empty? raise ArgumentError, "Missing required options: #{missing_keys * ', '}" end @registry = registry @port = [:port] @host = [:host] || '0.0.0.0' @logger = [:logger] || Logger.new(STDERR) @recvbuf = [:recvbuf] || 1024 * 1024 @unpacker = MessagePack::Unpacker.new end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
22 23 24 |
# File 'lib/metriksd/udp_server.rb', line 22 def host @host end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
22 23 24 |
# File 'lib/metriksd/udp_server.rb', line 22 def logger @logger end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
22 23 24 |
# File 'lib/metriksd/udp_server.rb', line 22 def port @port end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
22 23 24 |
# File 'lib/metriksd/udp_server.rb', line 22 def registry @registry end |
Instance Method Details
#join ⇒ Object
65 66 67 68 69 |
# File 'lib/metriksd/udp_server.rb', line 65 def join if EventMachine.reactor_thread? EventMachine.reactor_thread.join end end |
#start ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/metriksd/udp_server.rb', line 39 def start unless EventMachine.reactor_running? Thread.new do EventMachine.epoll = true if EventMachine.epoll? EventMachine.kqueue = true if EventMachine.kqueue? EventMachine.run end end EventMachine.next_tick do handler = proc do |data| begin unmarshal(data) rescue => e logger.error "Error in metriks server: #{e.class}: #{e.}\n\t#{e.backtrace.join("\n\t")}" end end EventMachine.open_datagram_socket(@host, @port, Handler, handler) end end |
#stop ⇒ Object
61 62 63 |
# File 'lib/metriksd/udp_server.rb', line 61 def stop EventMachine.stop end |