Strategies are more open-ended than services, though a strategy managed here might very well also be a service. The strategy is any interface that has multiple, (possibly short) named implementations.
StrategySelector manages resolution of particular implementation by (possibly short) name via the
selectStrategyImplementor 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 org. 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".
Strategy implementations can be managed by registerStrategyImplementor and unRegisterStrategyImplementor.
Originally designed to help the OSGi use case, though no longer used there.
The service also exposes a general typing API via resolveStrategy and resolveDefaultableStrategy
which accept implementation references rather than implementation names, allowing for a multitude of interpretations
of said "implementation reference". See the docs for resolveDefaultableStrategy for details.
| Modifier and Type | Method and Description |
|---|---|
| public <T> Collection | Returns: The implementors. Should never returnnullRetrieve all of the registered implementors of the given strategy. |
| public < The type of the strategy. Used to make sure that the strategy and implementation are type
compatible. T> void | registerStrategyImplementor(Class<T>
The strategy contract. strategy, String The registration name name, Class<? extends T> The implementation Class implementation)Registers a named implementor of a particular strategy contract. |
| public < The type of the strategy. Used to make sure that the strategy and implementation are type
compatible. T> T | Returns: The strategy instanceThe type (interface) of the strategy to be resolved. strategy, Object The reference to the strategy for which we need to resolve an instance. strategyReference, T THe default value to use if strategyReference is null defaultValue)Resolve strategy instances. |
| public < The type of the strategy. Used to make sure that the strategy and implementation are type
compatible. T> T | Returns: The strategy instanceThe type (interface) of the strategy to be resolved. strategy, Object The reference to the strategy for which we need to resolve an instance. strategyReference, Callable<T> A strategy for resolving the default value strategyReference resolves to null. defaultResolver)Resolve strategy instances. |
| public < The type of the strategy. Used to make sure that the strategy and implementation are type
compatible. T> T | Returns: The strategy instanceThe type (interface) of the strategy to be resolved. strategy, @Nullable Object The reference to the strategy for which we need to resolve an instance. strategyReference)Resolve strategy instances. |
| public <T> T | resolveStrategy(Class<T> strategy, Object strategyReference, Callable<T> defaultResolver, StrategyCreator<T> creator)
|
| public <T> T | resolveStrategy(Class<T> strategy, Object strategyReference, T defaultValue, StrategyCreator<T> creator)
|
| public < The type of the strategy. Used to make sure that the strategy and implementation are type
compatible. T> Class | Returns: The named strategy implementation class.The type of strategy to be resolved. strategy, String The name of the strategy to locate; might be either a registered name or the implementation FQN. name)Locate the named strategy implementation. |
| public < The type of the strategy. Used to make sure that the strategy and implementation are type
compatible. T> void | unRegisterStrategyImplementor(Class<T>
The strategy contract. strategy, Class<? extends T> The implementation Class implementation)Un-registers a named implementor of a particular strategy contract. |
| getRegisteredStrategyImplementors | back to summary |
|---|---|
| public <T> Collection Retrieve all of the registered implementors of the given strategy. Useful to allow defaulting the choice to the single registered implementor when only one is registered
| |
| registerStrategyImplementor | back to summary |
|---|---|
| public <T> void registerStrategyImplementor(Class<T> strategy, String name, Class<? extends T> implementation) Registers a named implementor of a particular strategy contract. | |
| resolveDefaultableStrategy | back to summary |
|---|---|
| public <T> T resolveDefaultableStrategy(Class<T> strategy, Object strategyReference, T defaultValue) Resolve strategy instances. The incoming reference might be:
| |
| resolveDefaultableStrategy | back to summary |
|---|---|
| public <T> T resolveDefaultableStrategy(Class<T> strategy, Object strategyReference, Callable<T> defaultResolver) Resolve strategy instances. The incoming reference might be:
| |
| resolveStrategy | back to summary |
|---|---|
| public <T> T resolveStrategy(Class<T> strategy, @Nullable Object strategyReference) Resolve strategy instances. See discussion on
| |
| resolveStrategy | back to summary |
|---|---|
| public <T> T resolveStrategy(Class<T> strategy, Object strategyReference, Callable<T> defaultResolver, StrategyCreator<T> creator) | |
| resolveStrategy | back to summary |
|---|---|
| public <T> T resolveStrategy(Class<T> strategy, Object strategyReference, T defaultValue, StrategyCreator<T> creator) | |
| selectStrategyImplementor | back to summary |
|---|---|
| public <T> Class Locate the named strategy implementation.
| |
| unRegisterStrategyImplementor | back to summary |
|---|---|
| public <T> void unRegisterStrategyImplementor(Class<T> strategy, Class<? extends T> implementation) Un-registers a named implementor of a particular strategy contract. Un-registers all named registrations for the given strategy contract naming the given class. | |