Class: Synapse::ServiceWatcher::ZookeeperDnsWatcher::Dns
- Inherits:
-
DnsWatcher
- Object
- BaseWatcher
- DnsWatcher
- Synapse::ServiceWatcher::ZookeeperDnsWatcher::Dns
- Defined in:
- lib/synapse/service_watcher/zookeeper_dns.rb
Constant Summary
Constants inherited from BaseWatcher
BaseWatcher::LEADER_WARN_INTERVAL
Instance Attribute Summary collapse
-
#discovery_servers ⇒ Object
Overrides the discovery_servers method on the parent class.
Attributes inherited from BaseWatcher
Instance Method Summary collapse
-
#initialize(opts = {}, parent = nil, synapse, message_queue) ⇒ Dns
constructor
A new instance of Dns.
- #stop ⇒ Object
- #watch ⇒ Object
Methods inherited from DnsWatcher
Methods inherited from BaseWatcher
#backends, #config_for_generator, #haproxy, #ping?, #start
Methods included from Logging
configure_logger_for, #log, logger_for
Constructor Details
#initialize(opts = {}, parent = nil, synapse, message_queue) ⇒ Dns
Returns a new instance of Dns.
54 55 56 57 58 59 |
# File 'lib/synapse/service_watcher/zookeeper_dns.rb', line 54 def initialize(opts={}, parent=nil, synapse, ) @message_queue = @parent = parent super(opts, synapse) end |
Instance Attribute Details
#discovery_servers ⇒ Object
Overrides the discovery_servers method on the parent class
52 53 54 |
# File 'lib/synapse/service_watcher/zookeeper_dns.rb', line 52 def discovery_servers @discovery_servers end |
Instance Method Details
#stop ⇒ Object
61 62 63 |
# File 'lib/synapse/service_watcher/zookeeper_dns.rb', line 61 def stop @message_queue.push(Messages::STOP_WATCHER_MESSAGE) end |
#watch ⇒ Object
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/synapse/service_watcher/zookeeper_dns.rb', line 65 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_queue.pop log.debug "synapse: received message #{.inspect}" case when Messages::StopWatcher break when Messages::NewServers self.discovery_servers = .servers when Messages::CheckInterval # Proceed to re-resolve the DNS else raise Messages::InvalidMessageError, "Received unrecognized 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) # Propagate revision updates down to ZookeeperDnsWatcher, so # that stanza cache can work properly. @revision += 1 @parent.reconfigure! unless @parent.nil? end end end end |