简体   繁体   中英

running multiple instances of ehcache on the same machine with a single config

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.

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="" />

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM