Class DBLockGlobalLockProvider

java.lang.Object
org.keycloak.models.dblock.DBLockGlobalLockProvider
All Implemented Interfaces:
GlobalLockProvider, Provider

public class DBLockGlobalLockProvider extends Object implements GlobalLockProvider
  • Field Details

  • Constructor Details

  • 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 the task and return result to the caller.

      See GlobalLockProvider.withLock(String, Duration, KeycloakSessionTaskWithResult) for more details.

      This implementation does NOT meet all requirements from the JavaDoc of GlobalLockProvider.withLock(String, Duration, KeycloakSessionTaskWithResult) because DBLockProvider 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 the task is also running in the caller thread/transaction.

      Specified by:
      withLock in 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
    • 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 interface GlobalLockProvider
    • close

      public void close()
      Specified by:
      close in interface Provider