2011-02-03 107 views
2

我嘗試使用ehcache,它工作正常。我只是試圖用ehcache RMI實現分佈式緩存。我跟着網址提供的步驟:http://ehcache.org/documentation/distributed_caching_with_rmi.html?cf03800515=21D4D871!NTAxODEzNDE0OmNvcnByYWRpdXNzc286vsRypkVtSPb7t3MnL22gFQ==#Ehcache - 使用RMI進行復制緩存

但我找不到分佈式緩存的工作...

<cacheManagerPeerProviderFactory 
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" 
properties="peerDiscovery=manual, 
rmiUrls=//<remotemachineip>:<i want to know what port id should be given here>/deviceCache1"/> 

<cacheManagerPeerListenerFactory 
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" 
properties="hostName=<localmachineip>,port=<i want to know what port id should be given here>, 
socketTimeoutMillis=120000"/> 

我給一些端口號,我有兩個機器獨立的Java代碼。 首先,我在朋友的機器上運行主程序,該程序將數據放入「deviceCache1」,並嘗試在我的主程序中訪問該緩存。但是我沒有發現兩臺機器之間發生任何連接。

我聽起來很愚蠢,但我需要知道一些關於緩存的事情。請有人澄清我的疑惑並幫助我。 所以,我的問題是: 1.兩臺機器的ehcache.xml中需要給出哪些端口ID? 2.我是否需要啓用一些Windows服務才能使用rmi端口? 3.我是否需要爲兩臺機器之間的連接添加任何其他代碼?

請儘快幫助我。 感謝

回答

0

您還需要cacheEventListenerFactory添加到緩存(這需要複製)

memoryStoreEvictionPolicy = 「LFU」 diskPersistent = 「真」
timeToLiveSeconds = 「86400」 maxElementsOnDisk =」 1000" >

你可以給任何端口(未正在使用的系統

+0

我有一個與我的條目相關聯。但無論我在提供者和聽衆中給予什麼端口,都沒有看到兩個系統之間發生任何通信。我試圖從第二臺機器訪問緩存,從第二臺機器嘗試從我的機​​器訪問緩存。但是兩者都沒有響應......所以我想知道,如果我需要給任何特定的端口/我們需要啓用任何RMI相關的服務/我們是否需要編寫任何代碼來建立連接或註冊端口。 – 2011-02-04 09:45:03

3

由於評論大小限制&這將會回答你的問題

配置在服務器1會是這樣

<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" 
    properties="hostName=localhost, port=40001,socketTimeoutMillis=2000"/> 

配置Server2上會是這樣

<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" 
    properties="hostName=localhost, port=40002,socketTimeoutMillis=2000"/> 

如果你仍然面臨這個問題,請粘貼你的ehcache.xml。如果它回答你的問題,請接受答案。

+0

服務器1 - 在server2 Amit 2011-02-05 14:57:48