class Synapse::ZookeeperDnsWatcher::Dns

Attributes

discovery_servers[RW]

Overrides the discovery_servers method on the parent class

Public Class Methods

new(opts={}, synapse, message_queue) click to toggle source
Calls superclass method
# File lib/synapse/service_watcher/zookeeper_dns.rb, line 54
def initialize(opts={}, synapse, message_queue)
  @message_queue = message_queue

  super(opts, synapse)
end

Public Instance Methods

stop() click to toggle source
# File lib/synapse/service_watcher/zookeeper_dns.rb, line 60
def stop
  @message_queue.push(Messages::STOP_WATCHER_MESSAGE)
end
watch() click to toggle source
# File lib/synapse/service_watcher/zookeeper_dns.rb, line 64
def watch
  last_resolution = nil
  while true
    # Blocks on message queue, the message will be a signal to stop
    # watching, to check a new set of servers from ZK, or to re-resolve
    # the DNS (triggered every check_interval seconds)
    message = @message_queue.pop

    log.debug "synapse: received message #{message.inspect}"

    case message
    when Messages::StopWatcher
      break
    when Messages::NewServers
      self.discovery_servers = message.servers
    when Messages::CheckInterval
      # Proceed to re-resolve the DNS
    else
      raise Messages::InvalidMessageError,
        "Received unrecognized message: #{message.inspect}"
    end

    # Empty servers means we haven't heard back from ZK yet or ZK is
    # empty.  This should only occur if we don't get results from ZK
    # within check_interval seconds or if ZK is empty.
    if self.discovery_servers.nil? || self.discovery_servers.empty?
      log.warn "synapse: no backends for service #{@name}"
    else
      # Resolve DNS names with the nameserver
      current_resolution = resolve_servers
      unless last_resolution == current_resolution
        last_resolution = current_resolution
        configure_backends(last_resolution)
      end
    end
  end
end

Private Instance Methods

validate_discovery_opts() click to toggle source

Validation is skipped as it has already occurred in the parent watcher

# File lib/synapse/service_watcher/zookeeper_dns.rb, line 105
def validate_discovery_opts
end