Class: FFWD::UDP::Connect
- Inherits:
-
Object
- Object
- FFWD::UDP::Connect
- Includes:
- Reporter
- Defined in:
- lib/ffwd/protocol/udp/connect.rb
Constant Summary collapse
- RESOLVE_TIMEOUT =
10
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#reporter_meta ⇒ Object
readonly
Returns the value of attribute reporter_meta.
Class Method Summary collapse
Instance Method Summary collapse
- #connection_completed ⇒ Object
-
#initialize(core, log, host, port, handler, config) ⇒ Connect
constructor
A new instance of Connect.
- #send_data(data) ⇒ Object
- #unbind ⇒ Object
Methods included from Reporter
build_meta, included, #increment, map_meta, #report!, #reporter_data
Constructor Details
#initialize(core, log, host, port, handler, config) ⇒ Connect
40 41 42 43 44 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ffwd/protocol/udp/connect.rb', line 40 def initialize core, log, host, port, handler, config @log = log @host = host @port = port @handler = handler ignored = config[:ignored] @bind_host = "0.0.0.0" @host_ip = nil @c = nil @peer = "#{host}:#{port}" = {:component => @handler.plugin_type, :peer => @peer} info = "udp://#{@peer}" @subs = [] r = FFWD.retry :timeout => RESOLVE_TIMEOUT do |a| unless @host_ip @host_ip = resolve_ip @host raise "Could not resolve: #{@host}" if @host_ip.nil? end @c = EM.open_datagram_socket @bind_host, nil, @handler, self, config unless ignored.include? :events @subs << core.output.event_subscribe{|e| handle_event e} end unless ignored.include? :metrics @subs << core.output.metric_subscribe{|m| handle_metric m} end log.info "Connect to #{info} (attempt #{a})" log.info " config: #{config.inspect}" end r.error do |a, t, e| log.warning "Connect to #{info} failed, retry ##{a} in #{t}s: #{e}" end r.depend_on core core.stopping do if @c @c.close @c = nil end @subs.each(&:unsubscribe).clear end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
30 31 32 |
# File 'lib/ffwd/protocol/udp/connect.rb', line 30 def config @config end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
30 31 32 |
# File 'lib/ffwd/protocol/udp/connect.rb', line 30 def log @log end |
#reporter_meta ⇒ Object (readonly)
Returns the value of attribute reporter_meta.
30 31 32 |
# File 'lib/ffwd/protocol/udp/connect.rb', line 30 def end |
Class Method Details
.prepare(config) ⇒ Object
25 26 27 28 |
# File 'lib/ffwd/protocol/udp/connect.rb', line 25 def self.prepare config config[:ignored] = (config[:ignored] || []).map{|v| Utils.check_ignored v} config end |
Instance Method Details
#connection_completed ⇒ Object
100 |
# File 'lib/ffwd/protocol/udp/connect.rb', line 100 def connection_completed; end |
#send_data(data) ⇒ Object
94 95 96 97 |
# File 'lib/ffwd/protocol/udp/connect.rb', line 94 def send_data data return unless @c @c.send_datagram data, @host_ip, @port end |
#unbind ⇒ Object
99 |
# File 'lib/ffwd/protocol/udp/connect.rb', line 99 def unbind; end |