Class ProviderSelector
java.lang.Object
org.episteme.core.technical.algorithm.ProviderSelector
Context-aware provider selector.
Unlike AlgorithmManager.getProvider(Class) which uses static priority,
ProviderSelector uses AlgorithmProvider.score(OperationContext)
to pick the best provider for a specific operation.
OperationContext ctx = new OperationContext.Builder()
.dataSize(1_000_000)
.addHint(OperationContext.Hint.SPARSE)
.build();
LinearAlgebraProvider best = ProviderSelector.select(
LinearAlgebraProvider.class, ctx);
- Since:
- 1.2
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Method Summary
Modifier and TypeMethodDescriptionstatic <P extends AlgorithmProvider, R>
Rexecute(Class<P> providerClass, OperationContext context, Function<P, R> operation) Executes an operation using the best available provider, with automatic fallback.static <P extends AlgorithmProvider>
PSelects using static priority (delegates toAlgorithmManager).static <P extends AlgorithmProvider>
Pselect(Class<P> providerClass, OperationContext context) Selects the best provider for the given operation context.static <P extends AlgorithmProvider>
Pselect(Class<P> providerClass, OperationContext context, Predicate<P> filter) Selects the best provider for the given operation context, with an optional filter.
-
Method Details
-
select
public static <P extends AlgorithmProvider> P select(Class<P> providerClass, OperationContext context) Selects the best provider for the given operation context.Scores all available providers via
AlgorithmProvider.score(OperationContext)and returns the one with the highest score.- Type Parameters:
P- the provider type- Parameters:
providerClass- the interface class of the providercontext- the operation context describing data characteristics- Returns:
- the best-scoring available provider
- Throws:
NoSuchElementException- if no provider is available
-
select
public static <P extends AlgorithmProvider> P select(Class<P> providerClass, OperationContext context, Predicate<P> filter) Selects the best provider for the given operation context, with an optional filter. -
execute
public static <P extends AlgorithmProvider, R> R execute(Class<P> providerClass, OperationContext context, Function<P, R> operation) Executes an operation using the best available provider, with automatic fallback.Iterates through all available providers (sorted by score) and attempts the operation. If a provider fails, it logs the warning and tries the next best provider.
- Type Parameters:
P- the provider typeR- the return type- Parameters:
providerClass- the interface class of the providercontext- the operation contextoperation- the operation to execute- Returns:
- the result of the operation
- Throws:
RuntimeException- if all providers fail
-
select
Selects using static priority (delegates toAlgorithmManager).Convenience method for when no operation context is available.
-