Class RemoteCacheServer<K,V>
- All Implemented Interfaces:
Serializable,Remote,Unreferenced,IRemoteCacheServer<K,,V> ICacheObserver,ICacheService<K,,V> ICacheServiceAdmin,ICacheServiceNonLocal<K,V>
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.
- See Also:
-
Field Summary
FieldsFields inherited from class java.rmi.server.RemoteObject
ref -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRemoteCacheServer(IRemoteCacheServerAttributes rcsa, Properties config) Constructor for the RemoteCacheServer object.protectedRemoteCacheServer(IRemoteCacheServerAttributes rcsa, Properties config, RMISocketFactory customRMISocketFactory) Constructor for the RemoteCacheServer object. -
Method Summary
Modifier and TypeMethodDescription<KK,VV> void addCacheListener(String cacheName, ICacheListener<KK, VV> listener) Subscribes to the specified remote cache.<KK,VV> void addCacheListener(ICacheListener<KK, VV> listener) Subscribes to all remote caches.voidFrees the specified remote cache.voidFrees the specified remote cache.Returns a cache value from the specified remote cache; or null if the cache or key does not exist.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 StringgetExtraInfoForRequesterId(long requesterId) Ip address for the client, if one is stored.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.getStats()Gets the stats attribute of the RemoteCacheServer object.protected voidlogApplicationEvent(String source, String eventName, String optionalDetails) Logs an event if an event logger is configured.protected <T> voidlogICacheEvent(ICacheEvent<T> cacheEvent) Logs an event if an event logger is configured.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.voidput(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.voidrelease()Frees all remote caches.voidRemoves the given key from the specified remote cache.voidRemove the key from the cache region and don't tell the source listener about it.voidRemove all keys from the specified remote cache.voidRemove all keys from the specified remote cache.voidremoveCacheListener(String cacheName, long listenerId) Unsubscribe this listener from this region.<KK,VV> void removeCacheListener(String cacheName, ICacheListener<KK, VV> listener) Unsubscribe this listener from this region.<KK,VV> void removeCacheListener(ICacheListener<KK, VV> listener) Unsubscribes from all remote caches.voidsetCacheEventLogger(ICacheEventLogger cacheEventLogger) Allows it to be injected.voidshutdown()Shuts down the remote server.voidShuts down a server at a particular host and port.voidCalled by the RMI runtime sometime after the runtime determines that the reference list, the list of clients referencing the remote object, becomes empty.voidupdate(ICacheElement<K, V> item) Puts a cache item to the cache.voidupdate(ICacheElement<K, V> item, long requesterId) The internal processing is wrapped in event logging calls.Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObjectMethods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
-
Field Details
-
DFEAULT_REMOTE_CONFIGURATION_FILE
- See Also:
-
-
Constructor Details
-
RemoteCacheServer
protected RemoteCacheServer(IRemoteCacheServerAttributes rcsa, Properties config) throws RemoteException Constructor for the RemoteCacheServer object. This initializes the server with the values from the properties object.- Parameters:
rcsa-config- cache hub configuration- Throws:
RemoteException
-
RemoteCacheServer
protected RemoteCacheServer(IRemoteCacheServerAttributes rcsa, Properties config, RMISocketFactory customRMISocketFactory) throws RemoteException Constructor for the RemoteCacheServer object. This initializes the server with the values from the properties object.- Parameters:
rcsa-config- cache hub configurationcustomRMISocketFactory-- Throws:
RemoteException
-
-
Method Details
-
put
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.
- Parameters:
item-- Throws:
IOException
-
update
Description copied from interface:ICacheServicePuts a cache item to the cache.- Specified by:
updatein interfaceICacheService<K,V> - Parameters:
item-- Throws:
IOException
-
update
The internal processing is wrapped in event logging calls.- Specified by:
updatein interfaceICacheServiceNonLocal<K,V> - Parameters:
item-requesterId-- Throws:
IOException
-
get
Returns a cache value from the specified remote cache; or null if the cache or key does not exist.- Specified by:
getin interfaceICacheService<K,V> - Parameters:
cacheName-key-- Returns:
- ICacheElement
- Throws:
IOException
-
get
Returns a cache bean from the specified cache; or null if the key does not exist.Adding the requestor id, allows the cache to determine the source of the get.
The internal processing is wrapped in event logging calls.
- Specified by:
getin interfaceICacheServiceNonLocal<K,V> - Parameters:
cacheName-key-requesterId-- Returns:
- ICacheElement
- Throws:
IOException
-
getMatching
Gets all matching items.- Specified by:
getMatchingin interfaceICacheService<K,V> - Parameters:
cacheName-pattern-- Returns:
- Map of keys and wrapped objects
- Throws:
IOException
-
getMatching
public Map<K,ICacheElement<K, getMatchingV>> (String cacheName, String pattern, long requesterId) throws IOException Retrieves all matching keys.- Specified by:
getMatchingin interfaceICacheServiceNonLocal<K,V> - Parameters:
cacheName-pattern-requesterId-- Returns:
- Map of keys and wrapped objects
- Throws:
IOException
-
processGetMatching
protected Map<K,ICacheElement<K, processGetMatchingV>> (String cacheName, String pattern, long requesterId) Retrieves all matching keys.- Parameters:
cacheName-pattern-requesterId-- Returns:
- Map of keys and wrapped objects
-
getMultiple
Gets multiple items from the cache based on the given set of keys.- Specified by:
getMultiplein interfaceICacheService<K,V> - Parameters:
cacheName-keys-- Returns:
- a map of K key to ICacheElement<K, V> element, or an empty map if there is no data in cache for any of these keys
- Throws:
IOException
-
getMultiple
public Map<K,ICacheElement<K, getMultipleV>> (String cacheName, Set<K> keys, long requesterId) throws IOException Gets multiple items from the cache based on the given set of keys.The internal processing is wrapped in event logging calls.
- Specified by:
getMultiplein interfaceICacheServiceNonLocal<K,V> - Parameters:
cacheName-keys-requesterId-- Returns:
- a map of K key to ICacheElement<K, V> element, or an empty map if there is no data in cache for any of these keys
- Throws:
IOException
-
getKeySet
Return the keys in the cache.- Specified by:
getKeySetin interfaceICacheServiceNonLocal<K,V> - Parameters:
cacheName- the name of the cache region- Returns:
- a set of the key type TODO This should probably be done in chunks with a range passed in. This will be a problem if someone puts a 1,000,000 or so items in a region.
- Throws:
IOException- See Also:
-
processGetKeySet
Gets the set of keys of objects currently in the cache.- Parameters:
cacheName-- Returns:
- Set
-
remove
Removes the given key from the specified remote cache. Defaults the listener id to 0.- Specified by:
removein interfaceICacheService<K,V> - Parameters:
cacheName-key-- Throws:
IOException
-
remove
Remove the key from the cache region and don't tell the source listener about it.The internal processing is wrapped in event logging calls.
- Specified by:
removein interfaceICacheServiceNonLocal<K,V> - Parameters:
cacheName-key-requesterId-- Throws:
IOException
-
removeAll
Remove all keys from the specified remote cache.- Specified by:
removeAllin interfaceICacheService<K,V> - Parameters:
cacheName-- Throws:
IOException
-
removeAll
Remove all keys from the specified remote cache.The internal processing is wrapped in event logging calls.
- Specified by:
removeAllin interfaceICacheServiceNonLocal<K,V> - Parameters:
cacheName-requesterId-- Throws:
IOException
-
dispose
Frees the specified remote cache.- Specified by:
disposein interfaceICacheService<K,V> - Parameters:
cacheName-- Throws:
IOException
-
dispose
Frees the specified remote cache.- Parameters:
cacheName-requesterId-- Throws:
IOException
-
release
Frees all remote caches.- Specified by:
releasein interfaceICacheService<K,V> - Throws:
IOException
-
getCacheListeners
Returns the cache listener for the specified cache. Creates the cache and the cache descriptor if they do not already exist.- Parameters:
cacheName-- Returns:
- The cacheListeners value
-
getClusterListeners
Gets the clusterListeners attribute of the RemoteCacheServer object.TODO may be able to remove this
- Parameters:
cacheName-- Returns:
- The clusterListeners value
-
addCacheListener
public <KK,VV> void addCacheListener(String cacheName, ICacheListener<KK, VV> listener) throws IOExceptionSubscribes to the specified remote cache.If the client id is 0, then the remote cache server will increment it's local count and assign an id to the client.
- Specified by:
addCacheListenerin interfaceICacheObserver- Parameters:
cacheName- the specified remote cache.listener- object to notify for cache changes. must be synchronized since there are remote calls involved.- Throws:
IOException
-
addCacheListener
Subscribes to all remote caches.- Specified by:
addCacheListenerin interfaceICacheObserver- Parameters:
listener- The feature to be added to the CacheListener attribute- Throws:
IOException
-
removeCacheListener
public <KK,VV> void removeCacheListener(String cacheName, ICacheListener<KK, VV> listener) throws IOExceptionUnsubscribe this listener from this region. If the listener is registered, it will be removed from the event queue map list.- Specified by:
removeCacheListenerin interfaceICacheObserver- Parameters:
cacheName-listener-- Throws:
IOException
-
removeCacheListener
Unsubscribe this listener from this region. If the listener is registered, it will be removed from the event queue map list.- Parameters:
cacheName-listenerId-
-
removeCacheListener
Unsubscribes from all remote caches.- Specified by:
removeCacheListenerin interfaceICacheObserver- Parameters:
listener-- Throws:
IOException
-
shutdown
Shuts down the remote server.- Specified by:
shutdownin interfaceICacheServiceAdmin- Throws:
IOException
-
shutdown
Shuts down a server at a particular host and port. Then it calls shutdown on the cache itself.- Specified by:
shutdownin interfaceICacheServiceAdmin- Parameters:
host-port-- Throws:
IOException
-
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.- Specified by:
unreferencedin interfaceUnreferenced
-
getStats
Gets the stats attribute of the RemoteCacheServer object.- Specified by:
getStatsin interfaceICacheServiceAdmin- Returns:
- The stats value
- Throws:
IOException
-
logApplicationEvent
Logs an event if an event logger is configured.- Parameters:
source-eventName-optionalDetails-
-
logICacheEvent
Logs an event if an event logger is configured.- Parameters:
cacheEvent-
-
getExtraInfoForRequesterId
Ip address for the client, if one is stored.Protected for testing.
- Parameters:
requesterId-- Returns:
- String
-
setCacheEventLogger
Allows it to be injected.- Parameters:
cacheEventLogger-
-