ehcache

net.sf.ehcache.distribution
Class RMICachePeer

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by net.sf.ehcache.distribution.RMICachePeer
All Implemented Interfaces:
Serializable, Remote, CachePeer
Direct Known Subclasses:
TransactionalRMICachePeer

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 5594 2012-05-07 16:04:31Z cdennis $
Author:
Greg Luck
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
RMICachePeer(Ehcache cache, String hostName, Integer rmiRegistryPort, Integer remoteObjectPort, Integer socketTimeoutMillis)
          Construct a new remote peer.
 
Method Summary
 List getElements(List keys)
          Gets a list of elements from the cache, for a list of keys, without updating Element statistics.
 String getGuid()
          Gets the globally unique id for the underlying Cache instance.
 List getKeys()
          Returns a list of all elements in the cache, whether or not they are expired.
 String getName()
          Gets the cache name
 Element getQuiet(Serializable key)
          Gets an element from the cache, without updating Element statistics.
 String getUrl()
          The URL for the remote replicator to connect.
 String getUrlBase()
          The URL base for the remote replicator to connect.
 void put(Element element)
          Puts an Element into the underlying cache without notifying listeners or updating statistics.
 boolean remove(Serializable key)
          Removes an Element from the underlying cache without notifying listeners or updating statistics.
 void removeAll()
          Removes all cached items.
 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.

 String toString()
          Returns a String that represents the value of this object.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RMICachePeer

public RMICachePeer(Ehcache cache,
                    String hostName,
                    Integer rmiRegistryPort,
                    Integer remoteObjectPort,
                    Integer socketTimeoutMillis)
             throws RemoteException
Construct a new remote peer.

Parameters:
cache - The cache attached to the peer
hostName - 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 - 65536
remoteObjectPort - 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
socketTimeoutMillis -
Throws:
RemoteException
Method Detail

getUrl

public final 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.

Specified by:
getUrl in interface CachePeer
Returns:
the URL, without the scheme, as a string e.g. //hostname:port/cacheName

getUrlBase

public final 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:
getUrlBase in interface CachePeer
Returns:
the URL, without the scheme, as a string e.g. //hostname:port

getKeys

public List getKeys()
             throws RemoteException
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.

Specified by:
getKeys in interface CachePeer
Returns:
a list of Object keys
Throws:
RemoteException

getQuiet

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

Specified by:
getQuiet in interface CachePeer
Parameters:
key - a serializable value
Returns:
the element, or null, if it does not exist.
Throws:
RemoteException

getElements

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

Specified by:
getElements in interface CachePeer
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:
RemoteException

put

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

Specified by:
put in interface CachePeer
Parameters:
element -
Throws:
RemoteException
IllegalArgumentException
IllegalStateException

remove

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

Specified by:
remove in interface CachePeer
Parameters:
key -
Returns:
true if the element was removed, false if it was not found in the cache
Throws:
RemoteException
IllegalStateException

removeAll

public void removeAll()
               throws RemoteException,
                      IllegalStateException
Removes all cached items.

Specified by:
removeAll in interface CachePeer
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
RemoteException

send

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

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

Specified by:
send in interface CachePeer
Parameters:
eventMessages - a list of type EventMessage
Throws:
RemoteException

getName

public final String getName()
                     throws RemoteException
Gets the cache name

Specified by:
getName in interface CachePeer
Throws:
RemoteException

getGuid

public final String getGuid()
                     throws RemoteException
Gets the globally unique id for the underlying Cache instance.

Specified by:
getGuid in interface CachePeer
Returns:
a String representation of the GUID
Throws:
RemoteException

toString

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

Overrides:
toString in class RemoteObject

ehcache

Copyright 2001-2015, Terracotta, Inc.