ehcache

net.sf.ehcache.store.compound.factories
Class CapacityLimitedInMemoryFactory

java.lang.Object
  extended by net.sf.ehcache.store.compound.factories.CapacityLimitedInMemoryFactory
All Implemented Interfaces:
IdentityElementSubstituteFactory

public class CapacityLimitedInMemoryFactory
extends Object
implements IdentityElementSubstituteFactory

An implementation of a capacity limited in-memory factory.

Author:
Chris Dennis

Constructor Summary
CapacityLimitedInMemoryFactory(DiskOverflowStorageFactory secondary, int capacity, Policy policy, RegisteredEventListeners eventService)
          Constructs a factory with the given secondary (null if none), capacity, and eviction policy.
 
Method Summary
 void bind(CompoundStore store)
          Bind a store instance to this factory.
 Element create(Object key, Element element)
          Creates a substitute for the supplied Element
 boolean created(Object object)
          Returns true if this factory created the given object.
 void expireElements()
          Remove elements created by this factory if they have expired.
 void free(Lock exclusion, Element object)
          Free any manually managed resources used by this Element or ElementSubstitute.
 Policy getEvictionPolicy()
          Return the eviction policy used by this factory.
 int getSize()
          Get the count of elements created by this factory
 long getSizeInBytes()
          Get the total serialized size of all elements created by this factory
 Element retrieve(Object key, Element object)
          Retrieves the supplied Element or ElementSubstitute.
 void setCapacity(int capacity)
          Set the maximum capacity of this factory.
 void setEvictionPolicy(Policy policy)
          Set the eviction policy used by this factory.
 void unbind(CompoundStore store)
          Unbinds a store instance from this factory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CapacityLimitedInMemoryFactory

public CapacityLimitedInMemoryFactory(DiskOverflowStorageFactory secondary,
                                      int capacity,
                                      Policy policy,
                                      RegisteredEventListeners eventService)
Constructs a factory with the given secondary (null if none), capacity, and eviction policy.

Parameters:
secondary - factory to evict through
capacity - maximum capacity
policy - policy to use on eviction
Method Detail

bind

public void bind(CompoundStore store)
Bind a store instance to this factory.

Parameters:
store - store to bind

unbind

public void unbind(CompoundStore store)
Unbinds a store instance from this factory

Parameters:
store - store to unbind

create

public Element create(Object key,
                      Element element)
Creates a substitute for the supplied Element

In the case that this element is no longer mapped to a key - if for example the element is being decoded following a removal - then the supplied key will be null.

Parameters:
key - key to which this element is mapped
element - Element to encode
Returns:
The potentially substitute Element

retrieve

public Element retrieve(Object key,
                        Element object)
Retrieves the supplied Element or ElementSubstitute.

Parameters:
key - key to which this element is mapped
object - Element or ElementSubstitute to retrieve
Returns:
a decoded Element

free

public void free(Lock exclusion,
                 Element object)
Free any manually managed resources used by this Element or ElementSubstitute.

object - Element or ElementSubstitute being free'd.

getSize

public int getSize()
Get the count of elements created by this factory


getSizeInBytes

public long getSizeInBytes()
Get the total serialized size of all elements created by this factory


getEvictionPolicy

public Policy getEvictionPolicy()
Return the eviction policy used by this factory.


setEvictionPolicy

public void setEvictionPolicy(Policy policy)
Set the eviction policy used by this factory.


setCapacity

public void setCapacity(int capacity)
Set the maximum capacity of this factory.


created

public boolean created(Object object)
Returns true if this factory created the given object.

Parameters:
object - object to check
Returns:
true if object created by this factory

expireElements

public void expireElements()
Remove elements created by this factory if they have expired.


ehcache

true