@NoImplement public interface ConnectionManager
It works under the model of one owner (from now on the 'config'), has a one-to-one relationship with a
ConnectionProvider
. That relationship is declared through the bind(Object, ConnectionProvider)
method. That
relationship can be broken through the unbind(Object)
method.
Once the config-provider pair has been bound, connections can be obtained through the getConnection(Object)
method.
That method will yield a ConnectionHandler
which will hide the details of how the connection is actually being managed
while also avoiding the need to pass around config, provider or even this manager.
All implementations are required to be thread-safe
Modifier and Type | Method and Description |
---|---|
<C> void |
bind(Object config,
ConnectionProvider<C> connectionProvider)
Binds the given
config and connectionProvider so that the latter is used each time that the config is
supplied as an argument of the getConnection(Object) method. |
<C> ConnectionHandler<C> |
getConnection(Object config)
Obtains a
ConnectionHandler for a config which was previously bound through the
bind(Object, ConnectionProvider) method. |
boolean |
hasBinding(Object config) |
<C> ConnectionValidationResult |
testConnectivity(C connection,
ConnectionHandler<C> connectionHandler)
Validates the given
connection |
ConnectionValidationResult |
testConnectivity(ConfigurationInstance configurationInstance)
Tests connectivity for the given
configurationInstance . |
<C> ConnectionValidationResult |
testConnectivity(ConnectionProvider<C> connectionProvider)
Tests connectivity of the given
connectionProvider . |
void |
unbind(Object config)
Breaks the binding that was previously produced by invoking
bind(Object, ConnectionProvider) with the given
config on this instance. |
<C> void bind(Object config, ConnectionProvider<C> connectionProvider)
config
and connectionProvider
so that the latter is used each time that the config
is
supplied as an argument of the getConnection(Object)
method.
If a binding already exists for the config
then this one replaces the previous one. All connections produced by the
previous binding are closed.
C
- the generic type of the connections to be producedconfig
- the config that acts as the binding keyconnectionProvider
- the ConnectionProvider
that produces the connectionsboolean hasBinding(Object config)
config
- the config that acts as the binding keyconfig
is currently bound to a ConnectionProvider
void unbind(Object config)
bind(Object, ConnectionProvider)
with the given
config
on this
instance.
All connections produced as a result of the broken binding are closed once they're released. Once all connections created
with the previous ConnectionProvider
are closed, the stop and dispose lifecycle phases are applied over the provider
if necessary.
If no such binding exists no action is taken.
config
- a config for which a binding is presumed to exists<C> ConnectionHandler<C> getConnection(Object config) throws ConnectionException
ConnectionHandler
for a config
which was previously bound through the
bind(Object, ConnectionProvider)
method.
This method does not guarantee if the returned connections are always different, reused, pooled, etc. That depends on the
implementation of this interface and the implementation of the bounded ConnectionProvider
.
Once the requester has finished using the obtained connection, it is MANDATORY for it to invoke the
ConnectionHandler.release()
method on it.
C
- the generic type of the returned connectionconfig
- a config for which a binding has been established through bind(Object, ConnectionProvider)
ConnectionHandler
wrapping the produced connectionConnectionException
- if the conection could not be established or if no such binding exists for the config
<C> ConnectionValidationResult testConnectivity(ConnectionProvider<C> connectionProvider)
connectionProvider
.
The connectionProvider
is expected to be fully initialised and functional. However,
it is not required for it to have been registered through the bind(Object, ConnectionProvider)
method.
C
- the generic type of the connections produced by the connectionProvider
connectionProvider
- a ConnectionProvider
ConnectionValidationResult
<C> ConnectionValidationResult testConnectivity(C connection, ConnectionHandler<C> connectionHandler)
connection
The connection
has to have been obtained through the given connectionHandler
, and the handler
has to have been obtained through this
instance
C
- the generic type of the validated connectionconnection
- the connection to validateconnectionHandler
- the connection's handlerConnectionValidationResult
IllegalArgumentException
- if any of the preconditions are not metConnectionValidationResult testConnectivity(ConfigurationInstance configurationInstance) throws IllegalArgumentException
configurationInstance
.
The connectionProvider
is expected to be fully initialised and functional. It is not
required for the config wrapped by the configurationInstance
to have been registered
through the bind(Object, ConnectionProvider)
method. However, if it has been, then
the test will be performed using the resources allocated by such registration.
configurationInstance
- a ConfigurationInstance
ConnectionValidationResult
IllegalArgumentException
- if the configurationInstance
doesn't have an associated ConnectionProvider
Copyright © 2018. All rights reserved.