Class HotRodLocksUtils


  • public class HotRodLocksUtils
    extends Object
    • Constructor Detail

      • HotRodLocksUtils

        public HotRodLocksUtils()
    • Method Detail

      • repeatPutIfAbsent

        public static void repeatPutIfAbsent​(org.infinispan.client.hotrod.RemoteCache<String,​String> locksCache,
                                             String lockName,
                                             Duration timeout,
                                             int repeatInterval,
                                             boolean isReentrant)
                                      throws LockAcquiringTimeoutException
        Repeatedly attempts to put an entry with the key lockName to the locksCache. Succeeds only if there is no entry with the same key already.

        The value of created entry is equal to instance identifier. It is possible to make the method succeed even if the value already exists with the same instance identifier. This behaviour is enabled using isReentrant switch.

        Execution of this method is time bounded, if this method does not succeed within timeoutMilliseconds it gives up and returns false.

        There is a pause after each unsuccessful attempt equal to repeatInterval milliseconds

        Parameters:
        locksCache - Cache that will be used for putting the value
        lockName - Name of the entry
        timeout - duration to wait until the lock is acquired
        repeatInterval - Number of milliseconds to wait after each unsuccessful attempt
        isReentrant - if this is set to true, the method succeeds also when the value for given key is equal to the instance identifier
        Throws:
        LockAcquiringTimeoutException - the key lockName was NOT put into the map within time boundaries
        IllegalStateException - when a lock value found in the storage has wrong format. It is expected the lock value has the following format 'timeAcquired;keycloakInstanceIdentifier'
      • removeWithInstanceIdentifier

        public static boolean removeWithInstanceIdentifier​(ConcurrentMap<String,​String> map,
                                                           String lockName)
        Removes the entry with key lockName from map if the value of the entry is equal to this node's identifier
        Parameters:
        map - Map that will be used for removing
        lockName - Name of the entry
        Returns:
        true if the entry was removed, false otherwise