class FnordMetric::TCPAcceptor
Public Class Methods
options(opts)
click to toggle source
# File lib/fnordmetric/acceptors/tcp_acceptor.rb, line 9 def self.options(opts) @@opts = opts end
start(opts)
click to toggle source
# File lib/fnordmetric/acceptors/tcp_acceptor.rb, line 4 def self.start(opts) @@opts = opts EM.start_server(*(opts[:listen] + [self])) end
Public Instance Methods
api()
click to toggle source
# File lib/fnordmetric/acceptors/tcp_acceptor.rb, line 54 def api @api ||= FnordMetric::API.new(FnordMetric.options) end
close_connection?()
click to toggle source
# File lib/fnordmetric/acceptors/tcp_acceptor.rb, line 38 def close_connection? #@backend.hangup unless @streaming || (@events_buffered!=0) end
next_event()
click to toggle source
# File lib/fnordmetric/acceptors/tcp_acceptor.rb, line 18 def next_event read_next_event push_next_event end
post_init()
click to toggle source
# File lib/fnordmetric/acceptors/tcp_acceptor.rb, line 42 def post_init @events_buffered = 0 @streaming = true @buffer = "" @events = [] end
push_next_event()
click to toggle source
# File lib/fnordmetric/acceptors/tcp_acceptor.rb, line 30 def push_next_event return true if @events.empty? @events_buffered -= 1 api.event(@events.pop) close_connection? EM.next_tick(&method(:push_next_event)) end
read_next_event()
click to toggle source
# File lib/fnordmetric/acceptors/tcp_acceptor.rb, line 23 def read_next_event while (event = @buffer.slice!(/^(.*)\n/)) @events_buffered += 1 @events << event end end
receive_data(chunk)
click to toggle source
# File lib/fnordmetric/acceptors/tcp_acceptor.rb, line 13 def receive_data(chunk) @buffer << chunk next_event end
unbind()
click to toggle source
# File lib/fnordmetric/acceptors/tcp_acceptor.rb, line 49 def unbind @streaming = false close_connection? end