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



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

def initialize_zk
  Timeout::timeout(timeout_duration) do
    self.zk = ZK.new zk_url, chroot: '/cellect'
  end
  setup
  self.state = :ready
end

#ready?Boolean

Returns:

  • (Boolean)


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

def ready?
  state == :ready
end