Class: Synapse::ServiceWatcher::ZookeeperWatcher
- Inherits:
-
BaseWatcher
- Object
- BaseWatcher
- Synapse::ServiceWatcher::ZookeeperWatcher
- Defined in:
- lib/synapse/service_watcher/zookeeper.rb
Direct Known Subclasses
Constant Summary collapse
- NUMBERS_RE =
/^\d+$/- @@zk_pool =
{}
- @@zk_pool_count =
{}
- @@zk_pool_lock =
Mutex.new
Constants inherited from BaseWatcher
BaseWatcher::LEADER_WARN_INTERVAL
Instance Attribute Summary
Attributes inherited from BaseWatcher
Instance Method Summary collapse
-
#initialize(opts = {}, synapse) ⇒ ZookeeperWatcher
constructor
A new instance of ZookeeperWatcher.
- #ping? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Methods inherited from BaseWatcher
Methods included from Logging
configure_logger_for, #log, logger_for
Constructor Details
#initialize(opts = {}, synapse) ⇒ ZookeeperWatcher
Returns a new instance of ZookeeperWatcher.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/synapse/service_watcher/zookeeper.rb', line 14 def initialize(opts={}, synapse) super(opts, synapse) # Alternative deserialization support. By default we use nerve # deserialization, but we also support serverset registries @decode_method = self.method(:nerve_decode) if @discovery['decode'] valid_methods = ['nerve', 'serverset'] decode_method = @discovery['decode']['method'] unless decode_method && valid_methods.include?(decode_method) raise ArgumentError, "missing or invalid decode method #{decode_method}" end if decode_method == 'serverset' @decode_method = self.method(:serverset_decode) end end end |
Instance Method Details
#ping? ⇒ Boolean
47 48 49 50 51 |
# File 'lib/synapse/service_watcher/zookeeper.rb', line 47 def ping? # @zk being nil implies no session *or* a lost session, do not remove # the check on @zk being truthy @zk && @zk.connected? end |
#start ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/synapse/service_watcher/zookeeper.rb', line 32 def start @zk_hosts = @discovery['hosts'].sort.join(',') @watcher = nil @zk = nil log.info "synapse: starting ZK watcher #{@name} @ hosts: #{@zk_hosts}, path: #{@discovery['path']}" zk_connect end |
#stop ⇒ Object
42 43 44 45 |
# File 'lib/synapse/service_watcher/zookeeper.rb', line 42 def stop log.warn "synapse: zookeeper watcher exiting" zk_cleanup end |