public class RMICacheManagerPeerListener extends Object implements net.sf.ehcache.distribution.CacheManagerPeerListener
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
Doing so would require the addition of grant statements in the java.policy file.
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.| Modifier and Type | Field and Description |
|---|---|
protected net.sf.ehcache.CacheManager |
cacheManager |
protected Map |
cachePeers
The cache peers.
|
protected String |
hostName |
protected Integer |
port
The RMI listener port
|
protected Registry |
registry |
protected boolean |
registryCreated |
protected Integer |
remoteObjectPort |
protected Integer |
socketTimeoutMillis |
protected net.sf.ehcache.Status |
status
status.
|
| Constructor and Description |
|---|
RMICacheManagerPeerListener(String hostName,
Integer port,
Integer remoteObjectPort,
net.sf.ehcache.CacheManager cacheManager,
Integer socketTimeoutMillis)
Constructor with full arguments.
|
| Modifier and Type | Method and Description |
|---|---|
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(String peerName,
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.
|
String |
getScheme()
The replication scheme this listener interacts with.
|
net.sf.ehcache.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(net.sf.ehcache.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 |
startRegistry()
Start the rmiregistry.
|
protected void |
stopRegistry()
Stop the rmiregistry if it was started by this class.
|
protected void |
unbind(RMICachePeer rmiCachePeer)
Unbinds an RMICachePeer and unexports it.
|
protected final Map cachePeers
protected net.sf.ehcache.Status status
protected Integer port
protected Registry registry
protected boolean registryCreated
protected final String hostName
protected net.sf.ehcache.CacheManager cacheManager
protected Integer socketTimeoutMillis
protected Integer remoteObjectPort
public RMICacheManagerPeerListener(String hostName, Integer port, Integer remoteObjectPort, net.sf.ehcache.CacheManager cacheManager, Integer socketTimeoutMillis) throws UnknownHostException
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 - 65536remoteObjectPort - the port number on which the remote objects bound in the registry receive calls.
This defaults to a free port if not specified.cacheManager - the CacheManager this listener belongs tosocketTimeoutMillis - TCP/IP Socket timeout when waiting on responseUnknownHostExceptionprotected void assignFreePort(boolean forced)
throws IllegalStateException
IllegalStateException - if the statis of the listener is not Status.STATUS_UNINITIALISEDprotected String calculateHostAddress() throws UnknownHostException
UnknownHostExceptionprotected int getFreePort()
throws IllegalArgumentException
IllegalArgumentExceptionpublic void init()
throws net.sf.ehcache.CacheException
init in interface net.sf.ehcache.event.CacheManagerEventListenernet.sf.ehcache.CacheExceptionprotected void bind(String peerName, RMICachePeer rmiCachePeer) throws Exception
rmiCachePeer - Exceptionprotected String[] listBoundRMICachePeers() throws net.sf.ehcache.CacheException
RMICachePeer objectsnet.sf.ehcache.CacheExceptionprotected Remote lookupPeer(String name) throws net.sf.ehcache.CacheException
name - the name of the cache e.g. sampleCache1net.sf.ehcache.CacheExceptionprotected void populateListOfRemoteCachePeers()
throws RemoteException
RemoteExceptionprotected boolean isDistributed(net.sf.ehcache.Ehcache cache)
cache - the cache to checkCacheReplicator is found in the listenersprotected void startRegistry()
throws RemoteException
rmiregistry binary, in which case:
RemoteExceptionprotected void stopRegistry()
throws RemoteException
RemoteExceptionpublic void dispose()
throws net.sf.ehcache.CacheException
dispose in interface net.sf.ehcache.event.CacheManagerEventListenernet.sf.ehcache.CacheExceptionprotected void disposeRMICachePeer(RMICachePeer rmiCachePeer) throws Exception
rmiCachePeer - the cache peer to dispose ofException - thrown if something goes wrongprotected void unbind(RMICachePeer rmiCachePeer) throws Exception
rmiCachePeer - the bound and exported cache peerExceptionpublic List getBoundCachePeers()
getBoundCachePeers in interface net.sf.ehcache.distribution.CacheManagerPeerListenerRMICachePeer objects. The list if not livepublic net.sf.ehcache.Status getStatus()
getStatus in interface net.sf.ehcache.event.CacheManagerEventListenerpublic String getUniqueResourceIdentifier()
getUniqueResourceIdentifier in interface net.sf.ehcache.distribution.CacheManagerPeerListenerpublic void attemptResolutionOfUniqueResourceConflict()
throws IllegalStateException,
net.sf.ehcache.CacheException
attemptResolutionOfUniqueResourceConflict in interface net.sf.ehcache.distribution.CacheManagerPeerListenerIllegalStateException - if the statis of the listener is not Status.STATUS_UNINITIALISEDnet.sf.ehcache.CacheExceptionpublic String getScheme()
getScheme in interface net.sf.ehcache.distribution.CacheManagerPeerListenerpublic void notifyCacheAdded(String cacheName) throws net.sf.ehcache.CacheException
Status.STATUS_UNINITIALISED to Status.STATUS_ALIVE. Care should be
taken on processing that notification because:
CacheManager.getCache(String) will cause a deadlock.
notifyCacheAdded in interface net.sf.ehcache.event.CacheManagerEventListenercacheName - the name of the Cache the operation relates tonet.sf.ehcache.CacheExceptionCacheEventListenerpublic void notifyCacheRemoved(String cacheName)
CacheEventListener status changed will also be triggered. Any attempt from that notification
to access CacheManager will also result in a deadlock.notifyCacheRemoved in interface net.sf.ehcache.event.CacheManagerEventListenercacheName - the name of the Cache the operation relates toCopyright © 2002-2023 Atlassian. All Rights Reserved.