Class: ActiveRecord::ConnectionAdapters::PoolConfig

Inherits:
Object
  • Object
show all
Includes:
Mutex_m
Defined in:
activerecord/lib/active_record/connection_adapters/pool_config.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_class, db_config, role, shard) ⇒ PoolConfig

Returns a new instance of PoolConfig.



20
21
22
23
24
25
26
27
28
# File 'activerecord/lib/active_record/connection_adapters/pool_config.rb', line 20

def initialize(connection_class, db_config, role, shard)
  super()
  @connection_class = connection_class
  @db_config = db_config
  @role = role
  @shard = shard
  @pool = nil
  INSTANCES[self] = self
end

Instance Attribute Details

#connection_classObject

Returns the value of attribute connection_class



9
10
11
# File 'activerecord/lib/active_record/connection_adapters/pool_config.rb', line 9

def connection_class
  @connection_class
end

#db_configObject (readonly)

Returns the value of attribute db_config



8
9
10
# File 'activerecord/lib/active_record/connection_adapters/pool_config.rb', line 8

def db_config
  @db_config
end

#roleObject (readonly)

Returns the value of attribute role



8
9
10
# File 'activerecord/lib/active_record/connection_adapters/pool_config.rb', line 8

def role
  @role
end

#schema_cacheObject

Returns the value of attribute schema_cache



9
10
11
# File 'activerecord/lib/active_record/connection_adapters/pool_config.rb', line 9

def schema_cache
  @schema_cache
end

#shardObject (readonly)

Returns the value of attribute shard



8
9
10
# File 'activerecord/lib/active_record/connection_adapters/pool_config.rb', line 8

def shard
  @shard
end

Class Method Details

.discard_pools!Object



15
16
17
# File 'activerecord/lib/active_record/connection_adapters/pool_config.rb', line 15

def discard_pools!
  INSTANCES.each_key(&:discard_pool!)
end

Instance Method Details

#connection_nameObject



30
31
32
33
34
35
36
# File 'activerecord/lib/active_record/connection_adapters/pool_config.rb', line 30

def connection_name
  if connection_class.primary_class?
    "ActiveRecord::Base"
  else
    connection_class.name
  end
end

#discard_pool!Object



59
60
61
62
63
64
65
66
67
68
# File 'activerecord/lib/active_record/connection_adapters/pool_config.rb', line 59

def discard_pool!
  return unless @pool

  synchronize do
    return unless @pool

    @pool.discard!
    @pool = nil
  end
end

#disconnect!Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'activerecord/lib/active_record/connection_adapters/pool_config.rb', line 38

def disconnect!
  ActiveSupport::ForkTracker.check!

  return unless @pool

  synchronize do
    return unless @pool

    @pool.automatic_reconnect = false
    @pool.disconnect!
  end

  nil
end

#poolObject



53
54
55
56
57
# File 'activerecord/lib/active_record/connection_adapters/pool_config.rb', line 53

def pool
  ActiveSupport::ForkTracker.check!

  @pool || synchronize { @pool ||= ConnectionAdapters::ConnectionPool.new(self) }
end