|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.rmi.server.RemoteObject
java.rmi.server.RemoteServer
wt.util.RMIServer
wt.cache.CacheManager
public class CacheManager
A multi-level cache manager service. This is an abstract parent class for specialized object caches. A cache is a fixed size collection of most recently used objects identified by a unique identifier.
This class manages the maintenance and synchronization of multi-level caches where multiple cache objects (usually in separate VMs) have a master/slave relationship. Updates to a cache are pushed synchronously to the master cache which asynchronously notifies other slave caches that an entry has been updated.
To be effective, updates to cached objects must notify the cache so that master/slave caches may receive corresponding updates. It is the responsibility of the application to make this happen.
When a new entry is put into the cache, the entire object is sent to the master cache. When an update call is made, the master is sent only the update. If the master has aged out it's cache entry, it will attempt to retrieve the full object from the slave.
The follow example is a simple cache of a objects used similarly to how a static Hashtable of object references would be used.
public class FooManager
{
// Foo cache
private static FooCache fooCache = null;
// Get/create Foo cache (unsynchronized)
private static FooCache getFooCache ()
{
if (fooCache == null)
createFooCache();
return fooCache;
}
// Create Foo cache (synchronized)
private static synchronized void createFooCache ()
{
if (fooCache == null)
{
try
{
fooCache = new FooCache();
}
catch (RemoteException e)
{
// Fatal - throw as method server exception
throw new MethodServerException("Unable to create foo cache", e);
}
}
}
public Foo getFoo (Object foo_key)
{
FooCache foo_cache = getFooCache();
Foo foo = (Foo)foo_cache.get(foo_key);
if (foo == null)
{
// Get or create foo object
foo = ...
// Add to foo cache
foo_cache.put(foo_key, foo);
}
return foo;
}
public void updateFoo (Foo foo, ...)
{
// Do update
Foo new_foo = ...
// Update foo cache (required even if new_foo is current cache entry)
Object foo_key = ...
getFooCache().put(foo_key, new_foo);
}
}
public class FooCache extends CacheManager
{
public FooCache ()
throws RemoteException
{
super();
}
}
| Field Summary |
|---|
| Fields inherited from class java.rmi.server.RemoteObject |
|---|
ref |
| Constructor Summary | |
|---|---|
CacheManager()
Construct a cache manager. |
|
CacheManager(String name,
int size,
wt.cache.RemoteCacheServer master)
Contruct a cache manager. |
|
| Method Summary | |
|---|---|
Object |
get(Object key)
Get cache entry with given key. |
String |
getDefaultName()
Get desired name of this cache. |
int |
getDefaultSize()
Get desired size of this cache. |
void |
put(Object key,
Object value)
Put a cache entry with given key. |
protected void |
putEntry(Object key,
Object value)
Protected method which allows subclasses of CacheManager to take some action when a new entry is being put into the local cache. |
void |
remove(Object key)
Remove an entry from the cache. |
protected void |
removeEntry(Object key)
Protected method which allows subclasses of CacheManager to take some action when a entry is being removed from the local cache. |
void |
reset()
Reset local cache after master reconnect. |
void |
update(Object cache_key,
Object update_key,
Object update_value)
Notify master and slave caches of a partial update to a large cache entry. |
protected Object |
updateEntry(Object current_value,
Object update_key,
Object update_value)
Perform a partial update to a large cached object. |
| Methods inherited from class java.rmi.server.RemoteServer |
|---|
getClientHost, getLog, setLog |
| Methods inherited from class java.rmi.server.RemoteObject |
|---|
equals, getRef, hashCode, toString, toStub |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public CacheManager()
throws RemoteException
getDefaultName method.
The cache size if obtained by calling the getDefaultSize method.
The master cache is assumed to be in the default (local) server manager using
the fully qualified class name as a service name.
If the wt.cache.master.codebase property is set, this local master
cache will itself be subordinate to a cache on the identified system.
On the master host, the wt.cache.master.codebase should not be set, or
if set, it should be identical to the wt.server.codebase property.
If a non-master and master share an identical wt.server.codebase URLs,
a second property, wt.cache.master.hostname, can be used to uniquely
identify the master host.
Supported API: true
RemoteException
public CacheManager(String name,
int size,
wt.cache.RemoteCacheServer master)
throws RemoteException
name - cache name used in debug tracingsize - maximum number of entries in the cachemaster - RemoteCacheServer used to call master cache (null = no master)
RemoteException| Method Detail |
|---|
public String getDefaultName()
public int getDefaultSize()
wt.cache.size.CacheName
where cacheName is the name of this cache. Subclasses can override this
method to control cache size in some other way. If no property is found, the default
size is 100.
public void reset()
throws RemoteException
NOTE: This may be called as a result of calling other cache updating operations
since that is when the disconnect and reconnect may take place. When this
happens, this method is called before the other methods return.
Supported API: true
RemoteExceptionpublic Object get(Object key)
key - the key object
public void put(Object key,
Object value)
key - the key objectvalue - the value object
protected void putEntry(Object key,
Object value)
put call or a call forwarded from a slave cache
or when a local get call downloads the entry from a master cache.
If this cache has a master cache, the put call will already
be forwarded to the master before this method is invoked. Slave caches
will be notified to remove their entries after this method returns.
This method must not cause a recursive put call.
key - the key objectvalue - the value object
public void update(Object cache_key,
Object update_key,
Object update_value)
updateEntry.
Any slave caches will have their corresponding entry removed. Subclasses should
override updateEntry to implement partial updates for large objects.
The caller is expected to have already updated the local cache entry before this
method is called.
Supported API: true
cache_key - the key for the cache entryupdate_key - the key for what is being updated in the entryupdate_value - the updated value
protected Object updateEntry(Object current_value,
Object update_key,
Object update_value)
update method is performed in a
slave cache. It must not cause a recursive update call.
cache_key - the key for the cache entryupdate_key - the key for what is being updated in the entryupdate_value - the updated valuepublic void remove(Object key)
put.(key, null) but it does not result in a
null entry taking up space in the cache.
key - the key object (null = clear entire cache)protected void removeEntry(Object key)
remove call or a call forwarded from a master cache.
If this cache has a master cache, the remove call will already
be forwarded to the master before this method is invoked. Slave caches
will be notified to remove their entries after this method returns.
This method must not cause a recursive remove call.
This method is not called when entries are being removed by the overflow
or reset methods.
Supported API: true
key - the key object (null = clear entire cache)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||