ehcache

net.sf.ehcache.distribution
Class MulticastRMICacheManagerPeerProvider

java.lang.Object
  extended by net.sf.ehcache.distribution.RMICacheManagerPeerProvider
      extended by 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.

  1. 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.
  2. 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".
  3. 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: MulticastRMICacheManagerPeerProvider.java 6488 2012-10-30 17:55:04Z cdennis $
Author:
Greg Luck

Nested Class Summary
protected static class MulticastRMICacheManagerPeerProvider.CachePeerEntry
          Entry containing a looked up CachePeer and date
 
Field Summary
protected static int SHORT_DELAY
          One tenth of a second, in ms
 
Fields inherited from class net.sf.ehcache.distribution.RMICacheManagerPeerProvider
cacheManager, peerUrls
 
Constructor Summary
MulticastRMICacheManagerPeerProvider(CacheManager cacheManager, InetAddress groupMulticastAddress, Integer groupMulticastPort, Integer timeToLive, InetAddress hostAddress)
          Creates and starts a multicast peer provider
 
Method Summary
 void dispose()
          Shutdown the heartbeat
 MulticastKeepaliveHeartbeatReceiver getHeartBeatReceiver()
           
 MulticastKeepaliveHeartbeatSender getHeartBeatSender()
           
protected  long getStaleTime()
          The time after which an unrefreshed peer provider entry is considered stale.
 long getTimeForClusterToForm()
          Time for a cluster to form.
 void init()
          Notifies providers to initialise themselves.
 List listRemoteCachePeers(Ehcache cache)
           
 void registerPeer(String rmiUrl)
          Register a new peer, but only if the peer is new, otherwise the last seen timestamp is updated.
protected  boolean stale(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,
                                            InetAddress groupMulticastAddress,
                                            Integer groupMulticastPort,
                                            Integer timeToLive,
                                            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.1
groupMulticastPort - 1025 to 65536 e.g. 4446
hostAddress - the address of the interface to use for sending and receiving multicast. May be null.
Method Detail

init

public final void init()
                throws CacheException
Notifies providers to initialise themselves.

Specified by:
init in interface CacheManagerPeerProvider
Specified by:
init in class RMICacheManagerPeerProvider
Throws:
CacheException

registerPeer

public final void registerPeer(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:
registerPeer in interface CacheManagerPeerProvider
Specified by:
registerPeer in class RMICacheManagerPeerProvider
Parameters:
rmiUrl -

listRemoteCachePeers

public final List listRemoteCachePeers(Ehcache cache)
                                throws CacheException
Specified by:
listRemoteCachePeers in interface CacheManagerPeerProvider
Specified by:
listRemoteCachePeers in class RMICacheManagerPeerProvider
Returns:
a list of CachePeer peers, excluding the local peer.
Throws:
CacheException

dispose

public final void dispose()
Shutdown the heartbeat

Specified by:
dispose in interface CacheManagerPeerProvider
Overrides:
dispose in class RMICacheManagerPeerProvider

getTimeForClusterToForm

public long getTimeForClusterToForm()
Time for a cluster to form. This varies considerably, depending on the implementation.

Specified by:
getTimeForClusterToForm in interface CacheManagerPeerProvider
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(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:
stale in class RMICacheManagerPeerProvider
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

ehcache

Copyright 2001-2014, Terracotta, Inc.