lock the named lock
注意：加锁和解锁必须配对地调用！Each call to acquire that returns true must be balanced by a call to release()

@return the inner id of the lock or -1 if timed out waiting for the lock
@throws RuntimeException any unknown runtime exception.
548805
public static int lock(String name, long timeoutInMilli) {
        if (name.contains("/")) {
            throw new IllegalArgumentException("锁的名称不允许包含'/'，yourLockName= " + name);
        }
        LOG.debug("由于zk单个znode下如果存在过多children会出现zk客户端无法ls列表，和无法rmr的问题，因此加入日期子路径");
        //todo 缺点1、一天的锁数量日后太大时也会有children过多问题
        //todo 缺点2、跨天锁失效
        //todo 以上解决方案：使用一致性哈希将锁分配到固定子路径内去
        //todo 优点、临时解决了我们维护zk困难的问题
        InterProcessMutex lock = new InterProcessMutex(ZkConnection.client, LOCK_ROOT + "/" + DateUtil.getDateStr() + "/" + name);
        int innerId = innerIdGenerator.getAndIncrement();
        try {
            if (!lock.acquire(timeoutInMilli, TimeUnit.MILLISECONDS)) {
                LOG.info(String.format("获取锁%s超时,超时时间%sms", name, timeoutInMilli));
                return TIME_OUT_INNER_ID;
            } else {
                map.put(innerId, lock);
                return innerId;
            }
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }
984295
public ActiveExecution lock(String id)
            throws Exception {
        LOGGER.debug("locking {}", id);
        if (!myLocks.contains(id)) {
            if (locking.acquire(id, null)) {
                myLocks.add(id);
                ActiveExecution ae = new ActiveExecution();
                ae.setMigrationJobId(id);
                ae.set_id(id);
                ae.setStartTime(new Date());
                return ae;
            }
        }
        return null;
    }
527566
@Managed
   @ManagedDescription("The number of active locks")
   public int getNumLocks()
   {
      try
      {
         return getNumLocks.run();
      }
      catch (LockException e)
      {
         if (LOG.isTraceEnabled())
         {
            LOG.trace("An exception occurred: " + e.getMessage());
         }
      }
      return -1;
   }
488191
public com.google.api.ads.admanager.axis.v201902.LockedOrientation getLockedOrientation() {
        return lockedOrientation;
    }
614804
public static synchronized RuntimeDelegate ensureSet() {
        if (singleton == null) {
            singleton = new MuRuntimeDelegate();
            RuntimeDelegate.setInstance(singleton);
        }
        return singleton;
    }
123377
protected Properties getLockProperties(String name) {
        return lockProperties != null ? lockProperties.get(name) : null;
    }
950219
@Override
  public boolean tryLock() throws JobLockException {
    try {
      return this.lock.acquire(lockAcquireTimeoutMilliseconds, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
      throw new JobLockException("Failed to acquire lock " + this.lockPath, e);
    }
  }
1265130
@SuppressWarnings("WeakerAccess")
  public String getId() {
    // Constructor ensures that name is not null
    ClusterName fullName =
        Verify.verifyNotNull(ClusterName.parse(stateProto.getName()), "Name can never be null");
    //noinspection ConstantConditions
    return fullName.getCluster();
  }
229220
public Observable<ServiceResponse<ManagementLockObjectInner>> getAtSubscriptionLevelWithServiceResponseAsync(String lockName) {
        if (lockName == null) {
            throw new IllegalArgumentException("Parameter lockName is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        if (this.client.apiVersion() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
        }
        return service.getAtSubscriptionLevel(lockName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ManagementLockObjectInner>>>() {
                @Override
                public Observable<ServiceResponse<ManagementLockObjectInner>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<ManagementLockObjectInner> clientResponse = getAtSubscriptionLevelDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }
158091
public LockedInodePath lockFinalEdgeWrite() throws InvalidPathException {
    Preconditions.checkState(!fullPathExists());

    LockedInodePath newPath =
        new LockedInodePath(mUri, this, mPathComponents, LockPattern.WRITE_EDGE);
    newPath.traverse();
    return newPath;
  }
908828
@SuppressWarnings("WeakerAccess")
  public String getId() {
    // Constructor ensures that name is not null
    InstanceName fullName =
        Verify.verifyNotNull(InstanceName.parse(proto.getName()), "Name can never be null");

    //noinspection ConstantConditions
    return fullName.getInstance();
  }
298452
public synchronized long nextId() {
        long timestamp = timeGen();
        if (timestamp < lastTimestamp) {
            throw new RuntimeException(
                    String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
        }
        //如果是同一时间生成的，则进行毫秒内序列
        if (lastTimestamp == timestamp) {
            sequence = (sequence + 1) & sequenceMask;
            //毫秒内序列溢出
            if (sequence == 0) {
                //阻塞到下一个毫秒,获得新的时间戳
                timestamp = tilNextMillis(lastTimestamp);
            }
        }
        //时间戳改变，毫秒内序列重置
        else {
            sequence = 0L;
        }
        //上次生成ID的时间截
        lastTimestamp = timestamp;
        //移位并通过或运算拼到一起组成64位的ID
        return ((timestamp - twepoch) << timestampLeftShift)
                | (dataCenterId << dataCenterIdShift)
                | (workerId << workerIdShift)
                | sequence;
    }
257799
static int computeLockId(String s) {
        // This method handles the following fact: Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE
        int hashCode = s.hashCode();
        if (hashCode == Integer.MIN_VALUE) {
            hashCode = 13;
        }
        return Math.abs(hashCode) % 1073741823;
    }
1015360
public CmsLock getLock() {

        if (m_lock == null) {
            try {
                m_lock = getCms().getLock(m_resource);
            } catch (Throwable e) {
                m_lock = CmsLock.getNullLock();
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        return m_lock;
    }
715589
public function getNextId()
    {
        try {
            return $this->innerGateway->getNextId();
        } catch (DBALException $e) {
            throw new \RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new \RuntimeException('Database error', 0, $e);
        }
    }
217748
@Nullable
  public String getWaitingLockString(final ThreadInfo threadInfo) {
    if (null == threadInfo.getLockInfo()) {
      return null;
    } else {
      return threadInfo.getLockName() + " held by " + threadInfo.getLockOwnerName();
    }
  }
683965
public String getId()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "getId");
    String id = new Long(_tick).toString();
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "getId", id);
    return id;
  }