/** * {@inheritDoc} */ public boolean freeSpace(Collection<PoolableStore> from, long bytes) { if (from == null || from.isEmpty()) { return false; } long remainingSizeInBytes = bytes; Collection<PoolableStore> tried = new ArrayList<PoolableStore>(); while (tried.size() != from.size()) { PoolableStore largestPoolableStore = findUntriedLargestPoolableStore(from, tried); long beforeEvictionSize = getSizeInBytes(largestPoolableStore); if (!evict(1, bytes, largestPoolableStore)) { tried.add(largestPoolableStore); continue; } long afterEvictionSize = getSizeInBytes(largestPoolableStore); remainingSizeInBytes -= (beforeEvictionSize - afterEvictionSize); if (remainingSizeInBytes <= 0L) { return true; } } return false; }