Class | Sequel::ConnectionPool
In: | lib/sequel/connection_pool.rb
Parent: | Object

The base connection pool class, which all other connection pools are based on. This class is not instantiated directly, but subclasses should at the very least implement the following API:

initialize(Hash, &block) : | The `block` is used as the connection proc, which should accept a single symbol argument.
hold(Symbol, &block) : | Yield a connection object (obtained from calling the block passed to `initialize`) to the current block. For sharded connection pools, the Symbol passed is the shard/server to use.
disconnect(Symbol, &block) : | Disconnect the connection object. If a block is given, pass the connection option to it, otherwise use the `:disconnection_proc` option in the hash passed to initialize. For sharded connection pools, the Symbol passed is the shard/server to use.
servers : | An array of shard/server symbols for all shards/servers that this connection pool recognizes.
size : | an integer representing the total number of connections in the pool, or for the given shard/server if sharding is supported.

For sharded connection pools, the sharded API adds the following methods:

add_servers(Array of Symbols) : | start recognizing all shards/servers specified by the array of symbols.

- remove_servers(Array of Symbols) :: no longer recognize all shards/servers

                                          specified by the array of symbols.

### Methods

created_count new servers

### Classes and Modules

Module Sequel::ConnectionPool::ClassMethods

### Constants

DEFAULT_SERVER | = | :default |  | The default server to use
CONNECTION_POOL_MAP | = | {[true, false] => :single, [true, true] => :sharded_single, [false, false] => :threaded, [false, true] => :sharded_threaded} |  | A map of [single threaded, sharded] values to symbols or ConnectionPool subclasses.

### Attributes

after_connect | [RW] | The after_connect proc used for this pool. This is called with each new connection made, and is usually used to set custom per-connection settings.
disconnection_proc | [RW] | The disconnect_proc used for the pool. This is called with each connection that is disconnected, usually to clean up related resources.

### Public Class methods

new(opts={}, &block)

Instantiates a connection pool with the given options. The block is called with a single symbol (specifying the server/shard to use) every time a new connection is needed. The following options are respected for all connection pools:

:after_connect : | The proc called after each new connection is made, with the connection object, useful for customizations that you want to apply to all connections.
:disconnection_proc : | The proc called when removing connections from the pool, which is passed the connection to disconnect.

[Source]

        # File lib/sequel/connection_pool.rb, line 78
    78:   def initialize(opts={}, &block)
    79:     raise(Sequel::Error, "No connection proc specified") unless @connection_proc = block
    80:     @disconnection_proc = opts[:disconnection_proc]
    81:     @after_connect = opts[:after_connect]
    82:   end

### Public Instance methods

created_count(*args)

Alias for `size`, not aliased directly for ease of subclass implementation

[Source]

        # File lib/sequel/connection_pool.rb, line 85
    85:   def created_count(*args)
    86:     size(*args)
    87:   end

servers()

An array of symbols for all shards/servers, which is a single `:default` by default.

[Source]

        # File lib/sequel/connection_pool.rb, line 90
    90:   def servers
    91:     [DEFAULT_SERVER]
    92:   end

[Validate]