Class: Familia::Connection::ScopedConnectionHandler
- Inherits:
-
Object
- Object
- Familia::Connection::ScopedConnectionHandler
- Includes:
- Handler
- Defined in:
- lib/familia/connection/handlers.rb
Overview
Serves the connection a Scope holds for the requested URI while the current fiber is inside #with_connection_scope.
One client per distinct connection configuration, created on first use and closed when the scope exits. Outside a scope, after the scope is released, and in a thread or fiber that did not open the scope, the handler declines and resolution continues down the chain.
Placed after ProviderConnectionHandler and CachedConnectionHandler: a scope governs only the lookups that would otherwise reach CreateConnectionHandler and mint an unowned client. A connection provider and a class-level @dbclient keep serving inside a scope.
Transactions and pipelines are allowed; they run on the scope's client for that URI, so WATCH, MULTI/EXEC and pipelined commands share one socket for the whole block.
Instance Method Summary collapse
- #handle(uri) ⇒ Object
-
#initialize(familia_module = nil) ⇒ ScopedConnectionHandler
constructor
A new instance of ScopedConnectionHandler.
Constructor Details
#initialize(familia_module = nil) ⇒ ScopedConnectionHandler
Returns a new instance of ScopedConnectionHandler.
301 302 303 |
# File 'lib/familia/connection/handlers.rb', line 301 def initialize(familia_module = nil) @familia_module = familia_module || Familia end |
Instance Method Details
#handle(uri) ⇒ Object
305 306 307 308 309 310 311 312 313 |
# File 'lib/familia/connection/handlers.rb', line 305 def handle(uri) scope = Familia::Connection::Scope.current return nil unless scope parsed_uri = @familia_module.normalize_uri(uri) client = scope.client(parsed_uri) Familia.trace :DBCLIENT_SCOPE, nil, "Using scoped connection for #{parsed_uri.serverid}" client end |