コード例 #1
0
ファイル: LockManagerImpl.java プロジェクト: pirater/aurora
  @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)));
      }
    }
  }
コード例 #2
0
ファイル: ResourceCounter.java プロジェクト: pirater/aurora
 /**
  * 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;
       });
 }
コード例 #3
0
ファイル: LockManagerImpl.java プロジェクト: pirater/aurora
 @Override
 public Iterable<ILock> getLocks() {
   return storage.read(storeProvider -> storeProvider.getLockStore().fetchLocks());
 }