Class: Sequel::ConnectionPool

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Defined in:
lib/sequel/connection_pool.rb

Overview

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(Database, Hash)

Initialize using the passed Sequel::Database object and options hash.

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)

Disconnect the connection object. 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.

max_size

an integer representing the maximum size of the connection pool, or the maximum size per 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.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

OPTS =
Sequel::OPTS
POOL_CLASS_MAP =
{
  :threaded => :ThreadedConnectionPool,
  :single => :SingleConnectionPool,
  :sharded_threaded => :ShardedThreadedConnectionPool,
  :sharded_single => :ShardedSingleConnectionPool,
  :timed_queue => :TimedQueueConnectionPool,
  :sharded_timed_queue => :ShardedTimedQueueConnectionPool,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

get_pool

Constructor Details

#initialize(db, opts = OPTS) ⇒ ConnectionPool

Instantiates a connection pool with the given Database and options.



111
112
113
114
115
116
117
# File 'lib/sequel/connection_pool.rb', line 111

def initialize(db, opts=OPTS) # SEQUEL6: Remove second argument, always use db.opts
  @db = db
  @use_old_connect_api = false # SEQUEL6: Remove
  @after_connect = opts[:after_connect] # SEQUEL6: Remove
  @connect_sqls = opts[:connect_sqls] # SEQUEL6: Remove
  @error_classes = db.send(:database_error_classes).dup.freeze
end

Instance Attribute Details

#after_connectObject

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. Deprecated.



88
89
90
# File 'lib/sequel/connection_pool.rb', line 88

def after_connect
  @after_connect
end

#connect_sqlsObject

An array of sql strings to execute on each new connection. Deprecated.



98
99
100
# File 'lib/sequel/connection_pool.rb', line 98

def connect_sqls
  @connect_sqls
end

#dbObject

The Sequel::Database object tied to this connection pool.



108
109
110
# File 'lib/sequel/connection_pool.rb', line 108

def db
  @db
end

Instance Method Details

#serversObject

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



120
121
122
# File 'lib/sequel/connection_pool.rb', line 120

def servers
  [:default]
end