net.sf.ehcache.distribution

Class RMICachePeer

public class RMICachePeer extends UnicastRemoteObject implements CachePeer, Remote

An RMI based implementation of CachePeer.

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

Version: $Id: RMICachePeer.java 191 2006-09-03 22:41:48Z gregluck $

Author: Greg Luck

UNKNOWN: FieldCanBeLocal

Constructor Summary
RMICachePeer(Ehcache cache, String hostName, Integer port, Integer socketTimeoutMillis)
Construct a new remote peer.
Method Summary
EhcachegetBoundCacheInstance()
Gets the cache instance that this listener is bound to
ListgetElements(List keys)
Gets a list of elements from the cache, for a list of keys, without updating Element statistics.
StringgetGuid()
ListgetKeys()
Returns a list of all elements in the cache, whether or not they are expired.
StringgetName()
Gets the cache name
ElementgetQuiet(Serializable key)
Gets an element from the cache, without updating Element statistics.
StringgetUrl()
{@inheritDoc }

This implementation gives an URL which has meaning to the RMI remoting system.

StringgetUrlBase()
{@inheritDoc }

This implementation gives an URL which has meaning to the RMI remoting system.

voidput(Element element)
Puts an Element into the underlying cache without notifying listeners or updating statistics.
booleanremove(Serializable key)
Removes an Element from the underlying cache without notifying listeners or updating statistics.
voidremoveAll()
Removes all cached items.
voidsend(List eventMessages)
Send the cache peer with an ordered list of EventMessages

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

StringtoString()
Returns a String that represents the value of this object.

Constructor Detail

RMICachePeer

public RMICachePeer(Ehcache cache, String hostName, Integer port, Integer socketTimeoutMillis)
Construct a new remote peer.

Parameters: cache hostName port socketTimeoutMillis

Throws: RemoteException

Method Detail

getBoundCacheInstance

final Ehcache getBoundCacheInstance()
Gets the cache instance that this listener is bound to

getElements

public List getElements(List keys)
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 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.

getGuid

public final String getGuid()
{@inheritDoc }

getKeys

public List 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: a list of Object keys

getName

public final String getName()
Gets the cache name

getQuiet

public Element getQuiet(Serializable key)
Gets an element from the cache, without updating Element statistics. Cache statistics are still updated.

Parameters: key a serializable value

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

getUrl

public final String getUrl()
{@inheritDoc }

This implementation gives an URL which has meaning to the RMI remoting system.

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

getUrlBase

public final String getUrlBase()
{@inheritDoc }

This implementation gives an URL which has meaning to the RMI remoting system.

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

put

public void put(Element element)
Puts an Element into the underlying cache without notifying listeners or updating statistics.

Parameters: element

Throws: java.rmi.RemoteException IllegalArgumentException IllegalStateException

remove

public final boolean remove(Serializable key)
Removes an Element from the underlying cache without notifying listeners or updating statistics.

Parameters: key

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

Throws: RemoteException IllegalStateException

removeAll

public final void removeAll()
Removes all cached items.

Throws: IllegalStateException if the cache is not STATUS_ALIVE

send

public final void send(List eventMessages)
Send the cache peer with an ordered list of EventMessages

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

toString

public String toString()
Returns a String that represents the value of this object.