ehcache

net.sf.ehcache.pool.impl
Class AbstractPoolAccessor

java.lang.Object
  extended by net.sf.ehcache.pool.impl.AbstractPoolAccessor
All Implemented Interfaces:
PoolAccessor<PoolParticipant>

public abstract class AbstractPoolAccessor
extends Object
implements PoolAccessor<PoolParticipant>

Abstract PoolAccessor implementation providing pool to store binding functionality.

Author:
Chris Dennis, Alex Snaps

Field Summary
protected  SizeOfEngine sizeOfEngine
          SizeOfEngine used by the accessor.
 
Constructor Summary
AbstractPoolAccessor(Pool pool, PoolParticipant participant, SizeOfEngine sizeOfEngine)
          Creates an accessor for the specified participant to access the specified pool.
 
Method Summary
protected abstract  long add(long sizeOf, boolean force)
          Add a specific number of bytes to the pool.
 long add(Object key, Object value, Object container, boolean force)
          Add an element to the pool.
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
 boolean canAddWithoutEvicting(Object key, Object value, Object container)
          Check if there is enough room in the pool to add an element without provoking any eviction
protected  void checkLinked()
          Throws IllegalStateException if this accessor is not linked to it's pool.
 void clear()
          Free resources used by this accessor.
protected abstract  void doClear()
          Free resources used by this accessor.
 PoolParticipant getParticipant()
          Return the store that uses this accessor
protected  Pool getPool()
          Return the pool this accessor is associated with.
 long getPoolOccupancy()
          Returns the occupied size for this pool.
 long getPoolSize()
          Returns the size of this pool.
 boolean hasAbortedSizeOf()
          Check if the store may contain elements which the SizeOf engine could not fully size.
 long replace(long currentSize, Object key, Object value, Object container, boolean force)
          Delete a fixed number of bytes from the pool with the given objects.
 void setMaxSize(long newValue)
          Sets the max size for this pool
 void unlink()
          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
SizeOfEngine used 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 accessed
participant - accessing participant
Method Detail

add

public final long add(Object key,
                      Object value,
                      Object container,
                      boolean force)
Add an element to the pool.

Specified by:
add in interface PoolAccessor<PoolParticipant>
Parameters:
key - the key of the element
value - the value of the element
container - the element-container object
force - 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(Object key,
                                           Object value,
                                           Object container)
Check if there is enough room in the pool to add an element without provoking any eviction

Specified by:
canAddWithoutEvicting in interface PoolAccessor<PoolParticipant>
Parameters:
key - the key of the element
value - the value of the element
container - the element-container object
Returns:
true if there is enough room left

add

protected abstract long add(long sizeOf,
                            boolean force)
                     throws IllegalArgumentException
Add a specific number of bytes to the pool.

Parameters:
sizeOf - number of bytes to add
force - 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:
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,
                          Object key,
                          Object value,
                          Object container,
                          boolean force)
Delete a fixed number of bytes from the pool with the given objects.

Specified by:
replace in interface PoolAccessor<PoolParticipant>
Parameters:
currentSize - the size of the object(s) being replaced
key - the key of the element
value - the value of the element
container - the element-container object
force - 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_VALUE if replace failed.

clear

public final void clear()
Free resources used by this accessor.

Specified by:
clear in interface PoolAccessor<PoolParticipant>

doClear

protected abstract void doClear()
Free resources used by this accessor. This method is called by clear().


unlink

public final void unlink()
unlink this PoolAccessor from its pool.

Specified by:
unlink in interface PoolAccessor<PoolParticipant>

getParticipant

public final PoolParticipant getParticipant()
Return the store that uses this accessor

Specified by:
getParticipant in interface PoolAccessor<PoolParticipant>
Returns:
store using this accessor

setMaxSize

public void setMaxSize(long newValue)
Sets the max size for this pool

Specified by:
setMaxSize in interface PoolAccessor<PoolParticipant>
Parameters:
newValue - the value in bytes

getPoolOccupancy

public long getPoolOccupancy()
Returns the occupied size for this pool.

Specified by:
getPoolOccupancy in interface PoolAccessor<PoolParticipant>
Returns:
occupied pool size

getPoolSize

public long getPoolSize()
Returns the size of this pool.

Specified by:
getPoolSize in interface PoolAccessor<PoolParticipant>
Returns:
pool size

checkLinked

protected final void checkLinked()
                          throws IllegalStateException
Throws IllegalStateException if this accessor is not linked to it's pool.

Throws:
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:
hasAbortedSizeOf in interface PoolAccessor<PoolParticipant>
Returns:
true if the store may contain partially sized objects

ehcache

Copyright 2001-2014, Terracotta, Inc.