|
|||||||||||
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
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 | |
private ManagedCache |
cache
|
private int |
cacheHits
|
private static Vector |
cacheHosts
|
private int |
cacheSummaryInterval
|
private static boolean |
DISABLED
|
(package private) int |
id
Id of this cache - assigned by master. |
private boolean |
inUnreferenced
|
private long |
lastFailed
|
(package private) static int |
MARSHAL_RETRY
|
private RemoteCacheServer |
master
|
protected static boolean |
MASTER
|
private static URL |
MASTER_CODEBASE
|
private static String |
MASTER_HOSTNAME
|
(package private) static int |
MASTER_MONITOR_INTERVAL
|
(package private) String |
name
Name of this cache. |
(package private) static int |
OTHER_RETRY
|
private static String |
previousCacheHost
|
private static String |
previousLocalHost
|
private static String |
RESOURCE
|
private static String |
RMI_HOST_NAME
|
private boolean |
skippedChanges
|
(package private) Vector |
slaves
Vector of registered slave caches. |
private static boolean |
USE_LOCAL_ADDRESS
|
private static boolean |
USE_LOCAL_NAME
|
(package private) static boolean |
VERBOSE_SERVER
|
Fields inherited from class wt.util.RMIServer |
csf, ssf |
Fields inherited from class java.rmi.server.RemoteServer |
|
Fields inherited from class java.rmi.server.RemoteObject |
ref |
Fields inherited from interface wt.cache.CacheServer |
versionID |
Constructor Summary | |
|
CacheManager()
Construct a cache manager. |
private |
CacheManager(boolean export)
|
|
CacheManager(String name,
int size,
RemoteCacheServer master)
Contruct a cache manager. |
Method Summary | |
protected void |
checkAccess()
Method to check access to cache for remote calls. |
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. |
Object |
getEntry(Object key)
Remote method for getting a cache entry. |
private Object |
getSlaveEntry(Object key,
int slave_id)
|
protected boolean |
isCacheHost(String host)
Method to check if a given host is a valid remote cache host. |
private void |
notifySlaves(Object key,
int skip_id)
|
private void |
notOk(RemoteException e)
|
private boolean |
ok(boolean change)
|
protected void |
overflow(Object key,
Object value)
Protected method which allows subclasses of CacheManager to take some action if so desired on a cache overflow. |
void |
ping()
Remote method for verifying ccess. |
private static void |
printRemoteException(RemoteException e)
|
void |
put(Object key,
Object value)
Put a cache entry with given key. |
private void |
put(Object key,
Object value,
int slave_id)
|
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 |
putEntry(Object key,
Object value,
int slave_id)
Remote method for putting an entry in the cache. |
void |
reference(CacheServer self)
Remote method for generating RMI DGC lease on self. |
int |
registerSlave(CacheServer slave)
Remote method for registering a slave cache. |
void |
remove(Object key)
Remove an entry from the cache. |
protected void |
remove(Object key,
int slave_id)
Deprecated. use removeEntry |
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 |
removeEntry(Object key,
int slave_id)
Remote method for removing an entry from the cache. |
void |
reset()
Reset local cache after master reconnect. |
void |
unreferenced()
Called when we are no longer referenced remotely by master or slave caches. |
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. |
private void |
update(Object cache_key,
Object update_key,
Object update_value,
int slave_id)
|
protected Object |
updateEntry(Object current_value,
Object update_key,
Object update_value)
Perform a partial update to a large cached object. |
void |
updateEntry(Object cache_key,
Object update_key,
Object update_value,
int slave_id)
Remote method for updating an existing cache entry. |
Methods inherited from class wt.util.RMIServer |
clone, exportObject, exportObject, exportObject, getClientSocketFactory, getPort, getServerSocketFactory, getStub, isHostInList, isLocalHost, setPort, writeReplace |
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 |
Field Detail |
private static final String RESOURCE
private static final URL MASTER_CODEBASE
private static final String MASTER_HOSTNAME
static final int MARSHAL_RETRY
static final int OTHER_RETRY
static final boolean VERBOSE_SERVER
private static final boolean USE_LOCAL_ADDRESS
private static final boolean USE_LOCAL_NAME
private static final String RMI_HOST_NAME
static final int MASTER_MONITOR_INTERVAL
private static final boolean DISABLED
protected static final boolean MASTER
String name
int id
private ManagedCache cache
private RemoteCacheServer master
Vector slaves
private boolean inUnreferenced
private long lastFailed
private boolean skippedChanges
private int cacheSummaryInterval
private int cacheHits
private static String previousCacheHost
private static String previousLocalHost
private static Vector cacheHosts
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
public CacheManager(String name, int size, 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)private CacheManager(boolean export) throws RemoteException
Method Detail |
private boolean ok(boolean change) throws RemoteException
RemoteException
private void notOk(RemoteException e)
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
RemoteException
public Object get(Object key)
key
- the key object
public void put(Object key, Object value)
key
- the key objectvalue
- the value objectprivate void put(Object key, Object value, int slave_id)
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 objectpublic 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 valueprivate void update(Object cache_key, Object update_key, Object update_value, int slave_id)
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.
update_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 remove(Object key, int slave_id)
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)public int registerSlave(CacheServer slave) throws RemoteException
registerSlave
in interface CacheServer
RemoteException
public Object getEntry(Object key)
getEntry
in interface CacheServer
public void putEntry(Object key, Object value, int slave_id)
putEntry
in interface CacheServer
public void updateEntry(Object cache_key, Object update_key, Object update_value, int slave_id)
updateEntry
in interface CacheServer
public void removeEntry(Object key, int slave_id)
removeEntry
in interface CacheServer
public void ping()
ping
in interface CacheServer
public void reference(CacheServer self) throws RemoteException
reference
in interface CacheServer
RemoteException
protected void checkAccess()
SecurityException
- if check fails and/or access is deniedprotected boolean isCacheHost(String host) throws IOException
wt.cache.master.slaveHosts
property.
IOException
public void unreferenced()
unreferenced
in interface Unreferenced
protected void overflow(Object key, Object value)
private void notifySlaves(Object key, int skip_id)
private Object getSlaveEntry(Object key, int slave_id)
private static void printRemoteException(RemoteException e)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |