Class Lock

java.lang.Object
org.pipservices3.components.lock.Lock
All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable, org.pipservices3.commons.config.IReconfigurable, ILock
Direct Known Subclasses:
MemoryLock

public abstract class Lock extends Object implements ILock, org.pipservices3.commons.config.IReconfigurable
Abstract lock that implements default lock acquisition routine.

### Configuration parameters ###

    - options:
  • - retry_timeout: timeout in milliseconds to retry lock acquisition. (Default: 100)
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • 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
    configure(org.pipservices3.commons.config.ConfigParams config)
    Configures component by passing configuration parameters.
    abstract void
    releaseLock(String correlationId, String key)
    Releases prevously acquired lock by its key.
    abstract boolean
    tryAcquireLock(String correlationId, String key, int ttl)
    Makes a single attempt to acquire a lock by its key.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Lock

      public Lock()
  • Method Details

    • configure

      public void configure(org.pipservices3.commons.config.ConfigParams config)
      Configures component by passing configuration parameters.
      Specified by:
      configure in interface org.pipservices3.commons.config.IConfigurable
      Parameters:
      config - configuration parameters to be set.
    • tryAcquireLock

      public abstract 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.
      Specified by:
      tryAcquireLock in interface ILock
      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

      public 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.
      Specified by:
      acquireLock in interface ILock
      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

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