[英]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. 我试图建立一个可以同时在本地网络和同一台计算机上运行的复制ehcache。 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. 我知道使用对等侦听器工厂端口(40001、40002等)可能会起作用,但我希望有一种配置在两种情况下都“可以正常使用”。
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. 尝试在cacheManagerPeerListenerFactory中使用hostname = localhost y port = 0。 It should work. 它应该工作。
If you set up 0 for port, RMICacheManagerPeerListenerFactory will allocate differents random ports intead of the same. 如果将端口设置为0,则RMICacheManagerPeerListenerFactory将为相同的端口分配不同的随机端口。
short answer is i cant. 简短的回答是我不能。 the jgroups support in ehcache 2.5 doesnt work and with RMI each node needs its own port. ehcache 2.5中的jgroups支持不起作用,并且对于RMI,每个节点都需要自己的端口。
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. 我最终要做的是从xml创建conf,从属性字段中解析出对等侦听器工厂的端口,并运行创建ServerSockets的循环,直到找到可用端口(这意味着ServerSocket构造函数不会抛出异常)并使用那。 its ugly but it works 它很丑但是可以用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.