Module: FiberedMysql2::FiberedDatabaseConnectionPool

Includes:
FiberedMonitorMixin
Defined in:
lib/fibered_mysql2/fibered_database_connection_pool.rb

Defined Under Namespace

Modules: Adapter_4_2, Adapter_5_2

Instance Method Summary collapse

Methods included from FiberedMonitorMixin

extend_object, #mon_check_owner, #mon_enter, #mon_exit, #mon_initialize, #mon_synchronize, #mon_try_enter, #new_cond

Instance Method Details

#connectionObject



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 251

def connection
  # this is correctly done double-checked locking
  # (ThreadSafe::Cache's lookups have volatile semantics)
  if (result = cached_connections[current_connection_id])
    result
  else
    synchronize do
      if (result = cached_connections[current_connection_id])
        result
      else
        cached_connections[current_connection_id] = checkout
      end
    end
  end
end

#initialize(connection_spec, *args, **keyword_args) ⇒ Object



240
241
242
243
244
245
246
247
248
249
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 240

def initialize(connection_spec, *args, **keyword_args)
  connection_spec.config[:reaping_frequency] and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
  connection_spec.config[:reaping_frequency] = nil # starting in Rails 5, this defaults to 60 if not explicitly set

  super(connection_spec, *args, **keyword_args)

  @reaper = nil # no need to keep a reference to this since it does nothing in this sub-class

  # note that @reserved_connections is a ThreadSafe::Cache which is overkill in a fibered world, but harmless
end

#reap_connectionsObject



267
268
269
270
271
272
273
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 267

def reap_connections
  cached_connections.values.each do |connection|
    unless connection.owner.alive?
      checkin(connection)
    end
  end
end