2016-03-09 2 views
2

Я пытаюсь настроить репликацию кеша между двумя tomcat на том же компьютере. Кэш работает отлично, но репликации нет.Ehcache не реплицируется между двумя tomcat на том же компьютере

Для моего теста я вызываю метод подсчета на сервере 1. Затем добавляю объект на сервер 2 и вызываю метод подсчета на сервере 2. Наконец, я снова вызываю метод подсчета на сервере 1: кэш попадает и мой добавленный объект не найден.

Tomcat версии: 6, версия Java: 1.6, Ehcache версия: 1.3, ОС: Linux

Войти при запуске (то же самое для обоих серверов):

DEBUG net.sf.ehcache.store.MemoryStore - Initialized net.sf.ehcache.store.LruMemoryStore for myCacheSample 
DEBUG net.sf.ehcache.store.LruMemoryStore - myCacheSample Cache: Using SpoolingLinkedHashMap implementation 
DEBUG net.sf.ehcache.Cache - Initialised cache: myCacheSample 
DEBUG net.sf.ehcache.distribution.RMICacheManagerPeerListener - Adding myCacheSample to RMI listener 
DEBUG net.sf.ehcache.distribution.RMICacheManagerPeerListener - 0 RMICachePeers bound in registry for RMI listener 

Код добавления:

public void persist(MyEntity myEntity) { 
    getEntityManager().persist(myEntity); 
} 

Код подсчитывать с установкой кэша:

public int count(String criteriaStr) { 
    Criteria criteria = ((HibernateEntityManager) getEntityManager()).getSession().createCriteria(MyEntity.class); 
    criteria.setCacheable(true).setCacheRegion("myCacheSample"); 
    criteria.add(Restrictions.eq("criteriaStr", criteriaStr)); 
    return (Integer) criteria.setProjection(Projections.rowCount()).uniqueResult(); 
} 

Код удалить:

public void remove(MyEntity myEntity) { 
    getEntityManager().remove(myEntity); 
    getEntityManager().flush(); 
} 

Сервер 1 ehcache.xml (для сервера 2: порты 40001 и 40002 переключаются):

<cacheManagerPeerProviderFactory 
    class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" 
    properties="peerDiscovery=manual, 
    rmiUrls=//localhost:40002/myCacheSample"/> 

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

<defaultCache 
    diskExpiryThreadIntervalSeconds="120" 
    diskPersistent="false" 
    eternal="false" 
    maxElementsInMemory="1000" 
    memoryStoreEvictionPolicy="LRU" 
    overflowToDisk="true" 
    timeToIdleSeconds="120" 
    timeToLiveSeconds="120"> 

<cacheEventListenerFactory 
    class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" 
    properties=" 
     asynchronousReplicationIntervalMillis=1000, 
     replicateAsynchronously=true, 
     replicatePuts=false, 
     replicateRemovals=true, 
     replicateUpdates=true, 
     replicateUpdatesViaCopy=false 
    "/> 

<cache 
    eternal="false" 
    maxElementsInMemory="1000" 
    timeToLiveSeconds="300" 
    timeToIdleSeconds="300" 
    name="myCacheSample" 
    overflowToDisk="false"/> 

Спасибо за ответы!

+0

Это работает, когда два кота находятся на разных серверах? – avianey

+0

Нет, но я не уверен в администрировании сети (межсетевой экран, порты и т. Д.). Вот почему я тестирую на той же машине раньше, а не в режиме многоадресной рассылки. – elfdev

ответ

0

Рабочая конфигурация репликации RMI для 3 экземпляров tomcat Надеюсь, что это сработает для вас.

Server 1 

<cacheManagerPeerProviderFactory 
    class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" 
    properties="peerDiscovery=manual, rmiUrls=//localhost:40002/apicache|//localhost:40003/apicache" /> 

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

Server 2   

<cacheManagerPeerProviderFactory 
    class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" 
    properties="peerDiscovery=manual, rmiUrls=//localhost:40001/apicache|//localhost:40003/apicache" /> 

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

Server 3 

<cacheManagerPeerProviderFactory 
    class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" 
    properties="peerDiscovery=manual, rmiUrls=//localhost:40001/apicache|//localhost:40002/apicache" /> 

<cacheManagerPeerListenerFactory 
    class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" 
    properties="hostName=192.168.1.152, port=40003, socketTimeoutMillis=2000" /> 
Смежные вопросы