Module: ZkService

Included in:
Publisher, Vendor
Defined in:
lib/zk_service.rb,
lib/zk_service/version.rb

Defined Under Namespace

Modules: Publisher Classes: InvalidZookeeperConfig, NoAvailableZookeeper, Vendor, ZkServicePublisherError, ZkServiceVendorError

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.check_namespaces(zookeeper_namespace) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/zk_service.rb', line 17

def self.check_namespaces(zookeeper_namespace)
  zookeeper_namespace ||= "/"
  if zookeeper_namespace && !zookeeper_namespace.start_with?("/")
    raise InvalidZookeeperConfig.new("Zookeeper namespace should start with '/'")
  end
  zookeeper_namespace
end

.configure(h, p) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/zk_service.rb', line 8

def self.configure( h, p )
  #config = YAML.env_config( "zookeeper" )
  #hostkey  = config[:host] || "localhost"
  #port = config[:port]     || "2181"
  hostkey, port = h, p
  zookeeper_server_addresses = []
  zookeeper_server_addresses << "#{h}:#{p}"
end

.create_connection(zookeeper_server_addresses) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zk_service.rb', line 25

def self.create_connection(zookeeper_server_addresses)
  begin
    tryable = zookeeper_server_addresses.choice
    Zookeeper.new( tryable )
    # TODO: do not resque Exception or explain, why that is necessary
    rescue Exception => e
      zookeeper_server_addresses.shift
      if zookeeper_server_addresses.empty?
        raise NoAvailableZookeeper.new         # We're out of options.
      else
        create_connection(zookeeper_server_addresses) # We recurse to try again.
      end
  end
end