Class ProcessLockUtils

java.lang.Object
com.kingsrook.qqq.backend.core.processes.locks.ProcessLockUtils

public class ProcessLockUtils extends Object
Utility class for working with ProcessLock table - creating, checking-in, and releasing process locks.
  • Constructor Details

    • ProcessLockUtils

      public ProcessLockUtils()
  • Method Details

    • create

      public static ProcessLock create(String key, String typeName, String details) throws UnableToObtainProcessLockException, QException
      try to create a process lock, of a given key invalid input: '&' type - but immediately fail if the lock already exists.
      Parameters:
      key - along with typeName, part of Unique Key for the lock.
      typeName - along with key, part of Unique Key for the lock. Must be a defined lock type, from which we derive defaultExpirationSeconds.
      details - advice to show users re: who/what created the lock.
      Throws:
      UnableToObtainProcessLockException
      QException
    • create

      public static ProcessLock create(String key, String typeName, String details, Duration sleepBetweenTries, Duration maxWait) throws UnableToObtainProcessLockException, QException
      try to create a process lock, of a given key invalid input: '&' type - and re-try if it failed. (e.g., wait until existing lock holder releases the lock).
      Parameters:
      key - along with typeName, part of Unique Key for the lock.
      typeName - along with key, part of Unique Key for the lock. Must be a defined lock type, from which we derive defaultExpirationSeconds.
      details - advice to show users re: who/what created the lock.
      sleepBetweenTries - how long to sleep between retries.
      maxWait - max amount of that will be waited between call to this method and an eventual UnableToObtainProcessLockException (plus or minus one sleepBetweenTries (actually probably just plus that).
      Throws:
      UnableToObtainProcessLockException
      QException
    • createMany

      public static Map<String,ProcessLockOrException> createMany(List<String> keys, String typeName, String details) throws QException
      try to create many process locks, of list of keys invalid input: '&' a type - but immediately fail (on a one-by-one basis) if the lock already exists.
      Parameters:
      keys - along with typeName, part of Unique Key for the lock.
      typeName - along with key, part of Unique Key for the lock. Must be a defined lock type, from which we derive defaultExpirationSeconds.
      details - advice to show users re: who/what created the lock.
      Throws:
      QException
    • createMany

      public static Map<String,ProcessLockOrException> createMany(List<String> keys, String typeName, String details, Duration sleepBetweenTries, Duration maxWait) throws QException
      try to create many process locks, of a given list of key invalid input: '&' a type - and re-try upon failures (e.g., wait until existing lock holder releases the lock).
      Parameters:
      keys - along with typeName, part of Unique Key for the lock.
      typeName - along with key, part of Unique Key for the lock. Must be a defined lock type, from which we derive defaultExpirationSeconds.
      details - advice to show users re: who/what created the lock.
      sleepBetweenTries - how long to sleep between retries.
      maxWait - max amount of that will be waited between call to this method and an eventual UnableToObtainProcessLockException (plus or minus one sleepBetweenTries (actually probably just plus that).
      Throws:
      QException
    • getById

      public static ProcessLock getById(Integer id) throws QException
      Throws:
      QException
    • checkIn

      public static void checkIn(ProcessLockUtils.CheckInInput input)
      Do a check-in, with a specific value for the expiresAtTimestamp - which can be set to null to make it null in the lock. If you don't want to specify the expiresAtTimestamp, call the overload that doesn't take the timestamp - in which case it'll either stay the same as it was, or will be set based on the type's default.
    • checkIn

      public static void checkIn(ProcessLock processLock, Instant expiresAtTimestamp)
      Do a check-in, with a specific value for the expiresAtTimestamp - which can be set to null to make it null in the lock. If you don't want to specify the expiresAtTimestamp, call the overload that doesn't take the timestamp - in which case it'll either stay the same as it was, or will be set based on the type's default.
    • checkIn

      public static void checkIn(ProcessLock processLock)
      Do a check-in, updating the expires-timestamp based on the lock type's default. (or leaving it the same as it was (null or otherwise) if there is no default on the type).
    • releaseById

      public static void releaseById(Integer id)
    • releaseByIds

      public static void releaseByIds(List<? extends Serializable> ids)
    • release

      public static void release(ProcessLock processLock)
    • releaseMany

      public static void releaseMany(List<ProcessLock> processLocks)