Module: ZK

Defined in:
lib/z_k.rb,
lib/z_k/find.rb,
lib/z_k/pool.rb,
lib/z_k/client.rb,
lib/z_k/locker.rb,
lib/z_k/logging.rb,
lib/z_k/mongoid.rb,
lib/z_k/version.rb,
lib/z_k/election.rb,
lib/z_k/exceptions.rb,
lib/z_k/extensions.rb,
lib/z_k/threadpool.rb,
lib/z_k/client/base.rb,
lib/z_k/event_handler.rb,
lib/z_k/message_queue.rb,
lib/z_k/client/unixisms.rb,
lib/z_k/client/state_mixin.rb,
lib/z_k/client/conveniences.rb,
lib/z_k/event_handler_subscription.rb

Defined Under Namespace

Modules: Client, Election, Exceptions, Extensions, Find, Locker, Logging, Mongoid, Pool Classes: EventHandler, EventHandlerSubscription, MessageQueue, Threadpool

Constant Summary collapse

ZK_ROOT =
File.expand_path('../..', __FILE__)
KILL_TOKEN =

:nodoc:

:__ZK_kILL_tOkEn__
VERSION =
"0.7.1"

Class Method Summary collapse

Class Method Details

.chomp_sep(str) ⇒ Object (protected)



84
85
86
87
# File 'lib/z_k.rb', line 84

def self.chomp_sep(str)
  p = (p[0] == ?/ ) ? p[1..-1] : p
  p = (p[-1] == ?/) ? p[0..-2] : p
end

.join(*paths) ⇒ Object

Eventually this will implement proper File.join-like behavior, but only using the ‘/’ char for a separator. for right now, this simply delegates to File.join – like File.join but ignores $INPUT_RECORD_SEPARATOR (i.e. $/, which is platform dependent) and only uses the ‘/’ character



79
80
81
# File 'lib/z_k.rb', line 79

def self.join(*paths)
  File.join(*paths)
end

.loggerObject

The logger used by the ZK library. uses a Logger to /dev/null by default



33
34
35
# File 'lib/z_k.rb', line 33

def self.logger
  @logger ||= Logger.new('/dev/null')
end

.logger=(logger) ⇒ Object

Assign the Logger instance to be used by ZK



38
39
40
# File 'lib/z_k.rb', line 38

def self.logger=(logger)
  @logger = logger
end

.new(*args, &block) ⇒ Object

Create a new ZK::Client instance. If no arguments are given, the default config of ‘localhost:2181’ will be used. Otherwise all args will be passed to ZK::Client#new

if a block is given, it will be yielded the client before the connection is established, this is useful for registering connected-state handlers.



49
50
51
52
53
54
55
56
57
# File 'lib/z_k.rb', line 49

def self.new(*args, &block)
  # XXX: might need to do some param parsing here
 
  opts = args.pop if args.last.kind_of?(Hash)
  args = %w[localhost:2181] if args.empty?

  # ignore opts for now
  Client.new(*args, &block)
end

.new_pool(host, opts = {}) ⇒ Object

creates a new ZK::Pool::Bounded with the default options.



69
70
71
# File 'lib/z_k.rb', line 69

def self.new_pool(host, opts={})
  ZK::Pool::Bounded.new(host, opts)
end

.open(*args) ⇒ Object

Like new, yields a connection to the given block and closes it when the block returns



61
62
63
64
65
66
# File 'lib/z_k.rb', line 61

def self.open(*args)
  cnx = new(*args)
  yield cnx
ensure
  cnx.close! if cnx
end