Does the given ID refer to the current lock holder?
---------------------------------------------------
@param {Task} task
@param {string} requestorId
@return {bool}
@throws {LockError}
@api {public}
971428
function isLockHolder(task, requestorId) {
  if(!task.semaphore) {
    throw new LockError('TaskNotLocked');
  }
  var requestKey  = hashKey(requestorId, task.id);

  return requestKey === task.semaphore.key;
}
1371252
function requestId(options){

    options = extend({}, DEFAULTS);

    return function requestIdMiddleware(req, res, next){

        let id = _getId(req, options);
        let attributeName = options.attributeName;

        // console.log('requestid', id);

        /*
         * Want to expose the genrated
         * id in the request and response
         */
        req[attributeName] = id;

        if(res.req) res.req[attributeName] = id;

        /*
         * We send a header with the required
         * id...
         */
        if(options.resHeader) {
            res.set(options.resHeader, id);
        }

        next();
    }
}
953789
@Override
    public final boolean lockItemIfAvailable(long lockID) throws SevereMessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "lockItemIfAvailable", Long.valueOf(lockID));

        boolean locked = false;
        if (AbstractItem.NO_LOCK_ID == lockID)
        {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "lockItemIfAvailable");
            throw new SevereMessageStoreException("invalid lockID - clashes with internal constant NO_LOCK_ID");
        }
        boolean hasBecomeNonReleasable = false;
        synchronized (this)
        {
            if (!isExpired() && isAvailable())
            {
                if (ItemLinkState.STATE_AVAILABLE == _itemLinkState)
                {
                    ListStatistics stats = getParentStatistics();
                    synchronized (stats)
                    {
                        stats.incrementLocked();
                        stats.decrementAvailable();
                    }
                }
                else
                {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                        SibTr.event(this, tc, "Invalid Item state: " + _itemLinkState);
                    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                        SibTr.exit(this, tc, "lockItemIfAvailable");
                    throw new StateException(_itemLinkState.toString());
                }
                locked = true;
                _lockID = lockID;
                hasBecomeNonReleasable = _declareNotDiscardable(_getItemNoRestore());
                _itemLinkState = ItemLinkState.STATE_LOCKED;
            }
        }
        if (hasBecomeNonReleasable)
        {
            _declareNotReleasable();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "lockItemIfAvailable", Boolean.valueOf(locked));
        return locked;
    }
1028108
function Lock(named) {
  if (!(this instanceof Lock))
    return Lock.create(named);

  this.named = named === true;

  this.jobs = [];
  this.busy = false;
  this.destroyed = false;

  this.map = new Map();
  this.current = null;

  this.unlocker = this.unlock.bind(this);
}
217855
DownloadState query(int downloadId) {
    synchronized (currentRequests) {
      for (DownloadRequest request : currentRequests) {
        if (request.downloadId() == downloadId) {
          return request.downloadState();
        }
      }
    }

    return DownloadState.INVALID;
  }
22562
function isUserLocked(username, path, callback) {
  var key = SyncLock.generateKey(username);
  redis.hget(key, path, function(err, value) {
    if(err) {
      log.error(err, 'Error getting redis lock key %s.', key);
      return callback(err);
    }

    callback(null, !!value);
  });
}
1134213
public Optional<SingularityTaskState> getTaskState(String requestId, String runId) {
    final Function<String, String> requestUri = (host) -> String.format(TRACK_BY_RUN_ID_FORMAT, getApiBase(host), requestId, runId);
    return getSingle(requestUri, "track by task id", String.format("%s-%s", requestId, runId), SingularityTaskState.class);
  }
775385
private void handleLockHeld(String taskId, ShardedJobStateImpl<T> jobState,
      IncrementalTaskState<T> taskState) {
    long currentTime = System.currentTimeMillis();
    int sliceTimeoutMillis = jobState.getSettings().getSliceTimeoutMillis();
    long lockExpiration = taskState.getLockInfo().lockedSince() + sliceTimeoutMillis;
    boolean wasRequestCompleted = wasRequestCompleted(taskState.getLockInfo().getRequestId());

    if (lockExpiration > currentTime && !wasRequestCompleted) {
      // if lock was not expired AND not abandon reschedule in 1 minute.
      long eta = Math.min(lockExpiration, currentTime + 60_000);
      scheduleWorkerTask(null, jobState.getSettings(), taskState, eta);
      log.info("Lock for " + taskId + " is being held. Will retry after " + (eta - currentTime));
    } else {
      ShardRetryState<T> retryState;
      if (wasRequestCompleted) {
        retryState = handleSliceFailure(jobState, taskState, new RuntimeException(
            "Resuming after abandon lock for " + taskId + " on slice: "
                + taskState.getSequenceNumber()), true);
      } else {
        retryState = handleShardFailure(jobState, taskState, new RuntimeException(
          "Lock for " + taskId + " expired on slice: " + taskState.getSequenceNumber()));
      }
      updateTask(jobState, taskState, retryState, false);
    }
  }
127305
function Lock(target, name, descriptor) {
    let fn = descriptor.value;
    let $$LockIsDoing = false;

    let reset = ()=>$$LockIsDoing=false;
    descriptor.value = function(...args) {
        if ($$LockIsDoing) return;
        $$LockIsDoing = true;

        let ret = fn.apply(this, args);

        if (ret && ret.then) {
            // is promise
            return ret.then((succ)=>{
                reset();
                return Promise.resolve(succ);
            }, (fail)=>{
                reset();
                return Promise.reject(fail);
            });
        } else {
            reset();
            return ret;
        }
    };

    return descriptor;
}
1250355
function(method, url, async, user, password) {
      this.user = user
      this.password = password
      this.url = url
      this.readyState = 1
      this.method = method.toUpperCase()
      if (async != undefined) this.async = async
      if (this.async) this.onreadystatechange()
    }
710818
def lock_status(self, resource_id, parent_id=None, account_id=None):
        
        account_id = self.get_account_id(account_id)
        params = parent_id and {'parent_id': parent_id} or None
        return self.http.get(
            "%s/%s/locks/%s" % (self.endpoint, account_id, resource_id),
            params=params, auth=self.get_api_auth())
651398
private void handleRequest(long requestId, Object request, HandlerHolder handler) {
    @SuppressWarnings("unchecked")
    CompletableFuture<Object> responseFuture = handler.handler.apply(request);
    if (responseFuture != null) {
      responseFuture.whenComplete((response, error) -> {
        ThreadContext context = ThreadContext.currentContext();
        if (context == null) {
          this.context.executor().execute(() -> {
            if (error == null) {
              handleRequestSuccess(requestId, response, this.context);
            } else {
              handleRequestFailure(requestId, error, this.context);
            }
          });
        } else {
          if (error == null) {
            handleRequestSuccess(requestId, response, context);
          } else {
            handleRequestFailure(requestId, error, context);
          }
        }
      });
    }
  }
294253
public String getRequestById(long requestId, boolean withErrors, boolean withData, String marshallingType) {

        String result = null;

        RequestInfo request = executorService.getRequestById(requestId);

        if (request == null) {
            throw new IllegalArgumentException("Request with id: " + requestId + " doesn't exist");
        } else {
            RequestInfoInstance requestInstance = convertToRequestInfo(request, withErrors, withData);

            String deploymentId = ((org.jbpm.executor.entities.RequestInfo) request).getDeploymentId();
            if (deploymentId != null && context.getContainer(deploymentId) != null) {
                result = marshallerHelper.marshal(deploymentId, marshallingType, requestInstance);
            } else {
                result = marshallerHelper.marshal(marshallingType, requestInstance);
            }
        }

        return result;
    }
1320047
function advisoryLock(callback) {
      if (!(req.htmlPageId && req.user)) {
        // Some consumers of this API might not participate
        // in advisory locking. Also, make sure we have a
        // valid user to minimize the risk of a DOS attack
        // via nuisance locking
        return callback(null);
      }
      return self.apos.docs.lock(req, docId, req.htmlPageId, callback);
    }
1216725
function setRequestId(id, cb) {
  var ns = getLoggerNamespace();
  ns.run(function() {
    ns.set('requestId', id);
    cb();
  });
}
919444
def lock(self, resource_id, region, account_id=None):
        
        account_id = self.get_account_id(account_id)
        return self.http.post(
            "%s/%s/locks/%s/lock" % (self.endpoint, account_id, resource_id),
            json={'region': region},
            auth=self.get_api_auth())
119490
synchronized int release(Locker locker) {

        //-----------------------------------------------------------------
        // A transaction can be both a holder and a waiter if
        // it is attempting to convert a shared lock to an exclusive one.
        //-----------------------------------------------------------------

        if (holders.remove(locker) != null) {
            numUsers--;
        }

        Waiter waiter = (Waiter) waiters.remove(locker);
        if (waiter != null) {
            numUsers--;
            synchronized (waiter) {
                waitQ.removeElement(waiter);
                waiter.released = true;
                lockMgr.unwaitEvent(waiter);
                waiter.notify();
            }
        }

        //----------------------------------------------------------------
        // Q: Do we care about attempts to release locks for given locker
        //    that are not held by that locker? If so fail here if locker
        //    was neither holder nor waiter.
        //----------------------------------------------------------------

        //----------------------------------------------------------
        // If there are no more holders then wake up all compatible
        // waiters from the head of the wait queue. This imposes a
        // strict FIFO scheduling.
        //----------------------------------------------------------

        if (holders.size() == 0) {

            //-------------------------------------------------
            // Grant first waiter the lock and then see if the
            // remaining waiters are compatible.
            //-------------------------------------------------

            if (waiters.size() > 0) {
                Waiter newHolder = (Waiter) waitQ.firstElement();
                synchronized (newHolder) {
                    waiters.remove(newHolder.locker);
                    waitQ.removeElementAt(0);
                    holders.put(newHolder.locker, newHolder.locker);
                    this.mode = newHolder.mode;
                    lockMgr.unwaitEvent(newHolder);
                    newHolder.notify();
                }
            }

            //--------------------------------------------------
            // If lock now held in exclusive mode we are done,
            // else grant lock to all waiters at head of queue
            // that are requesting the lock in the SHARED mode.
            //--------------------------------------------------

            if (mode == LockManager.EXCLUSIVE) {
                return numUsers;
            }

            while (waiters.size() > 0) {
                Waiter newHolder = (Waiter) waitQ.firstElement();
                if (newHolder.mode == LockManager.EXCLUSIVE) {
                    return numUsers;
                }

                synchronized (newHolder) {
                    waiters.remove(newHolder.locker);
                    waitQ.removeElementAt(0);
                    holders.put(newHolder.locker, newHolder.locker);
                    lockMgr.unwaitEvent(newHolder);
                    newHolder.notify();
                }
            }
        }
        return numUsers;

    }