Sha256: ecfd7f60aaa970a2a4923260aa92878fe8d0844fa2dc6e9984454995715fe6e8

Contents?: true

Size: 849 Bytes

Versions: 1

Compression:

Stored size: 849 Bytes

Contents

require 'fresh_connection/abstract_connection_manager'
require 'fresh_connection/connection_factory'

module FreshConnection
  class ConnectionManager < AbstractConnectionManager
    def slave_connection
      synchronize do
        slave_connections[current_thread_id] ||= connection_factory.new_connection
      end
    end

    def put_aside!
      synchronize do
        if c = slave_connections.delete(current_thread_id)
          c.disconnect! rescue nil
        end
      end
    end

    def recovery(failure_connection, exception)
      do_recovery = slave_down_message?(exception.message)
      put_aside! if do_recovery
      do_recovery
    end

    private

    def slave_connections
      @slave_connections ||= {}
    end

    def connection_factory
      @connection_factory ||= ConnectionFactory.new(@slave_group)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fresh_connection-0.4.0 lib/fresh_connection/connection_manager.rb