com.bigdata.relation.locator
Class AbstractCachingResourceLocator<T extends ILocatableResource>

java.lang.Object
  extended by com.bigdata.relation.locator.AbstractCachingResourceLocator<T>
All Implemented Interfaces:
IResourceLocator<T>
Direct Known Subclasses:
DefaultResourceLocator

public abstract class AbstractCachingResourceLocator<T extends ILocatableResource>
extends Object
implements IResourceLocator<T>

Abstract base class for IResourceLocators with caching. The cache uses WeakReferences so that cache entries will be cleared if the referenced item is cleared.

Version:
$Id: AbstractCachingResourceLocator.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Field Summary
protected static boolean INFO
           
protected static org.apache.log4j.Logger log
           
 
Constructor Summary
protected AbstractCachingResourceLocator(int capacity, long timeout)
           
 
Method Summary
 int capacity()
          The cache capacity.
protected  boolean clear(String namespace, long timestamp)
          Clears any resource having the same namespace and timestamp from the cache.
protected  T get(String namespace, long timestamp)
          Looks up the resource in the cache (thread-safe since the underlying cache is thread-safe).
protected  void put(T resource)
          Places the resource in the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.bigdata.relation.locator.IResourceLocator
locate
 

Field Detail

log

protected static final org.apache.log4j.Logger log

INFO

protected static final boolean INFO
Constructor Detail

AbstractCachingResourceLocator

protected AbstractCachingResourceLocator(int capacity,
                                         long timeout)
Parameters:
capacity - The cache capacity.
timeout - The timeout in milliseconds for stale entries.
Method Detail

capacity

public final int capacity()
The cache capacity.


get

protected T get(String namespace,
                long timestamp)
Looks up the resource in the cache (thread-safe since the underlying cache is thread-safe).

Parameters:
namespace -
timestamp -
Returns:
The relation -or- null iff it is not in the cache.

put

protected void put(T resource)
Places the resource in the cache.

Note: The underlying cache is thread-safe. However, when adding an entry to the cache the caller MUST be synchronized on the named resource, use get(String, long) to determine that there is no such entry in the cache, and then put(ILocatableResource) the entry.

Note: Read committed views are allowed into the cache.

For a Journal, this depends on Journal#getIndex(name,timestamp) returning a ReadCommittedView for an index so that the view does in fact have read-committed semantics.

For a federation, read-committed semantics are achieved by the IClientIndex implementations since they always make standoff requests to one (or more) data services. Those requests allow the data service to resolve the then most recent view for the index for each request.

Parameters:
resource - The resource.

clear

protected boolean clear(String namespace,
                        long timestamp)
Clears any resource having the same namespace and timestamp from the cache.

Note: The caller MUST be synchronized on the named resource.

Returns:
true iff there was an entry in the cache for the same resource namespace and timestamp, in which case it was cleared from the cache.


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.