Object readResolve() { return of(time, unit); } }
@JsonCreator public static SimpleTimeDuration of(@JsonProperty("time") long time, @JsonProperty("unit") TimeUnit unit) { return new SimpleTimeDuration(time, unit); }
@Override public int hashCode() { return Objects.hashCode(toNanos()); }
private void logIfAbnormallyOld(ExpiringToken token, long now, Supplier<String> description) { if (log.isInfoEnabled()) { long age = now - token.getCreationDateMs(); if (age > maxNormalLockAge.toMillis()) { log.debug("Token refreshed which is {} ms old: {}", SafeArg.of("ageMillis", age), UnsafeArg.of("description", description.get())); } } }
token = queue.take(); long timeUntilTokenExpiredMs = token.getExpirationDateMs() - currentTimeMillis() + maxAllowedClockDrift.toMillis(); long sleepTimeMs = Math.min(timeUntilTokenExpiredMs, maxAllowedClockDrift.toMillis()); if (sleepTimeMs > 0) { Thread.sleep(sleepTimeMs); - maxAllowedClockDrift.toMillis()) { queue.add(realToken); } else {
public String toString(long currentTimeMillis) { return MoreObjects.toStringHelper(getClass().getSimpleName()) .add("grantId", grantId.toString(Character.MAX_RADIX)) .add("createdAt", SimpleTimeDuration.of(creationDateMs, TimeUnit.MILLISECONDS)) .add("expiresIn", SimpleTimeDuration.of(expirationDateMs, TimeUnit.MILLISECONDS)) .add("lockCount", lockMap.size()) .add("firstLock", lockMap.entries().iterator().next()) .add("versionId", versionId) .toString(); }
@Override public boolean equals(@Nullable Object obj) { if (obj == this) { return true; } if (!(obj instanceof TimeDuration)) { return false; } return toNanos() == ((TimeDuration) obj).toNanos(); }
public static SimpleTimeDuration of(TimeDuration duration) { Preconditions.checkNotNull(duration, "duration should not be null"); if (duration instanceof SimpleTimeDuration) { return (SimpleTimeDuration) duration; } return new SimpleTimeDuration(duration.getTime(), duration.getUnit()); }
/** * Returns the maximum amount of time that can be passed to * {@link LockRequest.Builder#timeoutAfter(TimeDuration)}. The default value * is 10 minutes. */ @Value.Default public TimeDuration getMaxAllowedLockTimeout() { return SimpleTimeDuration.of(10, TimeUnit.MINUTES); }
@Override public int compareTo(TimeDuration other) { return Longs.compare(toNanos(), other.toNanos()); }
@JsonCreator public static SimpleTimeDuration of(@JsonProperty("time") long time, @JsonProperty("unit") TimeUnit unit) { return new SimpleTimeDuration(time, unit); }
/** * Returns the maximum permitted clock drift between the server and any * client. The default value is 5 seconds. */ @Value.Default public TimeDuration getMaxAllowedClockDrift() { return SimpleTimeDuration.of(5, TimeUnit.SECONDS); }
@Override public int hashCode() { return Objects.hashCode(toNanos()); }
public static SimpleTimeDuration of(TimeDuration duration) { Preconditions.checkNotNull(duration, "duration should not be null"); if (duration instanceof SimpleTimeDuration) { return (SimpleTimeDuration) duration; } return new SimpleTimeDuration(duration.getTime(), duration.getUnit()); }
/** * Returns the maximum amount of time a lock is usually held for. * The default value is 1 hour. */ @Value.Default public TimeDuration getMaxNormalLockAge() { return SimpleTimeDuration.of(1, TimeUnit.HOURS); }
@Override public boolean equals(@Nullable Object obj) { if (obj == this) { return true; } if (!(obj instanceof TimeDuration)) { return false; } return toNanos() == ((TimeDuration) obj).toNanos(); }
/** * Returns the maximum amount of time that may be passed to * {@link LockRequest.Builder#blockForAtMost(TimeDuration)}. The default * value is 60 seconds. * * @deprecated this value is no longer used or respected. */ @Deprecated @Value.Default public TimeDuration getMaxAllowedBlockingDuration() { return SimpleTimeDuration.of(60, TimeUnit.SECONDS); }
@Override public int compareTo(TimeDuration other) { return Longs.compare(toNanos(), other.toNanos()); }
public String toString(long currentTimeMillis) { return MoreObjects.toStringHelper(getClass().getSimpleName()) .add("tokenId", tokenId.toString(Character.MAX_RADIX)) .add("client", client) .add("createdAt", SimpleTimeDuration.of(creationDateMs, TimeUnit.MILLISECONDS)) .add("expiresIn", SimpleTimeDuration.of(expirationDateMs - currentTimeMillis, TimeUnit.MILLISECONDS)) .add("lockCount", lockMap.size()) .add("firstLock", lockMap.entries().iterator().next()) .add("versionId", versionId) .add("requestingThread", requestingThread) .toString(); }
/** * These grants should not be constructed by users. Only the lock service should hand them out. */ public HeldLocksGrant(BigInteger grantId, long creationDateMs, long expirationDateMs, SortedLockCollection<LockDescriptor> lockMap, TimeDuration lockTimeout, @Nullable Long versionId) { this.grantId = Preconditions.checkNotNull(grantId, "grantId should not be null"); this.creationDateMs = creationDateMs; this.expirationDateMs = expirationDateMs; this.lockMap = lockMap; this.lockTimeout = SimpleTimeDuration.of(lockTimeout); this.versionId = versionId; Preconditions.checkArgument(!this.lockMap.isEmpty()); }