Class: ProxyMgr::Sink

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/proxymgr/sink.rb

Instance Method Summary collapse

Methods included from Logging

disable!, #logger, logger

Constructor Details

#initialize(haproxy, opts = {}) ⇒ Sink

Returns a new instance of Sink.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/proxymgr/sink.rb', line 7

def initialize(haproxy, opts = {})
  @file            = opts[:haproxy_config_file] || '/tmp/haproxy.cfg'
  @default_timeout = opts[:default_timeout] || 2
  @max_timeout     = opts[:max_timeout] || 10
  @haproxy         = haproxy
  @timeout         = nil
  @thread          = nil
  @cv              = ConditionVariable.new
  @mutex           = Mutex.new
  @start_cv        = ConditionVariable.new
  @start_mutex     = Mutex.new
  @backends        = nil
  @haproxy.start
  start
end

Instance Method Details

#shutdownObject



34
35
36
37
38
# File 'lib/proxymgr/sink.rb', line 34

def shutdown
  @thread.kill
  @thread.join
  @haproxy.shutdown
end

#update_backends(backends) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/proxymgr/sink.rb', line 23

def update_backends(backends)
  @mutex.synchronize do
    @backends ||= {}
    backends.each do |name, watcher|
      next if watcher.servers.empty?
      @backends[name] = watcher
    end
    signal
  end
end