Class: FnordMetric::FyrehoseAcceptor
- Inherits:
-
Object
- Object
- FnordMetric::FyrehoseAcceptor
- Defined in:
- lib/fnordmetric/acceptors/fyrehose_acceptor.rb
Class Method Summary collapse
Instance Method Summary collapse
- #api ⇒ Object
- #events ⇒ Object
-
#initialize(opts) ⇒ FyrehoseAcceptor
constructor
A new instance of FyrehoseAcceptor.
- #push_next_event ⇒ Object
Constructor Details
#initialize(opts) ⇒ FyrehoseAcceptor
Returns a new instance of FyrehoseAcceptor.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fnordmetric/acceptors/fyrehose_acceptor.rb', line 10 def initialize(opts) reactor = EM.connect(opts[:host], opts[:port], Fyrehose::Reactor) reactor. do |channel, data| event = JSON.parse(data) event["_type"] ||= channel events << event push_next_event end opts[:channels].each do |channel| reactor.subscribe(channel) end end |
Class Method Details
.outboud? ⇒ Boolean
39 40 41 |
# File 'lib/fnordmetric/acceptors/fyrehose_acceptor.rb', line 39 def self.outboud? true end |
.start(opts) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/fnordmetric/acceptors/fyrehose_acceptor.rb', line 3 def self.start(opts) require "fyrehose" require "fyrehose/reactor" new(opts) end |
Instance Method Details
#api ⇒ Object
35 36 37 |
# File 'lib/fnordmetric/acceptors/fyrehose_acceptor.rb', line 35 def api @api ||= FnordMetric::API.new(FnordMetric.) end |
#events ⇒ Object
31 32 33 |
# File 'lib/fnordmetric/acceptors/fyrehose_acceptor.rb', line 31 def events @events ||= [] end |
#push_next_event ⇒ Object
25 26 27 28 29 |
# File 'lib/fnordmetric/acceptors/fyrehose_acceptor.rb', line 25 def push_next_event return true if events.empty? api.event(@events.pop) EM.next_tick(&method(:push_next_event)) end |