Setting up ehcache replication - what multicast settings do I need?

One mistake I encountered during EHCache peer replication. This might be useful so someone attempting peer replication on a single local box.

I wanted to run 3 peer-replicated instances of EhCache on a single Windows Vista box using peerDiscovery=automatic (the eventual target environment was Linux).

The peer-replication did not work. Oddly, all EhCache instances were starting-up without any errors or complaints in the log.

Took me a while to figure my mistake; without anything in the logs I had to grok around: I was using the same listenerPort (40001) in the peer listener configuration for each of the EhCache instances. Using different listenerPorts (40001, 40002...) did the trick.

<cacheManagerPeerListenerFactory 
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" 
properties="port=40001, socketTimeoutMillis=3000"/>

<cacheManagerPeerListenerFactory 
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" 
properties="port=40002, socketTimeoutMillis=3000"/>

Note that this is the 'peer listener' configuration that needed different port numbers. The multicast 'peer discovery' still uses identical multicast address and port numbers for every ehcache instance.


I want to test it locally so am running two separate tomcat instances with the above config.

As I have just submitted an answer regarding cherouvims related question I'd just like to highlight here too that they are in fact providing an example doing something similar at least (multiple nodes per host, though one instance only): see section Full Example in the RMI Distributed Caching documentation.

It's indeed important to change the TCP port for each cacheManagerPeerListenerFactory but the multicast settings can (I'd think they must) stay the same: you can see this in action within the ehcache.xml's for the Full Example mentioned above: the port number is increased one by one from 40001 up to 40006 per node while the multicast settings stay identical.

If you have obeyed that, your problem might just be related to Tomcat running on Windows - see the related paragraph within section Common Problems in RMI Distributed Caching:

There is a bug in Tomcat and/or the JDK where any RMI listener will fail to start on Tomcat if the installation path has spaces in it.
[...]
As the default on Windows is to install Tomcat in "Program Files", this issue will occur by default.


Make sure your servers have multicast enabled for starters. Not sure what platform you are running on.