Reputation: 24192
im trying to set up a replicated ehcache that can run both over a local network and on the same machine. my current config looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<diskStore path="java.io.tmpdir"/>
<!-- clustering -->
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, multicastPacketTimeToLive=255"
propertySeparator=","/>
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostname=localhost, port=40001, socketTimeoutMillis=2000"
propertySeparator=","/>
<cache name="demo-cache"
maxEntriesLocalHeap="0"
maxEntriesLocalDisk="0"
eternal="true"
overflowToDisk="true"
maxBytesLocalHeap="10M"
diskPersistent="false"
diskSpoolBufferSizeMB="5"
clearOnFlush="false">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true "/>
</cache>
this works across different machines, but does not work with multiple instances on the same machine. i know that playing around with the peer listener factory port (40001, 40002 etc) will probbaly work, but im hoping that there's a configuration that will "just work" in both scenarios.
Upvotes: 1
Views: 2536
Reputation: 3
Try with hostname=localhost y port=0 in cacheManagerPeerListenerFactory. It should work.
If you set up 0 for port, RMICacheManagerPeerListenerFactory will allocate differents random ports intead of the same.
Upvotes: 0
Reputation: 197
I know this is old topic but I also had similar problem. In such case I used configuration like below:
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" properties="" />
Upvotes: 1
Reputation: 24192
short answer is i cant. the jgroups support in ehcache 2.5 doesnt work and with RMI each node needs its own port.
what i eventually did was create the conf from the xml, parse the port out of the properties field for the peer listener factory and run a loop that creates ServerSockets until it finds a free port (meaning the ServerSocket constructor doesnt throw an exception) and uses that. its ugly but it works
Upvotes: 0