Class: Hermann::Discovery::Zookeeper::CuratorImpl

Inherits:
Object
  • Object
show all
Defined in:
lib/hermann/discovery/zookeeper.rb

Overview

The CuratorImpl is an implementation of simple broker discovery using Apache Curator libraries, if they are made available on the classpath for the process running Hermann::Discovery::Zookeeper.

For a number of reasons this is preferred over the ‘zk` gem, namely being a much more simple and mature Zookeeper client interface

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zks) ⇒ CuratorImpl

Returns a new instance of CuratorImpl.



130
131
132
133
# File 'lib/hermann/discovery/zookeeper.rb', line 130

def initialize(zks)
  retry_policy = Java::OrgApacheCuratorRetry::ExponentialBackoffRetry.new(1000, 3)
  @curator = Java::OrgApacheCuratorFramework::CuratorFrameworkFactory.newClient(zks, retry_policy)
end

Class Method Details

.usable?Boolean

Returns:

  • (Boolean)


121
122
123
124
125
126
127
128
# File 'lib/hermann/discovery/zookeeper.rb', line 121

def self.usable?
  begin
    Java::OrgApacheCuratorFramework::CuratorFrameworkFactory
    return true
  rescue NameError
    return false
  end
end

Instance Method Details

#brokers(timeout = 0) ⇒ Object

Timeout is discarded, only later versions of Curator support blockUntilConnected which would take the timeout variable



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/hermann/discovery/zookeeper.rb', line 137

def brokers(timeout=0)
  unless @curator.started?
    @curator.start
  end

  brokers = []
  @curator.children.for_path(BROKERS_PATH).each do |id|
    path = "#{BROKERS_PATH}/#{id}"
    brokers << @curator.data.for_path(path).to_s
  end
  return brokers
end