net.sf.ehcache.distribution
public class RMICacheManagerPeerListener extends Object implements CacheManagerPeerListener
if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); }Doing so would require the addition of
grant
statements in the java.policy
file.
Per the JDK documentation: "If no security manager is specified no class loading, by RMI clients or servers, is allowed,
aside from what can be found in the local CLASSPATH." The classpath of each instance of this class should have
all required classes to enable distribution, so no remote classloading is required or desirable. Accordingly,
no security manager is set and there are no special JVM configuration requirements.
This class opens a ServerSocket. The dispose method should be called for orderly closure of that socket. This class
has a shutdown hook which calls dispose() as a convenience feature for developers.Version: $Id: RMICacheManagerPeerListener.java 191 2006-09-03 22:41:48Z gregluck $
Field Summary | |
---|---|
protected Map | cachePeers
The cache peers. |
protected Integer | port
The RMI listener port |
protected Status | status
status. |
Constructor Summary | |
---|---|
RMICacheManagerPeerListener(String hostName, Integer port, CacheManager cacheManager, Integer socketTimeoutMillis)
Constructor with full arguments.
|
Method Summary | |
---|---|
void | addCachePeer(String name, RMICachePeer peer)
Package local method for testing |
protected void | assignFreePort(boolean forced)
Assigns a free port to be the listener port.
|
void | attemptResolutionOfUniqueResourceConflict()
If a conflict is detected in unique resource use, this method signals the listener to attempt
automatic resolution of the resource conflict.
|
protected void | bind(RMICachePeer rmiCachePeer)
Bind a cache peer
|
protected String | calculateHostAddress()
Calculates the host address as the default NICs IP address
|
void | dispose()
Stop the listener. |
protected void | disposeRMICachePeer(RMICachePeer rmiCachePeer)
A template method to dispose an individual RMICachePeer. |
List | getBoundCachePeers()
All of the caches which are listening for remote changes.
|
protected int | getFreePort()
Gets a free server socket port.
|
Status | getStatus()
Returns the listener status. |
String | getUniqueResourceIdentifier()
A listener will normally have a resource that only one instance can use at the same time,
such as a port. |
void | init() |
protected boolean | isDistributed(Ehcache cache)
Determine if the given cache is distributed.
|
protected String[] | listBoundRMICachePeers()
Returns a list of bound objects.
|
protected Remote | lookupPeer(String name)
Returns a reference to the remote object.
|
void | notifyCacheAdded(String cacheName)
Called immediately after a cache has been added and activated.
|
void | notifyCacheRemoved(String cacheName)
Called immediately after a cache has been disposed and removed. |
protected void | populateListOfRemoteCachePeers()
Should be called on init because this is one of the last things that should happen on CacheManager startup. |
protected void | removeShutdownHook()
Remove the shutdown hook to prevent leaving orphaned caches around. |
protected void | startRegistry()
Start the rmiregistry.
|
protected void | unbind(RMICachePeer rmiCachePeer)
Unbinds an RMICachePeer and unexports it.
|
Parameters: hostName may be null, in which case the hostName will be looked up. Machines with multiple interfaces should specify this if they do not want it to be the default NIC. port a port in the range 1025 - 65536 cacheManager the CacheManager this listener belongs to socketTimeoutMillis TCP/IP Socket timeout when waiting on response
Throws: IllegalStateException if the statis of the listener is not STATUS_UNINITIALISED
Throws: IllegalStateException if the statis of the listener is not STATUS_UNINITIALISED
Parameters: rmiCachePeer
Throws: UnknownHostException
Parameters: rmiCachePeer the cache peer to dispose of
Throws: Exception thrown if something goes wrong
Returns: a list of RMICachePeer
objects. The list if not live
Returns: a number in the range 1025 - 65536 that was free at the time this method was executed
Throws: IllegalArgumentException
Returns: a String identifier for the resource
Parameters: cache the cache to check
Returns: true if a CacheReplicator
is found in the listeners
Returns: a list of String representations of RMICachePeer
objects
Parameters: name the name of the cache e.g. sampleCache1
Parameters: cacheName the name of the Cache
the operation relates to
See Also: CacheEventListener
Parameters: cacheName the name of the Cache
the operation relates to
rmiregistry
binary, in which case:
Throws: RemoteException
Parameters: rmiCachePeer the bound and exported cache peer
Throws: Exception