Exemple #1
0
  @Override
  public void validateIfLocked(final ILockKey context, Optional<ILock> heldLock)
      throws LockException {

    Optional<ILock> stored =
        storage.read(storeProvider -> storeProvider.getLockStore().fetchLock(context));

    // The implementation below assumes the following use cases:
    // +-----------+-----------------+----------+
    // |   eq      |     held        | not held |
    // +-----------+-----------------+----------+
    // |stored     |(stored == held)?| invalid  |
    // +-----------+-----------------+----------+
    // |not stored |    invalid      |  valid   |
    // +-----------+-----------------+----------+
    if (!stored.equals(heldLock)) {
      if (stored.isPresent()) {
        throw new LockException(
            String.format(
                "Unable to perform operation for: %s. Use override/cancel option.",
                formatLockKey(context)));
      } else if (heldLock.isPresent()) {
        throw new LockException(
            String.format("Invalid operation context: %s", formatLockKey(context)));
      }
    }
  }
Exemple #2
0
 /**
  * Computes total quota allocations.
  *
  * @return Total allocated quota.
  * @throws StorageException if there was a problem fetching quotas from storage.
  */
 public Metric computeQuotaAllocationTotals() throws StorageException {
   return storage.read(
       storeProvider -> {
         Metric allocation = new Metric();
         for (IResourceAggregate quota : storeProvider.getQuotaStore().fetchQuotas().values()) {
           allocation.accumulate(quota);
         }
         return allocation;
       });
 }
Exemple #3
0
 @Override
 public Iterable<ILock> getLocks() {
   return storage.read(storeProvider -> storeProvider.getLockStore().fetchLocks());
 }