Class: FFWD::TCP::PlainConnect

Inherits:
Object
  • Object
show all
Includes:
Reporter
Defined in:
lib/ffwd/protocol/tcp/plain_connect.rb

Constant Summary collapse

INITIAL_TIMEOUT =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Reporter

build_meta, included, #increment, map_meta, #report!, #reporter_data

Constructor Details

#initialize(core, log, connection, config) ⇒ PlainConnect

Returns a new instance of PlainConnect.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



22
23
24
# File 'lib/ffwd/protocol/tcp/plain_connect.rb', line 22

def log
  @log
end

Class Method Details

.prepare(opts) ⇒ Object



24
25
26
# File 'lib/ffwd/protocol/tcp/plain_connect.rb', line 24

def self.prepare opts
  opts
end

Instance Method Details

#handle_event(event) ⇒ Object



71
72
73
74
75
76
77
78
79
# 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) ⇒ Object



81
82
83
84
85
86
87
88
89
# 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_metaObject



39
40
41
# File 'lib/ffwd/protocol/tcp/plain_connect.rb', line 39

def reporter_meta
  @c.reporter_meta
end