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_enter, #mon_exit, #mon_synchronize, #mon_try_enter, #new_cond

Instance Method Details

#connectionObject



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 185

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



174
175
176
177
178
179
180
181
182
183
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 174

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



201
202
203
204
205
206
207
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 201

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