2011-12-13 78 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="" /> 
相關問題