Package org.keycloak.expiration.jpa
Class ExpirationTaskBuilder
java.lang.Object
org.keycloak.expiration.jpa.ExpirationTaskBuilder
A builder for creating
ExpirationTask instances.
Required properties: withFactory(KeycloakSessionFactory), withAction(ExpirationAction),
withEntityId(String), withExecutor(Executor), and withInterval(int, TimeUnit).
Optional properties: withListener(ExpirationListener), withMetrics(boolean),
withRealmExpiration(boolean), withMaxRemoval(int) (defaults to 128),
and withTimeout(int, TimeUnit) (defaults to the interval).
Example usage:
ExpirationTask.builder()
.withFactory(factory)
.withEntityId("authentication-sessions")
.withInterval(600, TimeUnit.SECONDS)
.withTimeout(300, TimeUnit.SECONDS)
.withAction(myAction)
.withExecutor(executor)
.withMetrics(true)
.withRealmExpiration(true)
.withMaxRemoval(128)
.build()
.schedule();
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds theExpirationTask.withAction(ExpirationAction action) Sets theExpirationActionthat performs the actual deletion of expired entries.withEntityId(String entityId) Sets a unique identifier for the entity type being expired (e.g.withExecutor(Executor executor) Sets theExecutorused to run the cleanup work off the timer thread.withFactory(KeycloakSessionFactory factory) Sets theKeycloakSessionFactoryused to create sessions for each transaction.withInterval(int interval, TimeUnit timeUnit) Sets the interval between expiration task runs.withListener(ExpirationListener listener) Sets an optionalExpirationListenerto be notified after each task run.withMaxRemoval(int maxRemoval) Sets the maximum number of entries to remove per batch.withMetrics(boolean metrics) Enables or disables Micrometer metrics for this expiration task.withRealmExpiration(boolean realmExpiration) Enables per-realm expiration.withTimeout(int timeout, TimeUnit timeUnit) Sets the transaction timeout for each expiration task run.
-
Method Details
-
withAction
Sets theExpirationActionthat performs the actual deletion of expired entries. -
withListener
Sets an optionalExpirationListenerto be notified after each task run. When metrics are also enabled, both the metrics listener and this listener are notified. -
withExecutor
Sets theExecutorused to run the cleanup work off the timer thread. -
withEntityId
Sets a unique identifier for the entity type being expired (e.g."authentication-sessions"). Used in metric tags, log messages, and as the key prefix for distributed coordination viaServerConfigStorageProvider. -
withMetrics
Enables or disables Micrometer metrics for this expiration task. When enabled, akeycloak.expirationtimer and akeycloak.expiration.removalsdistribution summary are registered with tags for the entity type and outcome. -
withRealmExpiration
Enables per-realm expiration. Whentrue, the task iterates over all realms and invokes theExpirationActiononce per realm. Whenfalse, the action is invoked once with anullrealm ID. -
withMaxRemoval
Sets the maximum number of entries to remove per batch. Defaults to 128.- Throws:
ModelException- if the value is not positive.
-
withInterval
Sets the interval between expiration task runs.- Throws:
ArithmeticException- if the converted value overflows anint.
-
withTimeout
Sets the transaction timeout for each expiration task run. Defaults to the interval if not set.- Throws:
ArithmeticException- if the converted value overflows anint.
-
withFactory
Sets theKeycloakSessionFactoryused to create sessions for each transaction. -
build
Builds theExpirationTask.- Throws:
NullPointerException- if any required property is not set.ModelException- if the interval is not set or is not positive.
-