public abstract class AbstractRoutingConnectionFactory extends Object implements ConnectionFactory, InitializingBean
ConnectionFactory
implementation that routes
create()
calls to one of various target
factories
based on a lookup key.
The latter is typically (but not necessarily) determined from some
subscriber context.
Allows to configure a default ConnectionFactory
as fallback.
Calls to getMetadata()
are routed to the
default ConnectionFactory
if configured.
setTargetConnectionFactories(java.util.Map<?, ?>)
,
setDefaultTargetConnectionFactory(java.lang.Object)
,
determineCurrentLookupKey()
Constructor and Description |
---|
AbstractRoutingConnectionFactory() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by the containing
BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware , ApplicationContextAware etc. |
reactor.core.publisher.Mono<Connection> |
create() |
protected abstract reactor.core.publisher.Mono<Object> |
determineCurrentLookupKey()
Determine the current lookup key.
|
protected reactor.core.publisher.Mono<ConnectionFactory> |
determineTargetConnectionFactory()
Retrieve the current target
ConnectionFactory . |
ConnectionFactoryMetadata |
getMetadata() |
protected ConnectionFactory |
resolveSpecifiedConnectionFactory(Object connectionFactory)
Resolve the specified connection factory object into a
ConnectionFactory instance. |
protected Object |
resolveSpecifiedLookupKey(Object lookupKey)
Resolve the given lookup key object, as specified in the
targetConnectionFactories map,
into the actual lookup key to be used for matching with the
current lookup key . |
void |
setConnectionFactoryLookup(ConnectionFactoryLookup connectionFactoryLookup)
Set the
ConnectionFactoryLookup implementation to use for resolving
connection factory name Strings in the targetConnectionFactories map. |
void |
setDefaultTargetConnectionFactory(Object defaultTargetConnectionFactory)
Specify the default target
ConnectionFactory , if any. |
void |
setLenientFallback(boolean lenientFallback)
Specify whether to apply a lenient fallback to the default
ConnectionFactory
if no specific ConnectionFactory could be found for the current lookup key. |
void |
setTargetConnectionFactories(Map<?,?> targetConnectionFactories)
Specify the map of target
ConnectionFactories ,
with the lookup key as key. |
public void setTargetConnectionFactories(Map<?,?> targetConnectionFactories)
ConnectionFactories
,
with the lookup key as key. The mapped value can either be a corresponding
ConnectionFactory
instance or a connection factory name String (to be
resolved via a ConnectionFactoryLookup
).
The key can be of arbitrary type; this class implements the generic lookup
process only. The concrete key representation will be handled by
resolveSpecifiedLookupKey(Object)
and determineCurrentLookupKey()
.
public void setDefaultTargetConnectionFactory(Object defaultTargetConnectionFactory)
ConnectionFactory
, if any.
The mapped value can either be a corresponding ConnectionFactory
instance or a connection factory name String
(to be resolved via a
ConnectionFactoryLookup
).
This ConnectionFactory
will be used as target if none of the keyed
targetConnectionFactories
match the
current lookup key
.
public void setLenientFallback(boolean lenientFallback)
ConnectionFactory
if no specific ConnectionFactory
could be found for the current lookup key.
Default is true
, accepting lookup keys without a corresponding entry
in the target ConnectionFactory
map - simply falling back to the default
ConnectionFactory
in that case.
Switch this flag to false
if you would prefer the fallback to only
apply when no lookup key was emitted. Lookup keys without a ConnectionFactory
entry will then lead to an IllegalStateException
.
public void setConnectionFactoryLookup(ConnectionFactoryLookup connectionFactoryLookup)
ConnectionFactoryLookup
implementation to use for resolving
connection factory name Strings in the targetConnectionFactories
map.public void afterPropertiesSet()
InitializingBean
BeanFactory
after it has set all bean properties
and satisfied BeanFactoryAware
, ApplicationContextAware
etc.
This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
afterPropertiesSet
in interface InitializingBean
protected Object resolveSpecifiedLookupKey(Object lookupKey)
targetConnectionFactories
map,
into the actual lookup key to be used for matching with the
current lookup key
.
The default implementation simply returns the given key as-is.
lookupKey
- the lookup key object as specified by the userprotected ConnectionFactory resolveSpecifiedConnectionFactory(Object connectionFactory) throws IllegalArgumentException
ConnectionFactory
instance.
The default implementation handles ConnectionFactory
instances
and connection factory names (to be resolved via a
ConnectionFactoryLookup
).
connectionFactory
- the connection factory value object as specified in the
targetConnectionFactories
mapConnectionFactory
(never null
)IllegalArgumentException
- in case of an unsupported value typepublic reactor.core.publisher.Mono<Connection> create()
create
in interface ConnectionFactory
public ConnectionFactoryMetadata getMetadata()
getMetadata
in interface ConnectionFactory
protected reactor.core.publisher.Mono<ConnectionFactory> determineTargetConnectionFactory()
ConnectionFactory
. Determines the
current lookup key
, performs a lookup
in the targetConnectionFactories
map,
falls back to the specified default
target ConnectionFactory
if necessary.Mono
emitting the current ConnectionFactory
as
per determineCurrentLookupKey()
determineCurrentLookupKey()
protected abstract reactor.core.publisher.Mono<Object> determineCurrentLookupKey()
resolveSpecifiedLookupKey(java.lang.Object)
method.Mono
emitting the lookup key. May complete without emitting a value
if no lookup key available