Package org.keycloak.models.dblock
Class DBLockGlobalLockProvider
java.lang.Object
org.keycloak.models.dblock.DBLockGlobalLockProvider
- All Implemented Interfaces:
GlobalLockProvider
,Provider
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.keycloak.models.locking.GlobalLockProvider
GlobalLockProvider.Constants
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDBLockGlobalLockProvider
(KeycloakSession session, DBLockProvider dbLockProvider) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
Releases all locks acquired by this GlobalLockProvider.<V> V
withLock
(String lockName, Duration timeToWaitForLock, KeycloakSessionTaskWithResult<V> task) Acquires a new non-reentrant global lock that is visible to all Keycloak nodes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.keycloak.models.locking.GlobalLockProvider
withLock
-
Field Details
-
DATABASE
- See Also:
-
-
Constructor Details
-
DBLockGlobalLockProvider
-
-
Method Details
-
withLock
public <V> V withLock(String lockName, Duration timeToWaitForLock, KeycloakSessionTaskWithResult<V> task) Acquires a new non-reentrant global lock that is visible to all Keycloak nodes. If the lock was successfully acquired the method runs thetask
and return result to the caller. SeeGlobalLockProvider.withLock(String, Duration, KeycloakSessionTaskWithResult)
for more details. This implementation does NOT meet all requirements from the JavaDoc ofGlobalLockProvider.withLock(String, Duration, KeycloakSessionTaskWithResult)
becauseDBLockProvider
does not provide a way to lock and unlock in separate transactions. Also, the database schema update currently requires to be running in the same thread that initiated the update therefore thetask
is also running in the caller thread/transaction.- Specified by:
withLock
in interfaceGlobalLockProvider
- Type Parameters:
V
- Type of object returned by thetask
- Parameters:
lockName
- Identifier used for acquiring lock. Can be any non-null string.timeToWaitForLock
- Duration this method waits until it gives up acquiring the lock. Ifnull
, each implementation should provide some default duration, for example, using a configuration option.task
- The task that will be executed under the acquired lock- Returns:
- Value returned by the
task
-
forceReleaseAllLocks
public void forceReleaseAllLocks()Description copied from interface:GlobalLockProvider
Releases all locks acquired by this GlobalLockProvider. This method unlocks all existing locks acquired by this provider regardless of the thread or Keycloak instance that originally acquired them.- Specified by:
forceReleaseAllLocks
in interfaceGlobalLockProvider
-
close
public void close()
-