@Override public String toString() { return MoreObjects.toStringHelper(getClass().getSimpleName()) .omitNullValues() .add("lockCount", lockMap.size()) .add("firstLock", lockMap.entries().iterator().next()) .add("lockTimeout", lockTimeout) .add("lockGroupBehavior", lockGroupBehavior) .add("blockingMode", blockingMode) .add("blockingDuration", blockingDuration) .add("versionId", versionId) .toString(); }
public static <T> SortedLockCollection<T> of() { return new SortedLockCollection<T>(ImmutableList.<Map.Entry<T, LockMode>>of()); } }
@Override public boolean equals(@Nullable Object obj) { if (this == obj) { return true; } if (!(obj instanceof LockRequest)) { return false; } LockRequest other = (LockRequest) obj; return lockMap.equals(other.lockMap) && lockTimeout.equals(other.lockTimeout) && (lockGroupBehavior == other.lockGroupBehavior) && (blockingMode == other.blockingMode) && Objects.equal(blockingDuration, other.blockingDuration) && Objects.equal(versionId, other.versionId); }
public List<LockWithMode> getLocks() { return ImmutableList.copyOf(Iterables.transform(lockMap.entries(), TO_LOCK_WITH_MODE_FUNCTION)); }
private Builder(SortedLockCollection<LockDescriptor> lockMap) { this.lockMap = lockMap; Preconditions.checkArgument(!this.lockMap.isEmpty()); }
&& (locks.size() < request.getLockDescriptors().size()))) { if (log.isTraceEnabled()) { logNullResponse(client, request, null);
private LockRequest requestContaining(String table) { return argThat( argument -> argument != null && argument.getLockDescriptors().stream() .anyMatch(descriptor -> descriptor.getLockIdAsString().contains(table))); }
public List<LockWithMode> getLocks() { return ImmutableList.copyOf(Iterables.transform(lockMap.entries(), TO_LOCK_WITH_MODE_FUNCTION)); }
/** * Returns the set of locks which were successfully acquired, as a mapping * from descriptor to lock mode. */ @JsonIgnore public SortedLockCollection<LockDescriptor> getLocks() { Preconditions.checkState(!lockMap.isEmpty()); return lockMap; }
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(); }
public List<LockWithMode> getLocksWithMode() { return ImmutableList.copyOf(Iterables.transform(lockMap.entries(), TO_LOCK_WITH_MODE_FUNCTION)); }
/** * 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()); }
public static <T extends Comparable<T>> SortedLockCollection<T> of(SortedMap<T, LockMode> locks) { Preconditions.checkArgument(locks.comparator() == null || locks.comparator() == Ordering.natural(), "sorted lock collections must use naturally comparable keys"); return new SortedLockCollection<T>(locks.entrySet()); }
@Override public boolean equals(@Nullable Object obj) { if (this == obj) { return true; } if (!(obj instanceof LockRequest)) { return false; } LockRequest other = (LockRequest) obj; return lockMap.equals(other.lockMap) && lockTimeout.equals(other.lockTimeout) && (lockGroupBehavior == other.lockGroupBehavior) && (blockingMode == other.blockingMode) && Objects.equal(blockingDuration, other.blockingDuration) && Objects.equal(versionId, other.versionId); }
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(); }
@Override public String toString() { return "SortedLockCollection " + Iterables.toString(entries()); }
/** * This should only be created by the Lock Service. */ public HeldLocksToken(BigInteger tokenId, LockClient client, long creationDateMs, long expirationDateMs, SortedLockCollection<LockDescriptor> lockMap, TimeDuration lockTimeout, @Nullable Long versionId, String requestingThread) { this.tokenId = Preconditions.checkNotNull(tokenId, "tokenId should not be null"); this.client = Preconditions.checkNotNull(client, "client should not be null"); this.creationDateMs = creationDateMs; this.expirationDateMs = expirationDateMs; this.lockMap = lockMap; this.lockTimeout = SimpleTimeDuration.of(lockTimeout); this.versionId = versionId; this.requestingThread = requestingThread; Preconditions.checkArgument(!this.lockMap.isEmpty()); }
public static <T> SortedLockCollection<T> of() { return new SortedLockCollection<T>(ImmutableList.<Map.Entry<T, LockMode>>of()); } }
private LockRequestProgress getSuspectedLockProgress( LockClient client, LockRequest request) { int locksHeld = 0; for (Map.Entry<LockDescriptor, LockMode> entry : request.getLockDescriptors().entries()) { ClientAwareReadWriteLock clientAwareLock = descriptorToLockMap.get(entry.getKey()); KnownClientLock knownClientLock = clientAwareLock.get(client, entry.getValue()); if (!knownClientLock.isHeld()) { return ImmutableLockRequestProgress.builder() .request(request) .nextLock(entry.getKey()) .numLocksAcquired(locksHeld) .totalNumLocks(request.getLockDescriptors().size()) .build(); } locksHeld++; } // This means that it looks like we hold ALL of the locks return ImmutableLockRequestProgress.builder() .request(request) .numLocksAcquired(locksHeld) .totalNumLocks(request.getLockDescriptors().size()) .build(); }
try { previousThreadName = updateThreadName(request); for (Entry<LockDescriptor, LockMode> entry : request.getLockDescriptors().entries()) { if (blockingMode == BlockingMode.BLOCK_INDEFINITELY_THEN_RELEASE && !descriptorToLockMap.asMap().containsKey(entry.getKey())) {