class FFWD::TCP::PlainConnect

Constants

INITIAL_TIMEOUT

Attributes

log[R]

Public Class Methods

new(core, log, connection, config) click to toggle source
# File lib/ffwd/protocol/tcp/plain_connect.rb, line 45
def initialize core, log, connection, config
  @log = log
  @c = connection

  ignored = config[:ignored]

  subs = []

  core.starting do
    @c.connect

    unless ignored.include? :events
      subs << core.output.event_subscribe{|e| handle_event e}
    end

    unless ignored.include? :metrics
      subs << core.output.metric_subscribe{|e| handle_metric e}
    end
  end

  core.stopping do
    @c.disconnect
    subs.each(&:unsubscribe).clear
  end
end
prepare(opts) click to toggle source
# File lib/ffwd/protocol/tcp/plain_connect.rb, line 24
def self.prepare opts
  opts
end

Public Instance Methods

handle_event(event) click to toggle source
# File lib/ffwd/protocol/tcp/plain_connect.rb, line 71
def handle_event event
  return increment :dropped_events, 1 unless @c.writable?
  @c.send_event event
  increment :sent_events, 1
rescue => e
  log.error "Failed to handle event", e
  log.error "The following event could not be flushed: #{event.to_h}"
  increment :failed_events, 1
end
handle_metric(metric) click to toggle source
# File lib/ffwd/protocol/tcp/plain_connect.rb, line 81
def handle_metric metric
  return increment :dropped_metrics, 1 unless @c.writable?
  @c.send_metric metric
  increment :sent_metrics, 1
rescue => e
  log.error "Failed to handle metric", e
  log.error "The following metric could not be flushed: #{metric.to_h}"
  increment :failed_metrics, 1
end
reporter_meta() click to toggle source
# File lib/ffwd/protocol/tcp/plain_connect.rb, line 39
def reporter_meta
  @c.reporter_meta
end