示例#1
0
 public LockResult refreshLock(String token) {
   if (lock == null) throw new RuntimeException("not locked");
   if (!lock.lockId.equals(token)) throw new RuntimeException("invalid lock id");
   this.lock = lock.refresh();
   LockToken tok = makeToken();
   return LockResult.success(tok);
 }
示例#2
0
  public LockResult lock(LockTimeout timeout, LockInfo lockInfo) {
    System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  locking");
    //        if( lock != null ) {
    //            // todo
    //            throw new RuntimeException("already locked");
    //        }

    LockTimeout.DateAndSeconds lockedUntil = timeout.getLockedUntil(60l, 3600l);

    this.lock =
        new TLock(lockedUntil.date, UUID.randomUUID().toString(), lockedUntil.seconds, lockInfo);

    LockToken token = new LockToken();
    token.info = lockInfo;
    token.timeout = new LockTimeout(lockedUntil.seconds);
    token.tokenId = this.lock.lockId;

    return LockResult.success(token);
  }