private void checkAgainstQuotedResource()

in server/src/jetbrains/buildServer/sharedResources/server/runtime/TakenLocksImpl.java [264:308]


  private void checkAgainstQuotedResource(@NotNull final Lock lock,
                                          @NotNull final Map<Resource, TakenLock> takenLocks,
                                          @NotNull final QuotedResource resource,
                                          @NotNull final DistributionDataAccessor distributionDataAccessor,
                                          @NotNull final BuildPromotion buildPromotion,
                                          @NotNull final Map<Resource, String> result) {
    final TakenLock takenLock = getOrCreateTakenLock(takenLocks, resource);
    switch (lock.getType()) {
      case READ:
        // some build requested write lock on the current resource before us
        List<BuildPromotion> promosInFairSet = distributionDataAccessor.getFairSet().get(resource.getId());
        if (promosInFairSet != null && !promosInFairSet.isEmpty()) {
          String description = describeLockingPromotions(promosInFairSet);
          result.put(resource, "(write lock requested by " + description + ")");
          break;
        }
        // Check that no WriteLocks exist
        if (takenLock.hasWriteLocks()) {
          String description = describeLockingPromotions(takenLock.getReadLocks().keySet(), takenLock.getWriteLocks().keySet());
          result.put(resource, "(locked by " + description + ")");
          break;
        }
        if (isOverQuota(takenLock, resource)) {
          if (resource.getQuota() == 0) {
            result.put(resource, "(has zero quota available)");
          } else {
            String description = describeLockingPromotions(takenLock.getReadLocks().keySet());
            result.put(resource, "(locked by " + description + ")");
          }
          break;
        }
        break;
      case WRITE:
        // if anyone is accessing the resource
        if (takenLock.hasReadLocks() || takenLock.hasWriteLocks() || isOverQuota(takenLock, resource)) {
          addToFairSet(distributionDataAccessor, resource, buildPromotion);
          if (resource.getQuota() == 0) {
            result.put(resource, "(has zero quota available)");
          } else {
            String description = describeLockingPromotions(takenLock.getReadLocks().keySet(), takenLock.getWriteLocks().keySet());
            result.put(resource, "(locked by " + description + ")");
          }
        }
    }
  }