Class: ProxyMgr::Haproxy::SocketManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

disable!, #logger, logger

Constructor Details

#initializeSocketManager

Returns a new instance of SocketManager.



11
12
13
# File 'lib/proxymgr/haproxy/socket_manager.rb', line 11

def initialize
  @sockets = {}
end

Instance Attribute Details

#socketsObject (readonly)

Returns the value of attribute sockets.



9
10
11
# File 'lib/proxymgr/haproxy/socket_manager.rb', line 9

def sockets
  @sockets
end

Instance Method Details

#shutdownObject



15
16
17
18
19
# File 'lib/proxymgr/haproxy/socket_manager.rb', line 15

def shutdown
  @sockets.each do |_port, socket|
    socket.close
  end
end

#update(backends) ⇒ Object



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

def update(backends)
  fds = backends.each_with_object({}) do |(name, backend), mapping|
    socket = for_port(backend.port)
    mapping[backend.port] = socket.fileno if socket
  end

  (@sockets.keys - fds.keys).each do |port|
    @sockets.delete(port).close
  end

  fds
end