Class: FnordMetric::FyrehoseAcceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/fnordmetric/acceptors/fyrehose_acceptor.rb

Class Method Summary collapse

Instance Method Summary collapse

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.on_message 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

Returns:

  • (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

#apiObject



35
36
37
# File 'lib/fnordmetric/acceptors/fyrehose_acceptor.rb', line 35

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

#eventsObject



31
32
33
# File 'lib/fnordmetric/acceptors/fyrehose_acceptor.rb', line 31

def events
  @events ||= []
end

#push_next_eventObject



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