Package org.keycloak.models.map.lock
Class MapGlobalLockProvider
- java.lang.Object
- 
- org.keycloak.models.map.lock.MapGlobalLockProvider
 
- 
- All Implemented Interfaces:
- GlobalLockProvider,- Provider
 
 public class MapGlobalLockProvider extends Object implements GlobalLockProvider Implementing aGlobalLockProviderbased on a map storage. This requires the map store to support the entity typeMapLockEntity. One of the stores which supports this is the JPA Map Store. The store needs to support the uniqueness of entries in the lock area, seelock(String)for details.- Author:
- Alexander Schwartz
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface org.keycloak.models.locking.GlobalLockProviderGlobalLockProvider.Constants
 
- 
 - 
Constructor SummaryConstructors Constructor Description MapGlobalLockProvider(KeycloakSession session, long defaultTimeoutMilliseconds, Supplier<MapStorage<MapLockEntity,MapLockEntity>> lockStoreSupplier)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidforceReleaseAllLocks()Releases all locks acquired by this GlobalLockProvider.<V> VwithLock(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.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.keycloak.models.locking.GlobalLockProviderwithLock
 
- 
 
- 
- 
- 
Constructor Detail- 
MapGlobalLockProviderpublic MapGlobalLockProvider(KeycloakSession session, long defaultTimeoutMilliseconds, Supplier<MapStorage<MapLockEntity,MapLockEntity>> lockStoreSupplier) 
 
- 
 - 
Method Detail- 
withLockpublic <V> V withLock(String lockName, Duration timeToWaitForLock, KeycloakSessionTaskWithResult<V> task) throws LockAcquiringTimeoutException Description copied from interface:GlobalLockProviderAcquires a new non-reentrant global lock that is visible to all Keycloak nodes. If the lock was successfully acquired the method runs thetaskin a new transaction to ensure all data modified intaskis committed to the stores before releasing the lock and returning to the caller. If there is another global lock with the same identifier (lockName) already acquired, this method waits until the lock is released, however, not more thantimeToWaitForLockduration. If the lock is not acquired aftertimeToWaitForLockduration, the method throwsLockAcquiringTimeoutException. When the execution of thetaskfinishes, the acquired lock must be released regardless of the result. A note to implementors of the interface: To make sure acquiring/releasing the lock is visible to all Keycloak nodes it may be needed to run the code that acquires/releases the lock in a separate transactions. This means together the method can use 3 separate transactions, for example:try { KeycloakModelUtils.runJobInTransaction(factory, innerSession -> /* run code that acquires the lock *\/) KeycloakModelUtils.runJobInTransactionWithResult(factory, task) } finally { KeycloakModelUtils.runJobInTransaction(factory, innerSession -> /* run code that releases the lock *\/) }- Specified by:
- withLockin interface- GlobalLockProvider
- Type Parameters:
- V- Type of object returned by the- task
- 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. If- null, 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
- Throws:
- LockAcquiringTimeoutException- When the method waits for- timeToWaitForLockduration and the lock is still not available to acquire.
 
 - 
forceReleaseAllLockspublic void forceReleaseAllLocks() Description copied from interface:GlobalLockProviderReleases 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:
- forceReleaseAllLocksin interface- GlobalLockProvider
 
 
- 
 
-