org.jrabbit.base.data.cache
Class CachePointer<T extends Destroyable & Referenced>

java.lang.Object
  extended by org.jrabbit.base.data.cache.CachePointer<T>
Type Parameters:
T - The type of object this CachePointer is intended to retrieve.
All Implemented Interfaces:
Referenced, Retriever<T>
Direct Known Subclasses:
FontPointer, ImagePointer, SoundPointer

public abstract class CachePointer<T extends Destroyable & Referenced>
extends java.lang.Object
implements Retriever<T>, Referenced

A CachePointer is an object that retrieves an object from one of jRabbit's Caches. A Cache returns the object whose reference matches that of the CachePointer. To provide additional speed above the normal Cache retrieval rate (which does take some time, as it uses Strings for Hash keys), a CachePointer automatically keeps a reference to the object it retrieves from the Cache. This speeds up retrieval time significantly, but it is possible for this reference to become "dirty" (e.g., when the Cache is told to remove and destroy the object). If this happens, you can use refresh() to update the reference. NOTE: CachePointer is an abstract class. The default implementation shown here does not define retrieve(). Extensions of this class need to indicate how they interface with Caches to retrieve data.

Author:
Chris Molini

Field Summary
protected  T object
          The stored object reference.
protected  java.lang.String reference
          The string identifier that tells the cache which element we wish to use.
 
Constructor Summary
CachePointer(java.lang.String reference)
          Creates a CachePointer that will retrieve the object specified by the parameter.
 
Method Summary
 T object()
          Returns the object the CachePointer has retrieved.
 java.lang.String reference()
          Returns the identifier the CachePointer is looking for.
 void refresh()
          Updates the stored object reference to reflect the contents of the cache.
 void setReference(java.lang.String reference)
          Redefines what the CachePointer needs to search for and refreshes the stored object.
 boolean valid()
          Checks to see if the stored object reference is non-null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jrabbit.base.data.Retriever
retrieve
 

Field Detail

object

protected T extends Destroyable & Referenced object
The stored object reference.


reference

protected java.lang.String reference
The string identifier that tells the cache which element we wish to use.

Constructor Detail

CachePointer

public CachePointer(java.lang.String reference)
Creates a CachePointer that will retrieve the object specified by the parameter.

Parameters:
reference - The identifier that will tell the Cache which object to retrieve.
Method Detail

reference

public java.lang.String reference()
Returns the identifier the CachePointer is looking for.

Specified by:
reference in interface Referenced
Returns:
The reference that matches that of the desired object in the Cache.

setReference

public void setReference(java.lang.String reference)
Redefines what the CachePointer needs to search for and refreshes the stored object.

Parameters:
reference - The new reference to search for.

object

public T object()
Returns the object the CachePointer has retrieved. NOTE: Theoretically, this can return a reference to an object that has been destroyed in the cache, since using this method doesn't actually check.

Returns:
The stored object the CachePointer retrieves.

refresh

public void refresh()
Updates the stored object reference to reflect the contents of the cache.


valid

public boolean valid()
Checks to see if the stored object reference is non-null.

Returns:
True if the reference points to an object in memory, false otherwise.