Class: DruidConfig::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/druid_config/client.rb

Overview

Class to initialize the connection to Zookeeper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zookeeper, opts = {}) ⇒ Client

Initialize Zookeeper connection



11
12
13
14
15
16
# File 'lib/druid_config/client.rb', line 11

def initialize(zookeeper, opts = {})
  # Store it for future resets
  @zookeeper = zookeeper
  @opts = opts
  @zk = ZK.new(zookeeper, opts)
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



6
7
8
# File 'lib/druid_config/client.rb', line 6

def opts
  @opts
end

#zkObject (readonly)

Returns the value of attribute zk.



6
7
8
# File 'lib/druid_config/client.rb', line 6

def zk
  @zk
end

#zookeeperObject (readonly)

Returns the value of attribute zookeeper.



6
7
8
# File 'lib/druid_config/client.rb', line 6

def zookeeper
  @zookeeper
end

Instance Method Details

#close!Object

Close the client



43
44
45
# File 'lib/druid_config/client.rb', line 43

def close!
  zk.close!
end

#coordinatorObject

Get the URL of a coordinator.

This funciton can raise a DruidConfig::Exceptions::NotAvailableNodes exception indicating there aren’t any node to process this request



24
25
26
27
# File 'lib/druid_config/client.rb', line 24

def coordinator
  return zk.coordinator if zk.coordinator
  fail DruidConfig::Exceptions::NotAvailableNodes, 'coordinator'
end

#overlordObject

Get the URI of a overlord

This funciton can raise a DruidConfig::Exceptions::NotAvailableNodes exception indicating there aren’t any node to process this request



35
36
37
38
# File 'lib/druid_config/client.rb', line 35

def overlord
  return zk.overlord if zk.overlord
  fail DruidConfig::Exceptions::NotAvailableNodes, 'overlord'
end

#reset!Object

Reset the client



50
51
52
53
# File 'lib/druid_config/client.rb', line 50

def reset!
  close!
  @zk = ZK.new(@zookeeper, @opts)
end