Class: FnordMetric::UDPAcceptor

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/fnordmetric/acceptors/udp_acceptor.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.optsObject

Returns the value of attribute opts.



4
5
6
# File 'lib/fnordmetric/acceptors/udp_acceptor.rb', line 4

def opts
  @opts
end

Class Method Details

.start(opts) ⇒ Object



7
8
9
10
11
# File 'lib/fnordmetric/acceptors/udp_acceptor.rb', line 7

def self.start(opts)
  self.opts = opts

  EM.open_datagram_socket(*(opts[:listen] << self << opts))
end

Instance Method Details

#apiObject



33
34
35
# File 'lib/fnordmetric/acceptors/udp_acceptor.rb', line 33

def api
  @api ||= FnordMetric::API.new(FnordMetric.options)
end

#eventsObject



29
30
31
# File 'lib/fnordmetric/acceptors/udp_acceptor.rb', line 29

def events
  @events ||= []
end

#push_next_eventObject



18
19
20
21
22
23
# File 'lib/fnordmetric/acceptors/udp_acceptor.rb', line 18

def push_next_event
  return true if events.empty?
  ev = @events.pop
  api.event(ev)
  EM.next_tick(&method(:push_next_event))
end

#receive_data(event) ⇒ Object



13
14
15
16
# File 'lib/fnordmetric/acceptors/udp_acceptor.rb', line 13

def receive_data(event)
  events << event
  push_next_event
end

#unbindObject



25
26
27
# File 'lib/fnordmetric/acceptors/udp_acceptor.rb', line 25

def unbind
  #backend.hangup
end