lib/Lock.js
function Lock(client, basePath, lockName, lockDriver) {
  if (lockName instanceof LockDriver) {
    lockDriver = lockName;
    lockName = null;
  }
  if (!lockName) {
    lockName = Lock.LOCK_NAME;
  }
  if (!lockDriver) {
    lockDriver = new LockDriver();
  }


  /**
   * Keep ref to client as all the low-level operations are done through it.
   *
   * @type {Rorschach}
   */
  this.client = client;


  /**
   * Base path should be valid ZooKeeper path.
   *
   * @type {String}
   */
  this.basePath = basePath;


  /**
   * Node name.
   *
   * @type {String}
   */
  this.lockName = lockName;


  /**
   * Lock driver.
   *
   * @type {LockDriver}
   */
  this.driver = lockDriver;


  /**
   * Sequence node name (set when acquired).
   *
   * @type {String}
   */
  this.lockPath;


  /**
   * Number of max leases.
   *
   * @type {Number}
   */
  this.maxLeases = 1;


  /**
   * Number of acquires.
   *
   * @type {Number}
   */
  this.acquires = 0;
}
function Lock(client, basePath, lockName, lockDriver) {
  if (lockName instanceof LockDriver) {
    lockDriver = lockName;
    lockName = null;
  }
  if (!lockName) {
    lockName = Lock.LOCK_NAME;
  }
  if (!lockDriver) {
    lockDriver = new LockDriver();
  }


  /**
   * Keep ref to client as all the low-level operations are done through it.
   *
   * @type {Rorschach}
   */
  this.client = client;


  /**
   * Base path should be valid ZooKeeper path.
   *
   * @type {String}
   */
  this.basePath = basePath;


  /**
   * Node name.
   *
   * @type {String}
   */
  this.lockName = lockName;


  /**
   * Lock driver.
   *
   * @type {LockDriver}
   */
  this.driver = lockDriver;


  /**
   * Sequence node name (set when acquired).
   *
   * @type {String}
   */
  this.lockPath;


  /**
   * Number of max leases.
   *
   * @type {Number}
   */
  this.maxLeases = 1;


  /**
   * Number of acquires.
   *
   * @type {Number}
   */
  this.acquires = 0;
}
function Lock ( client , basePath , lockName , lockDriver ) { if ( lockName instanceof LockDriver ) { lockDriver = lockName ; lockName = null ; } if ( ! lockName ) { lockName = Lock . LOCK_NAME ; } if ( ! lockDriver ) { lockDriver = new LockDriver ( ) ; } /**
   * Keep ref to client as all the low-level operations are done through it.
   *
   * @type {Rorschach}
   */ this . client = client ; /**
   * Base path should be valid ZooKeeper path.
   *
   * @type {String}
   */ this . basePath = basePath ; /**
   * Node name.
   *
   * @type {String}
   */ this . lockName = lockName ; /**
   * Lock driver.
   *
   * @type {LockDriver}
   */ this . driver = lockDriver ; /**
   * Sequence node name (set when acquired).
   *
   * @type {String}
   */ this . lockPath ; /**
   * Number of max leases.
   *
   * @type {Number}
   */ this . maxLeases = 1 ; /**
   * Number of acquires.
   *
   * @type {Number}
   */ this . acquires = 0 ; }
Distributed lock implementation

@constructor
@param {Rorschach} client Rorschach instance
@param {String} basePath Base lock path
@param {String} [lockName] Ephemeral node name
@param {LockDriver} [lockDriver=new LockDriver()] Lock utilities
Distributed lock implementation