Class: FFWD::TCP::Bind

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

Constant Summary collapse

DEFAULT_REBIND_TIMEOUT =

Default initial timeout when binding fails.

10

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, host, port, connection, config) ⇒ Bind

Returns a new instance of Bind.



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
# File 'lib/ffwd/protocol/tcp/bind.rb', line 43

def initialize core, log, host, port, connection, config
  @log = log
  @peer = "#{host}:#{port}"
  @reporter_meta = {:component => connection.plugin_type, :listen => @peer}

  @server = nil

  info = "tcp://#{@peer}"
  rebind_timeout = config[:rebind_timeout]

  r = FFWD.retry :timeout => rebind_timeout do |a|
    @server = EM.start_server host, port, connection, self, core, config

    log.info "Bind on #{info} (attempt #{a})"
    log.info "  config: #{config.inspect}"
  end

  r.error do |a, t, e|
    log.warning "Bind on #{info} failed, retry ##{a} in #{t}s: #{e}"
  end

  r.depend_on core

  core.stopping do
    if @server
      EM.stop_server @server
      @server = nil
    end

    log.info "Unbound #{info}"
  end
end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



41
42
43
# File 'lib/ffwd/protocol/tcp/bind.rb', line 41

def log
  @log
end

#reporter_metaObject (readonly)

Returns the value of attribute reporter_meta.



41
42
43
# File 'lib/ffwd/protocol/tcp/bind.rb', line 41

def reporter_meta
  @reporter_meta
end

Class Method Details

.prepare(opts) ⇒ Object



28
29
30
31
# File 'lib/ffwd/protocol/tcp/bind.rb', line 28

def self.prepare opts
  opts[:rebind_timeout] ||= DEFAULT_REBIND_TIMEOUT
  opts
end