Interface ILock

All Known Implementing Classes:
Lock, MemoryLock, NullLock

public interface ILock
Interface for locks to synchronize work or parallel processes and to prevent collisions.

The lock allows to manage multiple locks identified by unique keys.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    acquireLock(String correlationId, String key, int ttl, long timeout)
    Makes multiple attempts to acquire a lock by its key within give time interval.
    void
    releaseLock(String correlationId, String key)
    Releases prevously acquired lock by its key.
    boolean
    tryAcquireLock(String correlationId, String key, int ttl)
    Makes a single attempt to acquire a lock by its key.
  • Method Details

    • tryAcquireLock

      boolean tryAcquireLock(String correlationId, String key, int ttl)
      Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      key - a unique lock key to acquire.
      ttl - a lock timeout (time to live) in milliseconds.
      Returns:
      true if the lock was acquired and false otherwise.
    • acquireLock

      void acquireLock(String correlationId, String key, int ttl, long timeout) throws InterruptedException, org.pipservices3.commons.errors.ApplicationException
      Makes multiple attempts to acquire a lock by its key within give time interval.
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      key - a unique lock key to acquire.
      ttl - a lock timeout (time to live) in milliseconds.
      timeout - a lock acquisition timeout.
      Throws:
      InterruptedException
      org.pipservices3.commons.errors.ApplicationException
    • releaseLock

      void releaseLock(String correlationId, String key)
      Releases prevously acquired lock by its key.
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      key - a unique lock key to release.