Package net.sf.ehcache.pool.impl
Class AbstractPoolAccessor
- java.lang.Object
-
- net.sf.ehcache.pool.impl.AbstractPoolAccessor
-
- All Implemented Interfaces:
PoolAccessor<PoolParticipant>
public abstract class AbstractPoolAccessor extends java.lang.Object implements PoolAccessor<PoolParticipant>
Abstract PoolAccessor implementation providing pool to store binding functionality.- Author:
- Chris Dennis, Alex Snaps
-
-
Field Summary
Fields Modifier and Type Field Description protected SizeOfEnginesizeOfEngineSizeOfEngineused by the accessor.
-
Constructor Summary
Constructors Constructor Description AbstractPoolAccessor(Pool pool, PoolParticipant participant, SizeOfEngine sizeOfEngine)Creates an accessor for the specified participant to access the specified pool.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract longadd(long sizeOf, boolean force)Add a specific number of bytes to the pool.longadd(java.lang.Object key, java.lang.Object value, java.lang.Object container, boolean force)Add an element to the pool.protected abstract booleancanAddWithoutEvicting(long sizeOf)Check if there is enough room in the pool to add a specific number of bytes without provoking any evictionbooleancanAddWithoutEvicting(java.lang.Object key, java.lang.Object value, java.lang.Object container)Check if there is enough room in the pool to add an element without provoking any evictionprotected voidcheckLinked()ThrowsIllegalStateExceptionif this accessor is not linked to it's pool.voidclear()Free resources used by this accessor.protected abstract voiddoClear()Free resources used by this accessor.PoolParticipantgetParticipant()Return the store that uses this accessorprotected PoolgetPool()Return the pool this accessor is associated with.longgetPoolOccupancy()Returns the occupied size for this pool.longgetPoolSize()Returns the size of this pool.booleanhasAbortedSizeOf()Check if the store may contain elements which the SizeOf engine could not fully size.longreplace(long currentSize, java.lang.Object key, java.lang.Object value, java.lang.Object container, boolean force)Delete a fixed number of bytes from the pool with the given objects.voidsetMaxSize(long newValue)Sets the max size for this poolvoidunlink()unlink this PoolAccessor from its pool.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.ehcache.pool.PoolAccessor
delete, getSize
-
-
-
-
Field Detail
-
sizeOfEngine
protected final SizeOfEngine sizeOfEngine
SizeOfEngineused by the accessor.
-
-
Constructor Detail
-
AbstractPoolAccessor
public AbstractPoolAccessor(Pool pool, PoolParticipant participant, SizeOfEngine sizeOfEngine)
Creates an accessor for the specified participant to access the specified pool.- Parameters:
pool- pool to be accessedparticipant- accessing participant
-
-
Method Detail
-
add
public final long add(java.lang.Object key, java.lang.Object value, java.lang.Object container, boolean force)Add an element to the pool.- Specified by:
addin interfacePoolAccessor<PoolParticipant>- Parameters:
key- the key of the elementvalue- the value of the elementcontainer- the element-container objectforce- true if the pool should accept adding the element, even if it's out of resources- Returns:
- how many bytes have been added to the pool or -1 if add failed.
-
canAddWithoutEvicting
public final boolean canAddWithoutEvicting(java.lang.Object key, java.lang.Object value, java.lang.Object container)Check if there is enough room in the pool to add an element without provoking any eviction- Specified by:
canAddWithoutEvictingin interfacePoolAccessor<PoolParticipant>- Parameters:
key- the key of the elementvalue- the value of the elementcontainer- the element-container object- Returns:
- true if there is enough room left
-
add
protected abstract long add(long sizeOf, boolean force) throws java.lang.IllegalArgumentExceptionAdd a specific number of bytes to the pool.- Parameters:
sizeOf- number of bytes to addforce- true if the pool should accept adding the element, even if it's out of resources- Returns:
- how many bytes have been added to the pool or -1 if add failed.
- Throws:
java.lang.IllegalArgumentException- when sizeOf is negative
-
canAddWithoutEvicting
protected abstract boolean canAddWithoutEvicting(long sizeOf)
Check if there is enough room in the pool to add a specific number of bytes without provoking any eviction- Parameters:
sizeOf- number of bytes to test against- Returns:
- true if there is enough room left
-
replace
public final long replace(long currentSize, java.lang.Object key, java.lang.Object value, java.lang.Object container, boolean force)Delete a fixed number of bytes from the pool with the given objects.- Specified by:
replacein interfacePoolAccessor<PoolParticipant>- Parameters:
currentSize- the size of the object(s) being replacedkey- the key of the elementvalue- the value of the elementcontainer- the element-container objectforce- true if the pool should accept replacing the element, even if it's out of resources- Returns:
- the change in size of the pool, or
Long.MIN_VALUEif replace failed.
-
clear
public final void clear()
Free resources used by this accessor.- Specified by:
clearin interfacePoolAccessor<PoolParticipant>
-
doClear
protected abstract void doClear()
Free resources used by this accessor. This method is called byclear().
-
unlink
public final void unlink()
unlink this PoolAccessor from its pool.- Specified by:
unlinkin interfacePoolAccessor<PoolParticipant>
-
getParticipant
public final PoolParticipant getParticipant()
Return the store that uses this accessor- Specified by:
getParticipantin interfacePoolAccessor<PoolParticipant>- Returns:
- store using this accessor
-
setMaxSize
public void setMaxSize(long newValue)
Sets the max size for this pool- Specified by:
setMaxSizein interfacePoolAccessor<PoolParticipant>- Parameters:
newValue- the value in bytes
-
getPoolOccupancy
public long getPoolOccupancy()
Returns the occupied size for this pool.- Specified by:
getPoolOccupancyin interfacePoolAccessor<PoolParticipant>- Returns:
- occupied pool size
-
getPoolSize
public long getPoolSize()
Returns the size of this pool.- Specified by:
getPoolSizein interfacePoolAccessor<PoolParticipant>- Returns:
- pool size
-
checkLinked
protected final void checkLinked() throws java.lang.IllegalStateExceptionThrowsIllegalStateExceptionif this accessor is not linked to it's pool.- Throws:
java.lang.IllegalStateException- if not linked
-
getPool
protected final Pool getPool()
Return the pool this accessor is associated with.- Returns:
- associated pool
-
hasAbortedSizeOf
public boolean hasAbortedSizeOf()
Check if the store may contain elements which the SizeOf engine could not fully size.- Specified by:
hasAbortedSizeOfin interfacePoolAccessor<PoolParticipant>- Returns:
- true if the store may contain partially sized objects
-
-