Ehcache - Replicated Caching using RMI

7k views Asked by At

I tried using the ehcache and it worked. And I am just trying to implement distributed caching with ehcache RMI. I followed the steps provided in the url: http://ehcache.org/documentation/distributed_caching_with_rmi.html?cf03800515=21D4D871!NTAxODEzNDE0OmNvcnByYWRpdXNzc286vsRypkVtSPb7t3MnL22gFQ==#

But I could not find the distributed caching working...

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

I gave some port number and I am having the standalone java code in two machines. First, I run the main program in my friend's machine which puts data to "deviceCache1" and I try to access that cache in my main program. But I don't find any connection happening between two machines.

I may sound silly, but I need to know few things regarding caching. Please some one clarify my doubts and help me. So, My questions are: 1. What port ids need to be given in ehcache.xml in both machines? 2. Do i need to have some windows service enabled to use rmi ports? 3. Do i need to add any other code for connection between 2 machines?

Please help me asap. Thanks

2

There are 2 answers

1
Amit On

Due to comments size limitation & this will answer your question

Config on server 1 will be like this

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

Config on server2 will be like this

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

If you are still facing the issue, paste your ehcache.xml. Kindly accept the answer if it answers your question.

1
Amit On

You would also need to add cacheEventListenerFactory to the cache(which needs to be replicated)

memoryStoreEvictionPolicy="LFU" diskPersistent="true"
timeToLiveSeconds="86400" maxElementsOnDisk="1000">

You can give any port(which is not being used by system