|
|||||||||
| Home >> All >> com >> go >> trove >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.go.trove.util
Class Depot

java.lang.Objectcom.go.trove.util.Depot
- public class Depot
- extends java.lang.Object
Depot implements a simple and efficient caching strategy. It is thread-safe, and it allows requests of different objects to occur concurrently. Depot is best suited as a front-end for accessing objects from a remote device, like a database. If the remote device is not responding, the Depot will continue to serve invalidated objects so that the requester may continue as normal.
Depot is designed as a cache in front of an object factory. Objects may be invalidated, but they are not explicitly removed from the cache until a replacement has been provided by the factory. The factory is invoked from another thread, allowing for the requester to timeout and use an invalidated object. When the factory eventually finishes, its object will be cached.
By allowing for eventual completion of the factory, Depot enables applications to dynamically adjust to the varying performance and reliability of remote data providers.
Depot will never return an object or null that did not originate from the factory. When retrieving an object that wasn't found cached, a call to the factory will block until it is finished.
Objects may be invalided from the Depot automatically. This approach is based on a fixed time expiration and is somewhat inflexible. An ideal invalidation strategy requires asynchronous notification from the actual data providers.
- Version:
- 14 , 01/07/09
| Nested Class Summary | |
static interface |
Depot.Factory
Implement this interface in order for Depot to retrieve objects when needed, often in a thread other than the requester's. |
static interface |
Depot.Filter
|
static interface |
Depot.Perishable
Values returned from the Factories may implement this interface if they manually handle expiration. |
static interface |
Depot.PerishablesFactory
A special kind of Factory that creates objects that are considered invalid after a specific amount of time has elapsed. |
private class |
Depot.Retriever
|
| Field Summary | |
private Depot.Factory |
mDefaultFactory
|
private java.util.Map |
mExpirations
|
private java.lang.Object |
mExpireLock
|
private java.util.Map |
mInvalidCache
|
private com.go.trove.util.tq.TransactionQueue |
mQueue
|
private java.util.Map |
mRetrievers
|
private long |
mTimeout
|
private java.util.Map |
mValidCache
|
| Constructor Summary | |
Depot(Depot.Factory factory,
int cacheSize,
com.go.trove.util.tq.TransactionQueue tq,
long timeout)
|
|
Depot(Depot.Factory factory,
java.util.Map validCache,
java.util.Map invalidCache,
com.go.trove.util.tq.TransactionQueue tq,
long timeout)
|
|
| Method Summary | |
void |
clear()
Completely removes all items from the Depot's caches. |
java.lang.Object |
get(Depot.Factory factory,
java.lang.Object key)
Retrieve an object from the Depot. |
java.lang.Object |
get(Depot.Factory factory,
java.lang.Object key,
long timeout)
Retrieve an object from the Depot. |
java.lang.Object |
get(java.lang.Object key)
Retrieve an object from the Depot. |
java.lang.Object |
get(java.lang.Object key,
long timeout)
Retrieve an object from the Depot. |
private void |
init(Depot.Factory factory,
java.util.Map validCache,
java.util.Map invalidCache,
com.go.trove.util.tq.TransactionQueue tq,
long timeout)
|
void |
invalidate(java.lang.Object key)
Invalidate the object referenced by the given key, if it is already cached in this Depot. |
void |
invalidateAll()
Invalidates all the objects in the Depot. |
void |
invalidateAll(Depot.Filter filter)
Invalidates objects in the Depot, using a filter. |
int |
invalidSize()
Returns the number of invalid objects in the Depot. |
boolean |
isEmpty()
|
void |
put(java.lang.Object key,
java.lang.Object value)
Put a value into the Depot, bypassing the factory. |
java.lang.Object |
remove(java.lang.Object key)
Completely removes an item from the Depot's caches. |
void |
removeAll(Depot.Filter filter)
Completely removes all the items from the Depot that the given filter accepts. |
private Depot.Retriever |
retrieve(Depot.Factory factory,
java.lang.Object key,
java.lang.Object originalValue,
boolean priority)
Caller must lock interned key. |
(package private) void |
setExpiration(java.lang.Object key,
long duration)
|
int |
size()
Returns the total number objects in the Depot. |
int |
validSize()
Returns the number of valid objects in the Depot. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
mDefaultFactory
private Depot.Factory mDefaultFactory
mValidCache
private java.util.Map mValidCache
mInvalidCache
private java.util.Map mInvalidCache
mQueue
private com.go.trove.util.tq.TransactionQueue mQueue
mTimeout
private long mTimeout
mRetrievers
private java.util.Map mRetrievers
mExpireLock
private final java.lang.Object mExpireLock
mExpirations
private java.util.Map mExpirations
| Constructor Detail |
Depot
public Depot(Depot.Factory factory, java.util.Map validCache, java.util.Map invalidCache, com.go.trove.util.tq.TransactionQueue tq, long timeout)
Depot
public Depot(Depot.Factory factory, int cacheSize, com.go.trove.util.tq.TransactionQueue tq, long timeout)
| Method Detail |
init
private void init(Depot.Factory factory, java.util.Map validCache, java.util.Map invalidCache, com.go.trove.util.tq.TransactionQueue tq, long timeout)
size
public int size()
- Returns the total number objects in the Depot.
isEmpty
public boolean isEmpty()
validSize
public int validSize()
- Returns the number of valid objects in the Depot.
invalidSize
public int invalidSize()
- Returns the number of invalid objects in the Depot.
get
public java.lang.Object get(java.lang.Object key)
- Retrieve an object from the Depot. If the requested object is in the
cache of valid objects, it is returned immediately. If the object is
found in the cache of invalid objects, then it will be returned only if
the factory cannot create a replacement in a timely manner. If the
requested object is not in any cache at all, the factory is called to
create the object, and the calling thread will block until the factory
has finished.
get
public java.lang.Object get(java.lang.Object key, long timeout)
- Retrieve an object from the Depot. If the requested object is in the
cache of valid objects, it is returned immediately. If the object is
found in the cache of invalid objects, then it will be returned only if
the factory cannot create a replacement in a timely manner. If the
requested object is not in any cache at all, the factory is called to
create the object, and the calling thread will block until the factory
has finished.
get
public java.lang.Object get(Depot.Factory factory, java.lang.Object key)
- Retrieve an object from the Depot. If the requested object is in the
cache of valid objects, it is returned immediately. If the object is
found in the cache of invalid objects, then it will be returned only if
the factory cannot create a replacement in a timely manner. If the
requested object is not in any cache at all, the factory is called to
create the object, and the calling thread will block until the factory
has finished.
get
public java.lang.Object get(Depot.Factory factory, java.lang.Object key, long timeout)
- Retrieve an object from the Depot. If the requested object is in the
cache of valid objects, it is returned immediately. If the object is
found in the cache of invalid objects, then it will be returned only if
the factory cannot create a replacement in a timely manner. If the
requested object is not in any cache at all, the factory is called to
create the object, and the calling thread will block until the factory
has finished.
invalidate
public void invalidate(java.lang.Object key)
- Invalidate the object referenced by the given key, if it is already
cached in this Depot. Invalidated objects are not removed from the
Depot until a replacement object has been successfully created from the
factory.
invalidateAll
public void invalidateAll(Depot.Filter filter)
- Invalidates objects in the Depot, using a filter. Each key that the
filter accepts is invalidated.
invalidateAll
public void invalidateAll()
- Invalidates all the objects in the Depot.
put
public void put(java.lang.Object key, java.lang.Object value)
- Put a value into the Depot, bypassing the factory. Invalidating an
object and relying on the factory to produce a new value is generally
preferred. This method will notify any threads waiting on a factory to
produce a value, but it will not disrupt the behavior of the factory.
remove
public java.lang.Object remove(java.lang.Object key)
- Completely removes an item from the Depot's caches. Invalidating an
object is preferred, and remove should be called only if the object
should absolutely never be used again.
removeAll
public void removeAll(Depot.Filter filter)
- Completely removes all the items from the Depot that the given filter
accepts.
clear
public void clear()
- Completely removes all items from the Depot's caches. Invalidating all
the objects is preferred, and clear should be called only if all the
cached objects should absolutely never be used again.
setExpiration
void setExpiration(java.lang.Object key, long duration)
retrieve
private Depot.Retriever retrieve(Depot.Factory factory, java.lang.Object key, java.lang.Object originalValue, boolean priority)
- Caller must lock interned key.
|
|||||||||
| Home >> All >> com >> go >> trove >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.go.trove.util.Depot