Class: Cellect::NodeSet

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/cellect/node_set.rb

Direct Known Subclasses

Server::NodeSet

Constant Summary collapse

ConnectionError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zk_url = nil) ⇒ NodeSet

Sets up the node set and starts connecting to ZooKeeper



11
12
13
14
15
# File 'lib/cellect/node_set.rb', line 11

def initialize(zk_url = nil)
  @zk_url = zk_url
  self.state = :initializing
  after(0.001){ async.initialize_zk } # don't block waiting for ZK to connect
end

Instance Attribute Details

#stateObject

Returns the value of attribute state.



8
9
10
# File 'lib/cellect/node_set.rb', line 8

def state
  @state
end

#zkObject

Returns the value of attribute zk.



8
9
10
# File 'lib/cellect/node_set.rb', line 8

def zk
  @zk
end

Instance Method Details

#initialize_zkObject

Connect to ZooKeeper, setup this node, and change state

Raises:



18
19
20
21
22
23
24
25
# File 'lib/cellect/node_set.rb', line 18

def initialize_zk
  # don't let ZK hang the thread, timeout and check connection status
  zk = ZK::Client.new zk_url, timeout: 0.5, chroot: '/cellect'
  raise ConnectionError.new("Can't connect to ZK server.") unless zk.connected?
  self.zk = zk
  setup
  self.state = :ready
end

#ready?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/cellect/node_set.rb', line 27

def ready?
  state == :ready
end