Class: Cellect::NodeSet

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

Direct Known Subclasses

Client::NodeSet

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
25
# File 'lib/cellect/node_set.rb', line 18

def initialize_zk
  # don't let ZK hang the thread, just retry connection on restart
  Timeout::timeout(5) do
    self.zk = ZK.new zk_url, chroot: '/cellect'
  end
  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