Package com.tnsai.spi
Class CheckpointerFactory
java.lang.Object
com.tnsai.spi.CheckpointerFactory
Factory for creating Checkpointer instances using SPI discovery.
This factory discovers and manages CheckpointerProvider implementations through Java's ServiceLoader mechanism, providing a unified API for creating checkpointers regardless of the underlying storage backend.
Usage
// Get factory instance
CheckpointerFactory factory = CheckpointerFactory.getInstance();
// List available providers
List<String> providers = factory.availableProviders();
// ["memory", "file", "sqlite", "postgres", "mongodb"]
// Create checkpointer by name
Checkpointer cp = factory.create("postgres", Map.of(
"url", "jdbc:postgresql://localhost/mydb",
"username", "user",
"password", "pass"
));
// Create with auto-detection (uses highest priority available)
Checkpointer cp = factory.createBest(Map.of("path", "./data"));
Built-in Providers
The core module includes these built-in providers:
- "memory" - In-memory storage (always available)
- "file" - File-based storage (always available)
External Providers
Additional providers can be added by including their modules:
- tnsai-store-sqlite - SQLite storage
- tnsai-store-postgres - PostgreSQL storage
- tnsai-store-mongodb - MongoDB storage
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordInformation about a provider. -
Method Summary
Modifier and TypeMethodDescriptionReturns the names of all available (usable) providers.Creates a Checkpointer using the named provider.createBest(Map<String, Object> config) Creates a Checkpointer using the best available provider.Creates a default in-memory Checkpointer.static CheckpointerFactoryReturns the singleton factory instance.getProviderInfo(String name) Gets information about a provider.booleanhasProvider(String name) Checks if a provider is registered.booleanisAvailable(String name) Checks if a provider is available (registered and dependencies met).Returns the names of all registered providers.voidreload()Reloads all providers.
-
Method Details
-
getInstance
Returns the singleton factory instance.- Returns:
- factory instance
-
reload
public void reload()Reloads all providers.This can be used after adding new provider JARs to the classpath.
-
registeredProviders
Returns the names of all registered providers.- Returns:
- list of provider names
-
availableProviders
Returns the names of all available (usable) providers.- Returns:
- list of available provider names
-
hasProvider
Checks if a provider is registered.- Parameters:
name- provider name- Returns:
- true if registered
-
isAvailable
Checks if a provider is available (registered and dependencies met).- Parameters:
name- provider name- Returns:
- true if available
-
getProviderInfo
Gets information about a provider.- Parameters:
name- provider name- Returns:
- provider info, or empty if not found
-
create
Creates a Checkpointer using the named provider.- Parameters:
name- provider nameconfig- configuration map- Returns:
- new Checkpointer instance
- Throws:
IllegalArgumentException- if provider not found or not available
-
createBest
Creates a Checkpointer using the best available provider.Selects the highest-priority available provider and creates a checkpointer with the given configuration.
- Parameters:
config- configuration map- Returns:
- new Checkpointer instance
- Throws:
IllegalStateException- if no providers are available
-
createInMemory
Creates a default in-memory Checkpointer.- Returns:
- new in-memory Checkpointer
-