Package net.sf.ehcache.distribution
Class MulticastRMICacheManagerPeerProvider
- java.lang.Object
-
- net.sf.ehcache.distribution.RMICacheManagerPeerProvider
-
- net.sf.ehcache.distribution.MulticastRMICacheManagerPeerProvider
-
- All Implemented Interfaces:
CacheManagerPeerProvider
public final class MulticastRMICacheManagerPeerProvider extends RMICacheManagerPeerProvider implements CacheManagerPeerProvider
A peer provider which discovers peers using Multicast.Hosts can be in three different levels of conformance with the Multicast specification (RFC1112), according to the requirements they meet.
- Level 0 is the "no support for IP Multicasting" level. Lots of hosts and routers in the Internet are in this state, as multicast support is not mandatory in IPv4 (it is, however, in IPv6). Not too much explanation is needed here: hosts in this level can neither send nor receive multicast packets. They must ignore the ones sent by other multicast capable hosts.
- Level 1 is the "support for sending but not receiving multicast IP datagrams" level. Thus, note that it is not necessary to join a multicast group to be able to send datagrams to it. Very few additions are needed in the IP module to make a "Level 0" host "Level 1-compliant".
- Level 2 is the "full support for IP multicasting" level. Level 2 hosts must be able to both send and receive multicast traffic. They must know the way to join and leave multicast groups and to propagate this information to multicast routers. Thus, they must include an Internet Group Management Protocol (IGMP) implementation in their TCP/IP stack.
The list of CachePeers is maintained via heartbeats. rmiUrls are looked up using RMI and converted to CachePeers on registration. On lookup any stale references are removed.
- Version:
- $Id$
- Author:
- Greg Luck
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classMulticastRMICacheManagerPeerProvider.CachePeerEntryEntry containing a looked up CachePeer and date
-
Field Summary
Fields Modifier and Type Field Description protected static intSHORT_DELAYOne tenth of a second, in ms-
Fields inherited from class net.sf.ehcache.distribution.RMICacheManagerPeerProvider
cacheManager, peerUrls
-
-
Constructor Summary
Constructors Constructor Description MulticastRMICacheManagerPeerProvider(CacheManager cacheManager, java.net.InetAddress groupMulticastAddress, java.lang.Integer groupMulticastPort, java.lang.Integer timeToLive, java.net.InetAddress hostAddress)Creates and starts a multicast peer provider
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()Shutdown the heartbeatMulticastKeepaliveHeartbeatReceivergetHeartBeatReceiver()MulticastKeepaliveHeartbeatSendergetHeartBeatSender()protected longgetStaleTime()The time after which an unrefreshed peer provider entry is considered stale.longgetTimeForClusterToForm()Time for a cluster to form.voidinit()Notifies providers to initialise themselves.java.util.ListlistRemoteCachePeers(Ehcache cache)voidregisterPeer(java.lang.String rmiUrl)Register a new peer, but only if the peer is new, otherwise the last seen timestamp is updated.protected booleanstale(java.util.Date date)Whether the entry should be considered stale.-
Methods inherited from class net.sf.ehcache.distribution.RMICacheManagerPeerProvider
getCacheManager, getScheme, lookupRemoteCachePeer, unregisterPeer
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.ehcache.distribution.CacheManagerPeerProvider
getScheme, unregisterPeer
-
-
-
-
Field Detail
-
SHORT_DELAY
protected static final int SHORT_DELAY
One tenth of a second, in ms- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MulticastRMICacheManagerPeerProvider
public MulticastRMICacheManagerPeerProvider(CacheManager cacheManager, java.net.InetAddress groupMulticastAddress, java.lang.Integer groupMulticastPort, java.lang.Integer timeToLive, java.net.InetAddress hostAddress)
Creates and starts a multicast peer provider- Parameters:
groupMulticastAddress- 224.0.0.1 to 239.255.255.255 e.g. 230.0.0.1groupMulticastPort- 1025 to 65536 e.g. 4446hostAddress- the address of the interface to use for sending and receiving multicast. May be null.
-
-
Method Detail
-
init
public final void init() throws CacheExceptionNotifies providers to initialise themselves.- Specified by:
initin interfaceCacheManagerPeerProvider- Specified by:
initin classRMICacheManagerPeerProvider- Throws:
CacheException
-
registerPeer
public final void registerPeer(java.lang.String rmiUrl)
Register a new peer, but only if the peer is new, otherwise the last seen timestamp is updated.This method is thread-safe. It relies on peerUrls being a synchronizedMap
- Specified by:
registerPeerin interfaceCacheManagerPeerProvider- Specified by:
registerPeerin classRMICacheManagerPeerProvider- Parameters:
rmiUrl-
-
listRemoteCachePeers
public final java.util.List listRemoteCachePeers(Ehcache cache) throws CacheException
- Specified by:
listRemoteCachePeersin interfaceCacheManagerPeerProvider- Specified by:
listRemoteCachePeersin classRMICacheManagerPeerProvider- Returns:
- a list of
CachePeerpeers, excluding the local peer. - Throws:
CacheException
-
dispose
public final void dispose()
Shutdown the heartbeat- Specified by:
disposein interfaceCacheManagerPeerProvider- Overrides:
disposein classRMICacheManagerPeerProvider
-
getTimeForClusterToForm
public long getTimeForClusterToForm()
Time for a cluster to form. This varies considerably, depending on the implementation.- Specified by:
getTimeForClusterToFormin interfaceCacheManagerPeerProvider- Returns:
- the time in ms, for a cluster to form
-
getStaleTime
protected long getStaleTime()
The time after which an unrefreshed peer provider entry is considered stale.
-
stale
protected final boolean stale(java.util.Date date)
Whether the entry should be considered stale. This will depend on the type of RMICacheManagerPeerProvider. This method should be overridden for implementations that go stale based on date- Specified by:
stalein classRMICacheManagerPeerProvider- Parameters:
date- the date the entry was created- Returns:
- true if stale
-
getHeartBeatReceiver
public MulticastKeepaliveHeartbeatReceiver getHeartBeatReceiver()
- Returns:
- the MulticastKeepaliveHeartbeatReceiver
-
getHeartBeatSender
public MulticastKeepaliveHeartbeatSender getHeartBeatSender()
- Returns:
- the MulticastKeepaliveHeartbeatSender
-
-