boolean acquired = false;
try {
acquired = amountRemaining.tryAcquire(neededForRequest, TIME_TO_WAIT, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RejectRequestException("Was interupted", e);
}
int remaining = amountRemaining.availablePermits();
if (acquired) {
log.info("Target available memory was " + (neededForRequest + remaining) + "mb is now "
+ remaining + "mb");
return neededForRequest;
} else {
throw new RejectRequestException("Not enough estimated memory for request: "
+ (neededForRequest) + "mb only have " + remaining + "mb remaining out of "
+ TOTAL_CLAIMABLE_MEMORY_SIZE_MB + "mb");
}
}