public <T,X extends Throwable>T reserveResources(String accountId,List<ResourceImpl> resources,ResourceUsageOperation<T,X> operation) throws X, NotFoundException, ServerException, ConflictException {
  final Lock lock=RESOURCES_LOCKS.get(accountId);
  lock.lock();
  try {
    List<ResourceImpl> availableResources=doGetAvailableResources(accountId);
    resourceAggregator.deduct(availableResources,resources);
    return operation.use();
  }
  finally {
    lock.unlock();
  }
}

public < T , X extends Throwable > T reserveResources ( String accountId , List < ResourceImpl > resources , ResourceUsageOperation < T , X > operation ) throws X , NotFoundException , ServerException , ConflictException { final Lock lock = RESOURCES_LOCKS . get ( accountId ) ; lock . lock ( ) ; try { List < ResourceImpl > availableResources = doGetAvailableResources ( accountId ) ; resourceAggregator . deduct ( availableResources , resources ) ; return operation . use ( ) ; } finally { lock . unlock ( ) ; } }
reserve resources for usage . < p > note : should be invoked while consuming operation starts
