wt.fc.cache
Class ReferenceCache

java.lang.Object
  extended bywt.fc.cache.ReferenceCache

public final class ReferenceCache
extends Object

The ReferenceCache uses a cache table to configure Persistable-to-Cache mappings. At a minimum, service.properties should could contain the following: wt.services/rsc/default/ObjectReferenceCacheTable/null/wt.admin.AdministrativeDomain/0=DomainCache wt.services/rsc/default/ObjectReferenceCacheTable/null/wt.fc.Persistable/0=DefaultCache wt.services/rsc/default/ObjectReferenceCacheTable/null/wt.inf.container.WTContainer/5=ContainerCache wt.services/rsc/default/ObjectReferenceCacheTable/ReportInterval/null/0=0 wt.services/rsc/default/ObjectReferenceCacheTable/Size/null/0=200

Supported API: false

Extendable: false


Nested Class Summary
static class ReferenceCache.ObjectReferenceCacheMessenger
          Signals remote method servers of a modified Persistable by istening for changes to the local cache
(package private)  class ReferenceCache.ObjectReferenceCacheTable
          An extension of CacheTable that maintains a mapping of Long oids to their corresponding cache.
private static class ReferenceCache.RemotePlaceholder
          A utility class that allows the cache to signal whether a remote call is necessary when an object is added to the local cache
private static class ReferenceCache.Singleton
          Provides thread-safe lazy initialization of the cache
 
Field Summary
private  ReferenceCache.ObjectReferenceCacheTable cacheTable
          Maintains the local caches of Persistables
private static String CLASSNAME
           
private static boolean DEBUG
           
private static DebugWriter LOG
           
private  ReferenceCache.ObjectReferenceCacheMessenger messenger
          Local instance of the messenger, that registers with the local caches
private  ReferenceResolver resolver
          Used to determine what the subtypes of CachedObjectReference are
 
Constructor Summary
private ReferenceCache()
          Called from the thread-safe Singleton static initializer
 
Method Summary
 void clear()
          Clears the contents of this cache.
protected  Persistable get(CachedObjectReference ref)
          Retrieves the Persistable for the given object reference
static ReferenceCache getInstance()
          Returns a reference to the cache instance
 Persistable getLocal(ObjectIdentifier oid)
          Retrieves the Persistable for the given object identifier, IFF the persistable is currently cached
 boolean isTarget(Class c)
          Determines if the given persistable class should be cached by the reference cache
 void remove(ObjectIdentifier oid)
          Notifies the cache that the given ObjectIdentifier has been removed.
 void remove(Persistable target)
          Notifies the cache that the given Persistable has been removed.
 void remove(WTCollection targets)
          Notifies the cache that the given collection of ObjectIdentifier objects have been removed.
 void update(Persistable target)
          Notifies the cache that the given Persistable has been updated.
 void update(Persistable copy, Persistable read_only)
          Updates the given Persistable, iff read_only still maps to the object's oid when the transaction commits.
 void update(WTCollection targets)
          Notifies the cache that the given collection of Persistables have been updated.
private  void update(WTCollection targets, boolean local)
          Private method used by both flavors of update
 void updateLocal(WTCollection targets)
          Notifies the cache that the given collection of Persistables have been updated.
protected  void writeContents(Writer w)
          Prints debug information to the writer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSNAME

private static final String CLASSNAME

DEBUG

private static final boolean DEBUG

LOG

private static final DebugWriter LOG

resolver

private final ReferenceResolver resolver
Used to determine what the subtypes of CachedObjectReference are


messenger

private final ReferenceCache.ObjectReferenceCacheMessenger messenger
Local instance of the messenger, that registers with the local caches


cacheTable

private final ReferenceCache.ObjectReferenceCacheTable cacheTable
Maintains the local caches of Persistables

Constructor Detail

ReferenceCache

private ReferenceCache()
Called from the thread-safe Singleton static initializer

Method Detail

getInstance

public static final ReferenceCache getInstance()
Returns a reference to the cache instance

Returns:
The single instance of the cache

getLocal

public Persistable getLocal(ObjectIdentifier oid)
                     throws WTException
Retrieves the Persistable for the given object identifier, IFF the persistable is currently cached

Returns:
A read-only copy of the cached persistable, or null if it isn't cached
Throws:
WTException

get

protected Persistable get(CachedObjectReference ref)
                   throws WTException
Retrieves the Persistable for the given object reference

Returns:
A cached copy of the Persistable
Throws:
WTException

update

public void update(Persistable target)
            throws WTException
Notifies the cache that the given Persistable has been updated. The cache will maintain a thread-local copy of the Persistable until the current transaction is committed or rolled back

Throws:
WTException

update

public void update(WTCollection targets)
            throws WTException
Notifies the cache that the given collection of Persistables have been updated. The cache will maintain thread-local copies of the Persistable objects until the current transaction is committed or rolled back

Throws:
WTException

updateLocal

public void updateLocal(WTCollection targets)
                 throws WTException
Notifies the cache that the given collection of Persistables have been updated. The cache will maintain thread-local copies of the Persistable objects until the current transaction is committed or rolled back

Unlike update, remote caches are not signaled by this method. Remote caches don't need to be signaled if we just want to ensure that the object is in the local cache, or that the in-memory state of the object is up to date.

Throws:
WTException

update

private void update(WTCollection targets,
                    boolean local)
             throws WTException
Private method used by both flavors of update

Parameters:
targets -
local -
Throws:
WTException

isTarget

public boolean isTarget(Class c)
Determines if the given persistable class should be cached by the reference cache

Parameters:
c - The persistable class that you want to find out whether or not it should be cached
Returns:
boolean

update

public void update(Persistable copy,
                   Persistable read_only)
            throws WTException
Updates the given Persistable, iff read_only still maps to the object's oid when the transaction commits. This can be used to keep an object's in-memory non-persistent state safely cached as follows: ObjectIdentifier oid = getOidOfObjectToUpdate(); // use appropriate subclass constructor CachedObjectReference ref = CacheObjectReference.newCachedObjectReference(oid); // call getReadOnly -before- calling getObject. // otherwise, getReadOnly returns the cloned result of getObject Persistable read_only = ref.getReadOnlyObject(); Persistable copy = ref.getObject(); // copy any nonpersistent state from the read only obj to the copy copy.nonPersistentState = read_only.nonPersistentState; // now update the copy's non-persistent state copy.nonPersistentState += updateNonPersistentState(); // finally, update the cache as long as another thread hasn't // added a new version of the read only object ReferenceCache.getInstance().update(copy, read_only);

Throws:
WTException

remove

public void remove(Persistable target)
            throws WTException
Notifies the cache that the given Persistable has been removed. The cache will maintain thread-local knowledge of the remove until the current transaction is committed or rolled back

Throws:
WTException

remove

public void remove(ObjectIdentifier oid)
            throws WTException
Notifies the cache that the given ObjectIdentifier has been removed. The cache will maintain thread-local knowledge of the remove until the current transaction is committed or rolled back

Throws:
WTException

remove

public void remove(WTCollection targets)
            throws WTException
Notifies the cache that the given collection of ObjectIdentifier objects have been removed. The cache will maintain thread-local knowledge of the remove until the current transaction is committed or rolled back

Throws:
WTException

writeContents

protected void writeContents(Writer w)
                      throws IOException
Prints debug information to the writer

Throws:
IOException

clear

public void clear()
           throws WTException
Clears the contents of this cache. Doesn't signal remote caches

Throws:
WTException