2011-12-13 31 views
1

即时尝试设置可以在本地网络和同一台机器上运行的复制ehcache。我目前的配置是这样的:使用单个配置在同一台机器上运行ehcache的多个实例

<?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> 

此功能适用于各种不同的机器上,但不与在同一台机器上的多个实例。 我知道玩对方听众的工厂端口(40001,40002等)将probbaly工作,但我希望有一个配置,将“在两种情况下工作”。

回答

0

简短的回答是我不能。 ehcache 2.5中的jgroups支持不起作用,并且RMI中的每个节点都需要自己的端口。

我最终做的是从xml创建conf,将端口从对等侦听器工厂的属性字段中解析出来,并运行一个创建ServerSockets的循环,直到它找到一个空闲端口(意味着ServerSocket构造函数不会抛出例外)并使用它。 它的丑陋,但它的作品

0

我知道这是老话题,但我也有类似的问题。在这种情况下,我使用如下配置:

<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"  properties="" /> 
相关问题