public final class ChangeTemplateManager
extends java.lang.Object
ChangeTemplate implementations discovered through Java's
ServiceLoader SPI.
The runtime entry point is loadTemplates() — called once during Flamingock
initialization to populate the internal registry. After that, callers look templates up
by name via getTemplate(String) or getTemplateOrFail(String).
This class is intentionally runtime-only. The GraalVM RegistrationFeature
needs a build-time-safe way to enumerate templates without instantiating them (which
would fire each template's <clinit> and pull SLF4J/Logback into the build-time
image heap). That enumeration lives inside the flamingock-graalvm module so it
can use the JDK 9+ ServiceLoader.Provider::type API; this module is Java-8
compatible and stays small.
Thread Safety Note: not thread-safe during initialization.
loadTemplates() modifies static state and is intended to be called only once
during application startup from a single thread. After initialization, the template
registry is effectively read-only and can be safely accessed concurrently.
| Modifier and Type | Method and Description |
|---|---|
static void |
addTemplate(java.lang.Class<? extends io.flamingock.api.template.ChangeTemplate<?,?,?>> templateClass)
Adds a template to the internal registry for testing purposes.
|
static java.util.Optional<ChangeTemplateDefinition> |
getTemplate(java.lang.String templateName)
Retrieves a template definition by name from the internal registry.
|
static ChangeTemplateDefinition |
getTemplateOrFail(java.lang.String templateName) |
static void |
loadTemplates()
Loads and registers all available templates from the classpath into the internal registry.
|
public static void loadTemplates()
Runtime-only. Iterates ServiceLoader for ChangeTemplate, which
instantiates each provider — that's fine here because we're at runtime; static
initializers (loggers etc.) are allowed to fire. The build-time path that must
not instantiate templates lives in the flamingock-graalvm module.
Not thread-safe; call once during application startup from a single thread, before any template lookups.
public static java.util.Optional<ChangeTemplateDefinition> getTemplate(java.lang.String templateName)
This method is used during runtime to look up template definitions by their simple name.
It returns an Optional that will be empty if no template with the specified
name has been registered.
This method is thread-safe after initialization (after loadTemplates() has been called).
templateName - The simple class name of the template to retrievepublic static ChangeTemplateDefinition getTemplateOrFail(java.lang.String templateName)
@TestOnly public static void addTemplate(java.lang.Class<? extends io.flamingock.api.template.ChangeTemplate<?,?,?>> templateClass)
This method is intended for use in test environments only to register mock or test templates.
It directly modifies the internal template registry and is not thread-safe.
The template is registered under its @ChangeTemplate annotation's id.
templateClass - The template class to register