public class RemoteCacheServer<K,V> extends UnicastRemoteObject implements IRemoteCacheServer<K,V>, Unreferenced
Remote cache servers can be clustered. If the cache used by this remote cache is configured to use a remote cache of type cluster, the two remote caches will communicate with each other. Remote and put requests can be sent from one remote to another. If they are configured to broadcast such event to their client, then remove an puts can be sent to all locals in the cluster.
Get requests are made between clustered servers if AllowClusterGet is true. You can setup several clients to use one remote server and several to use another. The get local will be distributed between the two servers. Since caches are usually high get and low put, this should allow you to scale.
| Modifier and Type | Field and Description |
|---|---|
static String |
DFEAULT_REMOTE_CONFIGURATION_FILE |
ref| Modifier | Constructor and Description |
|---|---|
protected |
RemoteCacheServer(IRemoteCacheServerAttributes rcsa,
Properties config)
Constructor for the RemoteCacheServer object.
|
protected |
RemoteCacheServer(IRemoteCacheServerAttributes rcsa,
Properties config,
RMISocketFactory customRMISocketFactory)
Constructor for the RemoteCacheServer object.
|
| Modifier and Type | Method and Description |
|---|---|
<KK,VV> void |
addCacheListener(ICacheListener<KK,VV> listener)
Subscribes to all remote caches.
|
<KK,VV> void |
addCacheListener(String cacheName,
ICacheListener<KK,VV> listener)
Subscribes to the specified remote cache.
|
void |
dispose(String cacheName)
Frees the specified remote cache.
|
void |
dispose(String cacheName,
long requesterId)
Frees the specified remote cache.
|
ICacheElement<K,V> |
get(String cacheName,
K key)
Returns a cache value from the specified remote cache; or null if the cache or key does not
exist.
|
ICacheElement<K,V> |
get(String cacheName,
K key,
long requesterId)
Returns a cache bean from the specified cache; or null if the key does not exist.
|
protected CacheListeners<K,V> |
getCacheListeners(String cacheName)
Returns the cache listener for the specified cache.
|
protected CacheListeners<K,V> |
getClusterListeners(String cacheName)
Gets the clusterListeners attribute of the RemoteCacheServer object.
|
protected String |
getExtraInfoForRequesterId(long requesterId)
Ip address for the client, if one is stored.
|
Set<K> |
getKeySet(String cacheName)
Return the keys in the cache.
|
Map<K,ICacheElement<K,V>> |
getMatching(String cacheName,
String pattern)
Gets all matching items.
|
Map<K,ICacheElement<K,V>> |
getMatching(String cacheName,
String pattern,
long requesterId)
Retrieves all matching keys.
|
Map<K,ICacheElement<K,V>> |
getMultiple(String cacheName,
Set<K> keys)
Gets multiple items from the cache based on the given set of keys.
|
Map<K,ICacheElement<K,V>> |
getMultiple(String cacheName,
Set<K> keys,
long requesterId)
Gets multiple items from the cache based on the given set of keys.
|
String |
getStats()
Gets the stats attribute of the RemoteCacheServer object.
|
protected void |
logApplicationEvent(String source,
String eventName,
String optionalDetails)
Logs an event if an event logger is configured.
|
protected <T> void |
logICacheEvent(ICacheEvent<T> cacheEvent)
Logs an event if an event logger is configured.
|
protected Set<K> |
processGetKeySet(String cacheName)
Gets the set of keys of objects currently in the cache.
|
protected Map<K,ICacheElement<K,V>> |
processGetMatching(String cacheName,
String pattern,
long requesterId)
Retrieves all matching keys.
|
void |
put(ICacheElement<K,V> item)
Puts a cache bean to the remote cache and notifies all listeners which
have a different listener id than the originating host; are currently subscribed to the related cache. |
void |
release()
Frees all remote caches.
|
void |
remove(String cacheName,
K key)
Removes the given key from the specified remote cache.
|
void |
remove(String cacheName,
K key,
long requesterId)
Remove the key from the cache region and don't tell the source listener about it.
|
void |
removeAll(String cacheName)
Remove all keys from the specified remote cache.
|
void |
removeAll(String cacheName,
long requesterId)
Remove all keys from the specified remote cache.
|
<KK,VV> void |
removeCacheListener(ICacheListener<KK,VV> listener)
Unsubscribes from all remote caches.
|
<KK,VV> void |
removeCacheListener(String cacheName,
ICacheListener<KK,VV> listener)
Unsubscribe this listener from this region.
|
void |
removeCacheListener(String cacheName,
long listenerId)
Unsubscribe this listener from this region.
|
void |
setCacheEventLogger(ICacheEventLogger cacheEventLogger)
Allows it to be injected.
|
void |
shutdown()
Shuts down the remote server.
|
void |
shutdown(String host,
int port)
Shuts down a server at a particular host and port.
|
void |
unreferenced()
Called by the RMI runtime sometime after the runtime determines that the reference list, the
list of clients referencing the remote object, becomes empty.
|
void |
update(ICacheElement<K,V> item)
Puts a cache item to the cache.
|
void |
update(ICacheElement<K,V> item,
long requesterId)
The internal processing is wrapped in event logging calls.
|
clone, exportObject, exportObject, exportObject, unexportObjectgetClientHost, getLog, setLogpublic static final String DFEAULT_REMOTE_CONFIGURATION_FILE
protected RemoteCacheServer(IRemoteCacheServerAttributes rcsa, Properties config) throws RemoteException
rcsa - config - cache hub configurationRemoteExceptionprotected RemoteCacheServer(IRemoteCacheServerAttributes rcsa, Properties config, RMISocketFactory customRMISocketFactory) throws RemoteException
rcsa - config - cache hub configurationcustomRMISocketFactory - RemoteExceptionpublic void put(ICacheElement<K,V> item) throws IOException
item - IOExceptionpublic void update(ICacheElement<K,V> item) throws IOException
ICacheServiceupdate in interface ICacheService<K,V>item - IOExceptionpublic void update(ICacheElement<K,V> item, long requesterId) throws IOException
update in interface ICacheServiceNonLocal<K,V>item - requesterId - IOExceptionpublic ICacheElement<K,V> get(String cacheName, K key) throws IOException
get in interface ICacheService<K,V>cacheName - key - IOExceptionpublic ICacheElement<K,V> get(String cacheName, K key, long requesterId) throws IOException
Adding the requestor id, allows the cache to determine the source of the get.
The internal processing is wrapped in event logging calls.
get in interface ICacheServiceNonLocal<K,V>cacheName - key - requesterId - IOExceptionpublic Map<K,ICacheElement<K,V>> getMatching(String cacheName, String pattern) throws IOException
getMatching in interface ICacheService<K,V>cacheName - pattern - IOExceptionpublic Map<K,ICacheElement<K,V>> getMatching(String cacheName, String pattern, long requesterId) throws IOException
getMatching in interface ICacheServiceNonLocal<K,V>cacheName - pattern - requesterId - IOExceptionprotected Map<K,ICacheElement<K,V>> processGetMatching(String cacheName, String pattern, long requesterId)
cacheName - pattern - requesterId - public Map<K,ICacheElement<K,V>> getMultiple(String cacheName, Set<K> keys) throws IOException
getMultiple in interface ICacheService<K,V>cacheName - keys - IOExceptionpublic Map<K,ICacheElement<K,V>> getMultiple(String cacheName, Set<K> keys, long requesterId) throws IOException
The internal processing is wrapped in event logging calls.
getMultiple in interface ICacheServiceNonLocal<K,V>cacheName - keys - requesterId - IOExceptionpublic Set<K> getKeySet(String cacheName) throws IOException
getKeySet in interface ICacheServiceNonLocal<K,V>cacheName - the name of the cache regionIOExceptionAuxiliaryCache.getKeySet()protected Set<K> processGetKeySet(String cacheName)
cacheName - public void remove(String cacheName, K key) throws IOException
remove in interface ICacheService<K,V>cacheName - key - IOExceptionpublic void remove(String cacheName, K key, long requesterId) throws IOException
The internal processing is wrapped in event logging calls.
remove in interface ICacheServiceNonLocal<K,V>cacheName - key - requesterId - IOExceptionpublic void removeAll(String cacheName) throws IOException
removeAll in interface ICacheService<K,V>cacheName - IOExceptionpublic void removeAll(String cacheName, long requesterId) throws IOException
The internal processing is wrapped in event logging calls.
removeAll in interface ICacheServiceNonLocal<K,V>cacheName - requesterId - IOExceptionpublic void dispose(String cacheName) throws IOException
dispose in interface ICacheService<K,V>cacheName - IOExceptionpublic void dispose(String cacheName, long requesterId) throws IOException
cacheName - requesterId - IOExceptionpublic void release()
throws IOException
release in interface ICacheService<K,V>IOExceptionprotected CacheListeners<K,V> getCacheListeners(String cacheName)
cacheName - protected CacheListeners<K,V> getClusterListeners(String cacheName)
TODO may be able to remove this
cacheName - public <KK,VV> void addCacheListener(String cacheName, ICacheListener<KK,VV> listener) throws IOException
If the client id is 0, then the remote cache server will increment it's local count and assign an id to the client.
addCacheListener in interface ICacheObservercacheName - the specified remote cache.listener - object to notify for cache changes. must be synchronized since there are
remote calls involved.IOExceptionpublic <KK,VV> void addCacheListener(ICacheListener<KK,VV> listener) throws IOException
addCacheListener in interface ICacheObserverlistener - The feature to be added to the CacheListener attributeIOExceptionpublic <KK,VV> void removeCacheListener(String cacheName, ICacheListener<KK,VV> listener) throws IOException
removeCacheListener in interface ICacheObservercacheName - listener - IOExceptionpublic void removeCacheListener(String cacheName, long listenerId)
cacheName - listenerId - public <KK,VV> void removeCacheListener(ICacheListener<KK,VV> listener) throws IOException
removeCacheListener in interface ICacheObserverlistener - IOExceptionpublic void shutdown()
throws IOException
shutdown in interface ICacheServiceAdminIOExceptionpublic void shutdown(String host, int port) throws IOException
shutdown in interface ICacheServiceAdminhost - port - IOExceptionpublic void unreferenced()
unreferenced in interface Unreferencedpublic String getStats() throws IOException
getStats in interface ICacheServiceAdminIOExceptionprotected void logApplicationEvent(String source, String eventName, String optionalDetails)
source - eventName - optionalDetails - protected <T> void logICacheEvent(ICacheEvent<T> cacheEvent)
cacheEvent - protected String getExtraInfoForRequesterId(long requesterId)
Protected for testing.
requesterId - public void setCacheEventLogger(ICacheEventLogger cacheEventLogger)
cacheEventLogger - Copyright © 2002–2022 The Apache Software Foundation. All rights reserved.