/** * {@inheritDoc} */ protected long add(long sizeOf, boolean force) throws IllegalArgumentException { if (sizeOf < 0L) { throw new IllegalArgumentException("cannot add negative size"); } long newSize = getPool().getSize() + sizeOf; if (newSize <= getPool().getMaxSize()) { // there is enough room => add & approve size.addAndGet(sizeOf); return sizeOf; } else { // check that the element isn't too big if (!force && sizeOf > getPool().getMaxSize()) { // this is too big to fit in the pool return -1; } // if there is not enough room => evict long missingSize = newSize - getPool().getMaxSize(); if (getPool().getEvictor().freeSpace(getPool().getPoolAccessors(), missingSize) || force) { size.addAndGet(sizeOf); return sizeOf; } else { // cannot free enough bytes return -1; } } }
/** * {@inheritDoc} */ protected long add(long sizeOf, boolean force) { long newSize = getPool().getSize() + sizeOf; if (newSize <= getPool().getMaxSize()) { // there is enough room => add & approve size.addAndGet(sizeOf); return sizeOf; } else { // check that the element isn't too big if (!force && sizeOf > getPool().getMaxSize()) { // this is too big to fit in the pool return -1; } // if there is not enough room => evict long missingSize = newSize - getPool().getMaxSize(); if (getPool().getEvictor().freeSpace(getPool().getPoolableStores(), missingSize) || force) { size.addAndGet(sizeOf); return sizeOf; } else { // cannot free enough bytes return -1; } } }
/** * {@inheritDoc} */ protected long add(long sizeOf, boolean force) throws IllegalArgumentException { if (sizeOf < 0L) { throw new IllegalArgumentException("cannot add negative size"); } long newSize = getPool().getSize() + sizeOf; if (newSize <= getPool().getMaxSize()) { // there is enough room => add & approve size.addAndGet(sizeOf); return sizeOf; } else { // check that the element isn't too big if (!force && sizeOf > getPool().getMaxSize()) { // this is too big to fit in the pool return -1; } // if there is not enough room => evict long missingSize = newSize - getPool().getMaxSize(); if (getPool().getEvictor().freeSpace(getPool().getPoolAccessors(), missingSize) || force) { size.addAndGet(sizeOf); return sizeOf; } else { // cannot free enough bytes return -1; } } }
/** * {@inheritDoc} */ protected long add(long sizeOf, boolean force) throws IllegalArgumentException { if (sizeOf < 0L) { throw new IllegalArgumentException("cannot add negative size"); } long newSize = getPool().getSize() + sizeOf; if (newSize <= getPool().getMaxSize()) { // there is enough room => add & approve size.addAndGet(sizeOf); return sizeOf; } else { // check that the element isn't too big if (!force && sizeOf > getPool().getMaxSize()) { // this is too big to fit in the pool return -1; } // if there is not enough room => evict long missingSize = newSize - getPool().getMaxSize(); if (getPool().getEvictor().freeSpace(getPool().getPoolAccessors(), missingSize) || force) { size.addAndGet(sizeOf); return sizeOf; } else { // cannot free enough bytes return -1; } } }