Class: ZK::Pool::Simple

Inherits:
Bounded show all
Defined in:
lib/z_k/pool.rb

Overview

create a connection pool useful for multithreaded applications

Will spin up number_of_connections at creation time and remain fixed at that number for the life of the pool.

Example

pool = ZK::Pool::Simple.new("localhost:2181", 10)
pool.checkout do |zk|
  zk.create("/mynew_path")
end

Constant Summary

Constants inherited from Bounded

Bounded::DEFAULT_OPTIONS

Instance Attribute Summary

Attributes inherited from Base

#connections

Instance Method Summary collapse

Methods inherited from Bounded

#add_connection!, #available_size, #checkin, #checkout, #count_waiters, #create_connection, #handle_checkin_on_connection, #populate_pool!, #size

Methods inherited from Base

#assert_open!, #close_all!, #closed?, #closing?, #force_close!, #forced?, #locker, #method_missing, #open?, #pool_state, #size, #synchronize, #with_connection, #with_lock

Constructor Details

#initialize(host, number_of_connections = 10, opts = {}) ⇒ Object

initialize a connection pool using the same optons as ZK.new

Parameters:

  • String

    host the same arguments as ZK.new

  • Integer

    number_of_connections the number of connections to put in the pool

  • optional

    Hash opts Options to pass on to each connection



288
289
290
291
292
293
# File 'lib/z_k/pool.rb', line 288

def initialize(host, number_of_connections=10, opts = {})
  opts = opts.dup
  opts[:max_clients] = opts[:min_clients] = number_of_connections.to_i

  super(host, opts)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ZK::Pool::Base