Package org.keycloak.cluster.infinispan
Class DatabaseAwareClusterProvider
java.lang.Object
org.keycloak.cluster.infinispan.DatabaseAwareClusterProvider
- All Implemented Interfaces:
ClusterProvider,Provider
Wraps an
InfinispanClusterProvider and additionally persists events to the database
for cross-cluster communication.- Author:
- Alexander Schwartz
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.keycloak.cluster.ClusterProvider
ClusterProvider.DCNotify -
Constructor Summary
ConstructorsConstructorDescriptionDatabaseAwareClusterProvider(ClusterProvider delegate, KeycloakSession session, NodeInfo nodeInfo, org.infinispan.commons.marshall.Marshaller marshaller, Duration awaitTimeout) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()<T> ExecutionResult<T>executeIfNotExecuted(String taskKey, int taskTimeoutInSeconds, Callable<T> task) Execute given task just if it's not already in progress (either on this or any other cluster node).executeIfNotExecutedAsync(String taskKey, int taskTimeoutInSeconds, Callable task) Execute given task just if it's not already in progress (either on this or any other cluster node).intSame value for all cluster nodes.booleanChecks if the current cluster is the primary cluster.booleanChecks if the primary cluster check is supported.voidnotify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender) voidnotify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender, ClusterProvider.DCNotify dcNotify) An alternative toClusterProvider.notify(String, ClusterEvent, boolean, DCNotify)that sends multiple events in a single network call.voidnotify(String taskKey, ClusterEvent event, boolean ignoreSender) voidnotify(String taskKey, ClusterEvent event, boolean ignoreSender, ClusterProvider.DCNotify dcNotify) Notify registered listeners on all cluster nodes in all datacenters.voidregisterListener(String taskKey, ClusterListener task) Register task (listener) under given key.
-
Constructor Details
-
DatabaseAwareClusterProvider
public DatabaseAwareClusterProvider(ClusterProvider delegate, KeycloakSession session, NodeInfo nodeInfo, org.infinispan.commons.marshall.Marshaller marshaller, Duration awaitTimeout)
-
-
Method Details
-
getClusterStartupTime
public int getClusterStartupTime()Description copied from interface:ClusterProviderSame value for all cluster nodes. It will use startup time of this server in non-cluster environment.- Specified by:
getClusterStartupTimein interfaceClusterProvider
-
executeIfNotExecuted
public <T> ExecutionResult<T> executeIfNotExecuted(String taskKey, int taskTimeoutInSeconds, Callable<T> task) Description copied from interface:ClusterProviderExecute given task just if it's not already in progress (either on this or any other cluster node).- Specified by:
executeIfNotExecutedin interfaceClusterProvidertaskTimeoutInSeconds- timeout for given task. If there is existing task in progress for longer time, it's considered outdated so we will start our task.- Returns:
- result with "executed" flag specifying if execution was executed or ignored.
-
isPrimaryCluster
public boolean isPrimaryCluster()Description copied from interface:ClusterProviderChecks if the current cluster is the primary cluster.- Specified by:
isPrimaryClusterin interfaceClusterProvider- Returns:
trueif this node is the coordinator.
-
isPrimaryClusterSupported
public boolean isPrimaryClusterSupported()Description copied from interface:ClusterProviderChecks if the primary cluster check is supported.Not all configurations use JDBC_PING and can determine this information.
- Specified by:
isPrimaryClusterSupportedin interfaceClusterProvider- Returns:
trueif the coordinator check is supported.
-
executeIfNotExecutedAsync
public Future<Boolean> executeIfNotExecutedAsync(String taskKey, int taskTimeoutInSeconds, Callable task) Description copied from interface:ClusterProviderExecute given task just if it's not already in progress (either on this or any other cluster node). It will return corresponding future to every caller and this future is fulfilled if: - The task is successfully finished. In that case Future will be true - The task wasn't successfully finished. For example because cluster node failover. In that case Future will be false- Specified by:
executeIfNotExecutedAsyncin interfaceClusterProvidertaskTimeoutInSeconds- timeout for given task. If there is existing task in progress for longer time, it's considered outdated so we will start our task.- Returns:
- Future, which will be completed once the running task is finished. Returns true if task was successfully finished. Otherwise (for example if cluster node when task was running leaved cluster) returns false
-
registerListener
Description copied from interface:ClusterProviderRegister task (listener) under given key. When this key will be put to the cache on any cluster node, the task will be executed.- Specified by:
registerListenerin interfaceClusterProvider
-
notify
public void notify(String taskKey, ClusterEvent event, boolean ignoreSender, ClusterProvider.DCNotify dcNotify) Description copied from interface:ClusterProviderNotify registered listeners on all cluster nodes in all datacenters. It will notify listeners registered under given taskKey- Specified by:
notifyin interfaceClusterProviderignoreSender- if true, then sender node itself won't receive the notificationdcNotify- Specify which DCs to notify. SeeClusterProvider.DCNotifyenum values for more info
-
notify
- Specified by:
notifyin interfaceClusterProvider
-
notify
public void notify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender, ClusterProvider.DCNotify dcNotify) Description copied from interface:ClusterProviderAn alternative toClusterProvider.notify(String, ClusterEvent, boolean, DCNotify)that sends multiple events in a single network call.Notifies registered listeners on all cluster nodes in all datacenters. It will notify listeners registered under given
taskKey- Specified by:
notifyin interfaceClusterProvider- See Also:
-
notify
- Specified by:
notifyin interfaceClusterProvider
-
close
public void close()
-