Class: Synapse::ZookeeperDnsWatcher

Inherits:
BaseWatcher show all
Defined in:
lib/synapse/service_watcher/zookeeper_dns.rb

Defined Under Namespace

Modules: Messages Classes: Dns, Zookeeper

Constant Summary

Constants inherited from BaseWatcher

BaseWatcher::LEADER_WARN_INTERVAL

Instance Attribute Summary

Attributes inherited from BaseWatcher

#haproxy, #name

Instance Method Summary collapse

Methods inherited from BaseWatcher

#initialize

Methods included from Logging

configure_logger_for, #log, logger_for

Constructor Details

This class inherits a constructor from Synapse::BaseWatcher

Instance Method Details

#backendsObject


185
186
187
# File 'lib/synapse/service_watcher/zookeeper_dns.rb', line 185

def backends
  @dns.backends
end

#ping?Boolean


174
175
176
# File 'lib/synapse/service_watcher/zookeeper_dns.rb', line 174

def ping?
  @watcher.alive? && @dns.ping? && @zk.ping?
end

#startObject


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/synapse/service_watcher/zookeeper_dns.rb', line 130

def start
  dns_discovery_opts = @discovery.select do |k,_|
    k == 'nameserver'
  end

  zookeeper_discovery_opts = @discovery.select do |k,_|
    k == 'hosts' || k == 'path'
  end

  @check_interval = @discovery['check_interval'] || 30.0

  @message_queue = Queue.new

  @dns = Dns.new(
    mk_child_watcher_opts(dns_discovery_opts),
    @synapse,
    @message_queue
  )

  @zk = Zookeeper.new(
    mk_child_watcher_opts(zookeeper_discovery_opts),
    @synapse,
    @message_queue
  )

  @zk.start
  @dns.start

  @watcher = Thread.new do
    until @should_exit
      # Trigger a DNS resolve every @check_interval seconds
      sleep @check_interval

      # Only trigger the resolve if the queue is empty, every other message
      # on the queue would either cause a resolve or stop the watcher
      if @message_queue.empty?
        @message_queue.push(Messages::CHECK_INTERVAL_MESSAGE)
      end

    end
    log.info "synapse: zookeeper_dns watcher exited successfully"
  end
end

#stopObject


178
179
180
181
182
183
# File 'lib/synapse/service_watcher/zookeeper_dns.rb', line 178

def stop
  super

  @dns.stop
  @zk.stop
end