Package com.tnsai.spi

Interface CheckpointerProvider


public interface CheckpointerProvider
Service Provider Interface for Checkpointer implementations.

This interface enables pluggable storage backends for checkpointing through Java's ServiceLoader mechanism. Implementations are discovered at runtime, allowing the core module to remain free of database-specific dependencies.

Implementing a Provider


 public class PostgresCheckpointerProvider implements CheckpointerProvider {
     @Override
     public String name() {
         return "postgres";
     }

     @Override
     public boolean isAvailable() {
         try {
             Class.forName("org.postgresql.Driver");
             return true;
         } catch (ClassNotFoundException e) {
             return false;
         }
     }

     @Override
     public Checkpointer create(Map<String, Object> config) {
         String url = (String) config.get("url");
         return new PostgreSQLCheckpointer(url);
     }
 }
 

Registration

Register the provider in META-INF/services/com.tnsai.spi.CheckpointerProvider:

 com.tnsai.store.postgres.PostgresCheckpointerProvider
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new Checkpointer instance with the given configuration.
    default String
    Returns a human-readable description of this provider.
    boolean
    Checks if this provider's dependencies are available.
    Returns the unique name of this provider.
    default int
    Returns the priority of this provider.
    default Optional<String>
    Validates the configuration without creating a Checkpointer.
  • Method Details

    • name

      String name()
      Returns the unique name of this provider.

      Common names include:

      • "memory" - In-memory storage
      • "file" - File-based storage
      • "sqlite" - SQLite database
      • "postgres" - PostgreSQL database
      • "mongodb" - MongoDB database
      Returns:
      provider name (lowercase, alphanumeric with hyphens)
    • description

      default String description()
      Returns a human-readable description of this provider.
      Returns:
      provider description
    • isAvailable

      boolean isAvailable()
      Checks if this provider's dependencies are available.

      This should check for required classes, drivers, or other dependencies without throwing exceptions.

      Returns:
      true if the provider can be used
    • create

      Checkpointer create(Map<String,Object> config)
      Creates a new Checkpointer instance with the given configuration.

      Common configuration keys:

      • "url" - Database connection URL
      • "path" - File path (for file-based stores)
      • "maxCheckpointsPerThread" - Maximum checkpoints per thread
      • "username" - Database username
      • "password" - Database password
      Parameters:
      config - configuration map
      Returns:
      new Checkpointer instance
      Throws:
      IllegalArgumentException - if required configuration is missing
      IllegalStateException - if provider is not available
    • priority

      default int priority()
      Returns the priority of this provider.

      Higher priority providers are preferred when multiple providers are available for the same type. Default priority is 0.

      Returns:
      priority value (higher = more preferred)
    • validateSpec

      default Optional<String> validateSpec(Map<String,Object> config)
      Validates the configuration without creating a Checkpointer.
      Parameters:
      config - configuration to validate
      Returns:
      empty if valid, or error message if invalid