Top Description Fields Constructors Methods
net.sf.ehcache.distribution

public Class RMICachePeer

extends UnicastRemoteObject
implements CachePeer, Remote
Class Inheritance
All Implemented Interfaces
java.rmi.Remote, net.sf.ehcache.distribution.CachePeer
Known Direct Subclasses
net.sf.ehcache.distribution.TransactionalRMICachePeer
Imports
net.sf.ehcache.Ehcache, .Element, java.io.Serializable, java.rmi.Remote, .RemoteException, java.rmi.server.UnicastRemoteObject, java.util.ArrayList, .List, net.sf.ehcache.distribution.RmiEventMessage.RmiEventType, org.slf4j.Logger, .LoggerFactory

An RMI based implementation of CachePeer.

This class features a customised RMIClientSocketFactory which enables socket timeouts to be configured.

Author
Greg Luck
Version
$Id: RMICachePeer.java 10789 2018-04-26 02:08:13Z adahanne $

Field Summary

Modifier and TypeField and Description
private final Ehcache
private final String
private static final Logger
private Integer
private final Integer

Constructor Summary

AccessConstructor and Description
public
RMICachePeer(Ehcache
The cache attached to the peer
cache
,
String
The host name the peer is running on.
hostName
,
Integer
The port number on which the RMI Registry listens. Should be an unused port in the range 1025 - 65536
rmiRegistryPort
,
Integer
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 - 65536
remoteObjectPort
,
Integer socketTimeoutMillis)

Construct a new remote peer.

Method Summary

Modifier and TypeMethod and Description
pack-priv final Ehcache
getBoundCacheInstance()

Gets the cache instance that this listener is bound to

public List<E>

Returns:

a list of Elements. If an element was not found or null, it will not be in the list.
getElements
(List<E>
a list of serializable values which represent keys
keys
)

Implements net.sf.ehcache.distribution.CachePeer.getElements.

Gets a list of elements from the cache, for a list of keys, without updating Element statistics.
public final String
getGuid()

Implements net.sf.ehcache.distribution.CachePeer.getGuid.

Gets the globally unique id for the underlying Cache instance.
public List<E>

Returns:

a list of Object keys
getKeys
()

Implements net.sf.ehcache.distribution.CachePeer.getKeys.

Returns a list of all elements in the cache, whether or not they are expired.
public final String
getName()

Implements net.sf.ehcache.distribution.CachePeer.getName.

Gets the cache name
public Element

Returns:

the element, or null, if it does not exist.
getQuiet
(Serializable
a serializable value
key
)

Implements net.sf.ehcache.distribution.CachePeer.getQuiet.

Gets an element from the cache, without updating Element statistics.
public final String

Returns:

the URL, without the scheme, as a string e.g. //hostname:port/cacheName
getUrl
()

Implements net.sf.ehcache.distribution.CachePeer.getUrl.

The URL for the remote replicator to connect.
public final String

Returns:

the URL, without the scheme, as a string e.g. //hostname:port
getUrlBase
()

Implements net.sf.ehcache.distribution.CachePeer.getUrlBase.

The URL base for the remote replicator to connect.
public void
put(Element element)

Implements net.sf.ehcache.distribution.CachePeer.put.

Puts an Element into the underlying cache without notifying listeners or updating statistics.
public boolean

Returns:

true if the element was removed, false if it was not found in the cache
remove
(Serializable key)

Implements net.sf.ehcache.distribution.CachePeer.remove.

Removes an Element from the underlying cache without notifying listeners or updating statistics.
public void
removeAll()

Implements net.sf.ehcache.distribution.CachePeer.removeAll.

Removes all cached items.
public void
send(List<E>
a list of type EventMessage
eventMessages
)

Implements net.sf.ehcache.distribution.CachePeer.send.

Send the cache peer with an ordered list of EventMessages

This enables multiple messages to be delivered in one network invocation.

public String
toString()

Overrides java.rmi.server.RemoteObject.toString.

Returns a String that represents the value of this object.
Inherited from java.rmi.server.UnicastRemoteObject:
cloneexportObjectexportObjectexportObjectexportObjectexportObjectunexportObject

Field Detail

cacheback to summary
private final Ehcache cache
hostnameback to summary
private final String hostname
LOGback to summary
private static final Logger LOG
remoteObjectPortback to summary
private Integer remoteObjectPort
rmiRegistryPortback to summary
private final Integer rmiRegistryPort

Constructor Detail

RMICachePeerback to summary
public RMICachePeer(Ehcache cache, String hostName, Integer rmiRegistryPort, Integer remoteObjectPort, Integer socketTimeoutMillis) throws RemoteException

Construct a new remote peer.

Parameters
cache:Ehcache

The cache attached to the peer

hostName:String

The host name the peer is running on.

rmiRegistryPort:Integer

The port number on which the RMI Registry listens. Should be an unused port in the range 1025 - 65536

remoteObjectPort:Integer

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 - 65536

Method Detail

getBoundCacheInstanceback to summary
pack-priv final Ehcache getBoundCacheInstance()

Gets the cache instance that this listener is bound to

getElementsback to summary
public List<E> getElements(List<E> keys) throws RemoteException

Implements net.sf.ehcache.distribution.CachePeer.getElements.

Gets 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.

Parameters
keys:List<E>

a list of serializable values which represent keys

Returns:List<E>

a list of Elements. If an element was not found or null, it will not be in the list.

getGuidback to summary
public final String getGuid() throws RemoteException

Implements net.sf.ehcache.distribution.CachePeer.getGuid.

Doc from net.sf.ehcache.distribution.CachePeer.getGuid.

Gets the globally unique id for the underlying Cache instance.

Returns:String

a String representation of the GUID

getKeysback to summary
public List<E> getKeys() throws RemoteException

Implements net.sf.ehcache.distribution.CachePeer.getKeys.

Returns 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.

Returns:List<E>

a list of Object keys

getNameback to summary
public final String getName() throws RemoteException

Implements net.sf.ehcache.distribution.CachePeer.getName.

Gets the cache name

getQuietback to summary
public Element getQuiet(Serializable key) throws RemoteException

Implements net.sf.ehcache.distribution.CachePeer.getQuiet.

Gets an element from the cache, without updating Element statistics. Cache statistics are still updated.

Parameters
key:Serializable

a serializable value

Returns:Element

the element, or null, if it does not exist.

getUrlback to summary
public final String getUrl()

Implements net.sf.ehcache.distribution.CachePeer.getUrl.

Doc from net.sf.ehcache.distribution.CachePeer.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.

Returns:String

the URL, without the scheme, as a string e.g. //hostname:port/cacheName

getUrlBaseback to summary
public final String getUrlBase()

Implements net.sf.ehcache.distribution.CachePeer.getUrlBase.

Doc from net.sf.ehcache.distribution.CachePeer.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.

Returns:String

the URL, without the scheme, as a string e.g. //hostname:port

putback to summary
public void put(Element element) throws RemoteException, IllegalArgumentException, IllegalStateException

Implements net.sf.ehcache.distribution.CachePeer.put.

Puts an Element into the underlying cache without notifying listeners or updating statistics.

Exceptions
IllegalArgumentException:

Doc from net.sf.ehcache.distribution.CachePeer.put.

if the element is null

IllegalStateException:

Doc from net.sf.ehcache.distribution.CachePeer.put.

if the cache is not net.sf.ehcache.Status#STATUS_ALIVE

removeback to summary
public boolean remove(Serializable key) throws RemoteException, IllegalStateException

Implements net.sf.ehcache.distribution.CachePeer.remove.

Removes an Element from the underlying cache without notifying listeners or updating statistics.

Returns:boolean

true if the element was removed, false if it was not found in the cache

Exceptions
IllegalStateException:

Doc from net.sf.ehcache.distribution.CachePeer.remove.

if the cache is not net.sf.ehcache.Status#STATUS_ALIVE

removeAllback to summary
public void removeAll() throws RemoteException, IllegalStateException

Implements net.sf.ehcache.distribution.CachePeer.removeAll.

Removes all cached items.

Exceptions
IllegalStateException:
if the cache is not net.sf.ehcache.Status#STATUS_ALIVE
sendback to summary
public void send(List<E> eventMessages) throws RemoteException

Implements net.sf.ehcache.distribution.CachePeer.send.

Send the cache peer with an ordered list of EventMessages

This enables multiple messages to be delivered in one network invocation.

Parameters
eventMessages:List<E>

Doc from net.sf.ehcache.distribution.CachePeer.send.

a list of type EventMessage

toStringback to summary
public String toString()

Overrides java.rmi.server.RemoteObject.toString.

Returns a String that represents the value of this object.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.