Package com.tnsai.spi

Class CheckpointerFactory

java.lang.Object
com.tnsai.spi.CheckpointerFactory

public final class CheckpointerFactory extends Object
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:
  • Method Details

    • getInstance

      public static CheckpointerFactory 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

      public List<String> registeredProviders()
      Returns the names of all registered providers.
      Returns:
      list of provider names
    • availableProviders

      public List<String> availableProviders()
      Returns the names of all available (usable) providers.
      Returns:
      list of available provider names
    • hasProvider

      public boolean hasProvider(String name)
      Checks if a provider is registered.
      Parameters:
      name - provider name
      Returns:
      true if registered
    • isAvailable

      public boolean isAvailable(String name)
      Checks if a provider is available (registered and dependencies met).
      Parameters:
      name - provider name
      Returns:
      true if available
    • getProviderInfo

      public Optional<CheckpointerFactory.ProviderInfo> getProviderInfo(String name)
      Gets information about a provider.
      Parameters:
      name - provider name
      Returns:
      provider info, or empty if not found
    • create

      public Checkpointer create(String name, Map<String,Object> config)
      Creates a Checkpointer using the named provider.
      Parameters:
      name - provider name
      config - configuration map
      Returns:
      new Checkpointer instance
      Throws:
      IllegalArgumentException - if provider not found or not available
    • createBest

      public Checkpointer createBest(Map<String,Object> config)
      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

      public Checkpointer createInMemory()
      Creates a default in-memory Checkpointer.
      Returns:
      new in-memory Checkpointer