public interface StrategySelector extends Service
selectStrategyImplementor(java.lang.Class<T>, java.lang.String)
method, which is the main contract here. As indicated in the docs of that
method the given name might be either a short registered name or the implementation FQN. As an example, consider
resolving the TransactionCoordinatorBuilder
implementation to use. To use the
JDBC-based TransactionCoordinatorBuilder the passed name might be either "jdbc"
or
"org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl"
(which is the FQN).
Strategy implementations can be managed by registerStrategyImplementor(java.lang.Class<T>, java.lang.String, java.lang.Class<? extends T>)
and
unRegisterStrategyImplementor(java.lang.Class<T>, java.lang.Class<? extends T>)
. Originally designed to help the OSGi use case, though no longer used there.
The service also exposes a general typing API via resolveStrategy(java.lang.Class<T>, java.lang.Object)
and resolveDefaultableStrategy(java.lang.Class<T>, java.lang.Object, T)
which accept implementation references rather than implementation names, allowing for a multitude of interpretations
of said "implementation reference". See the docs for resolveDefaultableStrategy(java.lang.Class<T>, java.lang.Object, T)
for details.Modifier and Type | Method and Description |
---|---|
<T> void |
registerStrategyImplementor(java.lang.Class<T> strategy,
java.lang.String name,
java.lang.Class<? extends T> implementation)
Registers a named implementor of a particular strategy contract.
|
<T> T |
resolveDefaultableStrategy(java.lang.Class<T> strategy,
java.lang.Object strategyReference,
java.util.concurrent.Callable<T> defaultResolver)
Resolve strategy instances.
|
<T> T |
resolveDefaultableStrategy(java.lang.Class<T> strategy,
java.lang.Object strategyReference,
T defaultValue)
Resolve strategy instances.
|
<T> T |
resolveStrategy(java.lang.Class<T> strategy,
java.lang.Object strategyReference)
Resolve strategy instances.
|
<T> T |
resolveStrategy(java.lang.Class<T> strategy,
java.lang.Object strategyReference,
java.util.concurrent.Callable<T> defaultResolver,
StrategyCreator<T> creator) |
<T> T |
resolveStrategy(java.lang.Class<T> strategy,
java.lang.Object strategyReference,
T defaultValue,
StrategyCreator<T> creator) |
<T> java.lang.Class<? extends T> |
selectStrategyImplementor(java.lang.Class<T> strategy,
java.lang.String name)
Locate the named strategy implementation.
|
<T> void |
unRegisterStrategyImplementor(java.lang.Class<T> strategy,
java.lang.Class<? extends T> implementation)
Un-registers a named implementor of a particular strategy contract.
|
<T> void registerStrategyImplementor(java.lang.Class<T> strategy, java.lang.String name, java.lang.Class<? extends T> implementation)
T
- The type of the strategy. Used to make sure that the strategy and implementation are type
compatible.strategy
- The strategy contract.name
- The registration nameimplementation
- The implementation Class<T> void unRegisterStrategyImplementor(java.lang.Class<T> strategy, java.lang.Class<? extends T> implementation)
T
- The type of the strategy. Used to make sure that the strategy and implementation are type
compatible.strategy
- The strategy contract.implementation
- The implementation Class<T> java.lang.Class<? extends T> selectStrategyImplementor(java.lang.Class<T> strategy, java.lang.String name)
T
- The type of the strategy. Used to make sure that the strategy and implementation are type
compatible.strategy
- The type of strategy to be resolved.name
- The name of the strategy to locate; might be either a registered name or the implementation FQN.<T> T resolveStrategy(java.lang.Class<T> strategy, java.lang.Object strategyReference)
resolveDefaultableStrategy(java.lang.Class<T>, java.lang.Object, T)
.
Only difference is that here, the implied default value is null
.T
- The type of the strategy. Used to make sure that the strategy and implementation are type
compatible.strategy
- The type (interface) of the strategy to be resolved.strategyReference
- The reference to the strategy for which we need to resolve an instance.<T> T resolveDefaultableStrategy(java.lang.Class<T> strategy, java.lang.Object strategyReference, T defaultValue)
null
- in which case defaultValue is returned.
Class
- an instance is created by calling
Class.newInstance()
(aka, the class's no-arg ctor).
Class
reference
is resolved, and then an instance is created by calling Class.newInstance()
T
- The type of the strategy. Used to make sure that the strategy and implementation are type
compatible.strategy
- The type (interface) of the strategy to be resolved.strategyReference
- The reference to the strategy for which we need to resolve an instance.defaultValue
- THe default value to use if strategyReference is null<T> T resolveDefaultableStrategy(java.lang.Class<T> strategy, java.lang.Object strategyReference, java.util.concurrent.Callable<T> defaultResolver)
null
- in which case defaultValue is returned.
Class
- an instance is created by calling
Class.newInstance()
(aka, the class's no-arg ctor).
Class
reference
is resolved, and then an instance is created by calling Class.newInstance()
T
- The type of the strategy. Used to make sure that the strategy and implementation are type
compatible.strategy
- The type (interface) of the strategy to be resolved.strategyReference
- The reference to the strategy for which we need to resolve an instance.defaultResolver
- A strategy for resolving the default value strategyReference resolves to null.<T> T resolveStrategy(java.lang.Class<T> strategy, java.lang.Object strategyReference, java.util.concurrent.Callable<T> defaultResolver, StrategyCreator<T> creator)
<T> T resolveStrategy(java.lang.Class<T> strategy, java.lang.Object strategyReference, T defaultValue, StrategyCreator<T> creator)
Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.