Class RMICachePeer
- java.lang.Object
-
- java.rmi.server.RemoteObject
-
- java.rmi.server.RemoteServer
-
- java.rmi.server.UnicastRemoteObject
-
- net.sf.ehcache.distribution.RMICachePeer
-
- All Implemented Interfaces:
java.io.Serializable,java.rmi.Remote,CachePeer
- Direct Known Subclasses:
TransactionalRMICachePeer
public class RMICachePeer extends java.rmi.server.UnicastRemoteObject implements CachePeer, java.rmi.Remote
An RMI based implementation ofCachePeer.This class features a customised RMIClientSocketFactory which enables socket timeouts to be configured.
- Version:
- $Id$
- Author:
- Greg Luck
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RMICachePeer(Ehcache cache, java.lang.String hostName, java.lang.Integer rmiRegistryPort, java.lang.Integer remoteObjectPort, java.lang.Integer socketTimeoutMillis)Construct a new remote peer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.ListgetElements(java.util.List keys)Gets a list of elements from the cache, for a list of keys, without updating Element statistics.java.lang.StringgetGuid()Gets the globally unique id for the underlyingCacheinstance.java.util.ListgetKeys()Returns a list of all elements in the cache, whether or not they are expired.java.lang.StringgetName()Gets the cache nameElementgetQuiet(java.io.Serializable key)Gets an element from the cache, without updating Element statistics.java.lang.StringgetUrl()The URL for the remote replicator to connect.java.lang.StringgetUrlBase()The URL base for the remote replicator to connect.voidput(Element element)Puts an Element into the underlying cache without notifying listeners or updating statistics.booleanremove(java.io.Serializable key)Removes an Element from the underlying cache without notifying listeners or updating statistics.voidremoveAll()Removes all cached items.voidsend(java.util.List eventMessages)Send the cache peer with an ordered list ofEventMessagesjava.lang.StringtoString()Returns a String that represents the value of this object.
-
-
-
Constructor Detail
-
RMICachePeer
public RMICachePeer(Ehcache cache, java.lang.String hostName, java.lang.Integer rmiRegistryPort, java.lang.Integer remoteObjectPort, java.lang.Integer socketTimeoutMillis) throws java.rmi.RemoteException
Construct a new remote peer.- Parameters:
cache- The cache attached to the peerhostName- The host name the peer is running on.rmiRegistryPort- The port number on which the RMI Registry listens. Should be an unused port in the range 1025 - 65536remoteObjectPort- the port number on which the remote objects bound in the registry receive calls. This defaults to a free port if not specified. Should be an unused port in the range 1025 - 65536socketTimeoutMillis-- Throws:
java.rmi.RemoteException
-
-
Method Detail
-
getUrl
public final java.lang.String getUrl()
The URL for the remote replicator to connect. The value will only have meaning for a specific implementation of replicator and remote peer.This method is not meant to be used remotely. The replicator already needs to know this. It has to throw RemoteException to comply with RMI requirements
This implementation gives an URL which has meaning to the RMI remoting system.
-
getUrlBase
public final java.lang.String getUrlBase()
The URL base for the remote replicator to connect. The value will have meaning only to a specific implementation of replicator and remote peer.This implementation gives an URL which has meaning to the RMI remoting system.
- Specified by:
getUrlBasein interfaceCachePeer- Returns:
- the URL, without the scheme, as a string e.g. //hostname:port
-
getKeys
public java.util.List getKeys() throws java.rmi.RemoteExceptionReturns a list of all elements in the cache, whether or not they are expired.The returned keys are unique and can be considered a set.
The List returned is not live. It is a copy.
The time taken is O(n). On a single cpu 1.8Ghz P4, approximately 8ms is required for each 1000 entries.
-
getQuiet
public Element getQuiet(java.io.Serializable key) throws java.rmi.RemoteException
Gets an element from the cache, without updating Element statistics. Cache statistics are still updated.
-
getElements
public java.util.List getElements(java.util.List keys) throws java.rmi.RemoteExceptionGets a list of elements from the cache, for a list of keys, without updating Element statistics. Time to idle lifetimes are therefore not affected.Cache statistics are still updated.
Callers should ideally first call this method with a small list of keys to gauge the size of a typical Element. Then a calculation can be made of the right number to request each time so as to optimise network performance and not cause an OutOfMemory error on this Cache.
- Specified by:
getElementsin interfaceCachePeer- Parameters:
keys- a list of serializable values which represent keys- Returns:
- a list of Elements. If an element was not found or null, it will not be in the list.
- Throws:
java.rmi.RemoteException
-
put
public void put(Element element) throws java.rmi.RemoteException, java.lang.IllegalArgumentException, java.lang.IllegalStateException
Puts an Element into the underlying cache without notifying listeners or updating statistics.
-
remove
public boolean remove(java.io.Serializable key) throws java.rmi.RemoteException, java.lang.IllegalStateExceptionRemoves an Element from the underlying cache without notifying listeners or updating statistics.
-
removeAll
public void removeAll() throws java.rmi.RemoteException, java.lang.IllegalStateExceptionRemoves all cached items.- Specified by:
removeAllin interfaceCachePeer- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVEjava.rmi.RemoteException
-
send
public void send(java.util.List eventMessages) throws java.rmi.RemoteExceptionSend the cache peer with an ordered list ofEventMessagesThis enables multiple messages to be delivered in one network invocation.
- Specified by:
sendin interfaceCachePeer- Parameters:
eventMessages- a list of typeEventMessage- Throws:
java.rmi.RemoteException
-
getName
public final java.lang.String getName() throws java.rmi.RemoteExceptionGets the cache name
-
getGuid
public final java.lang.String getGuid() throws java.rmi.RemoteExceptionGets the globally unique id for the underlyingCacheinstance.
-
toString
public java.lang.String toString()
Returns a String that represents the value of this object.- Overrides:
toStringin classjava.rmi.server.RemoteObject
-
-