2016-03-06 1 views
1

J'ai les configurations ehcache suivantes pour 3 instances de tomcat différentes.Réplication de cache avec ehcache dans le cluster Tomcat

Mon hypothèse est, que dans chaque ehcache, nous devrions définir tous les autres nœuds en tant que fournisseur et ce nœud actuel en tant qu'auditeur.

Faut-il définir tous nos caches dans chaque fichier ehcache.xml? et si oui, devrions-nous également ajouter ces noms aux adresses RMI? J'ai défini les ehcaches comme ceci. La réplication de deux des caches fonctionne correctement, mais pour deux autres caches, elle ne fonctionne pas (activityCache et classificationCache). Bien sûr, cela dépend de leurs implémentations, mais pour le moment, je voudrais m'assurer que les config ehcache sont correctes.

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:noNamespaceSchemaLocation="ehcache.xsd"> 

<cache name="activityCache" 
      maxElementsInMemory="30" 
      maxElementsOnDisk="100000" 
      eternal="true" 
      overflowToDisk="true" 
      diskPersistent="true" 
      diskSpoolBufferSizeMB="20" 
      timeToIdleSeconds="50" 
      timeToLiveSeconds="5" 
      memoryStoreEvictionPolicy="LFU"> 

      <bootstrapCacheLoaderFactory class = "net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" properties = "bootstrapAsynchronously=false, maximumChunkSizeBytes=5000000"/> 

      <cacheEventListenerFactory class = "net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, asynchronousReplicationIntervalMillis=100"/> 

      </cache> 

     <cache name="featureCache" 
      maxElementsInMemory="30" 
      maxElementsOnDisk="100000" 
      eternal="true" 
      overflowToDisk="true" 
      diskPersistent="true" 
      diskSpoolBufferSizeMB="20" 
      timeToIdleSeconds="50" 
      timeToLiveSeconds="5" 
      memoryStoreEvictionPolicy="LFU">    

      <bootstrapCacheLoaderFactory class = "net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" properties = "bootstrapAsynchronously=false, maximumChunkSizeBytes=5000000"/> 

      <cacheEventListenerFactory class = "net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, asynchronousReplicationIntervalMillis=100"/> 

      </cache> 

     <cache name="classificationCache" 
      maxElementsInMemory="30" 
      maxElementsOnDisk="100000" 
      eternal="true" 
      overflowToDisk="true" 
      diskPersistent="true" 
      diskSpoolBufferSizeMB="20" 
      timeToIdleSeconds="50" 
      timeToLiveSeconds="5" 
      memoryStoreEvictionPolicy="LFU">  

      <bootstrapCacheLoaderFactory class = "net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" properties = "bootstrapAsynchronously=false, maximumChunkSizeBytes=5000000"/> 

      <cacheEventListenerFactory class = "net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, asynchronousReplicationIntervalMillis=100"/> 

      </cache> 

    <cache name="userGroupCache" 
      maxElementsInMemory="30" 
      maxElementsOnDisk="100000" 
      eternal="true" 
      overflowToDisk="true" 
      diskPersistent="true" 
      diskSpoolBufferSizeMB="20" 
      timeToIdleSeconds="50" 
      timeToLiveSeconds="5" 
      memoryStoreEvictionPolicy="LFU"> 

      <bootstrapCacheLoaderFactory class = "net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" properties = "bootstrapAsynchronously=false, maximumChunkSizeBytes=5000000"/> 

      <cacheEventListenerFactory class = "net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, asynchronousReplicationIntervalMillis=100"/> 

      </cache>     

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

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

</ehcache> 

Voici également les définitions des caches et cahchSevices:

 <bean id="featureCache" parent="abstractOptionalCache"> 
     <property name="maxElementsInMemory" value="${cache.feature.maxMemoryElements}"/> 
     <property name="maxElementsOnDisk" value="${cache.feature.maxDiskElements}"/> 
     <property name="overflowToDisk" value="${cache.feature.useDisk}"/> 
     </bean> 

     <bean id="featureCacheService" parent="abstractService" class="com.service.business.cache.impl.ehcache.EHcacheFeatureCacheService"> 
     <property name="cache" ref="featureCache"/> 
     <property name="enabled" value="${cache.feature.enable}"/> 
     </bean> 

     <bean id="activityCache" parent="abstractMandatoryCache"> 
     <property name="cacheManager" ref="cacheManager"/> 
     <property name="maxElementsInMemory" value="${cache.activity.maxMemoryElements}"/> 
     </bean> 

     <bean id="activityCacheService" parent="abstractService" class="com.service.business.cache.impl.ehcache.EHcacheActivityCacheService"> 
     <property name="cache" ref="activityCache"/> 
     </bean> 

     <bean id="classificationCache" parent="abstractOptionalCache"> 
     <property name="cacheManager" ref="cacheManager"/> 
     <property name="maxElementsInMemory" value="${cache.classification.maxMemoryElements}"/> 
     <property name="maxElementsOnDisk" value="${cache.classification.maxDiskElements}"/> 
     <property name="overflowToDisk" value="${cache.classification.useDisk}"/> 
     </bean> 

     <bean id="classificationCacheService" parent="abstractService" class="com.service.business.cache.impl.ehcache.EHcacheClassificationCacheService"> 
     <property name="cache"  ref="classificationCache" /> 
     <property name="enabled" value="${cache.classification.enable}"/> 
     </bean> 

     <bean id="userGroupCache" parent="abstractOptionalCache"> 
    <property name="cacheManager" ref="cacheManager"/> 
    <property name="maxElementsInMemory" value="${cache.userGroup.maxMemoryElements}"/> 
    <property name="maxElementsOnDisk" value="${cache.userGroup.maxDiskElements}"/> 
    <property name="overflowToDisk" value="${cache.userGroup.useDisk}"/> 
    </bean> 

    <bean id="userGroupCacheService" parent="abstractService" class="com.service.business.cache.impl.ehcache.EHcacheUserGroupCacheService"> 
    <property name="cache"  ref="userGroupCache" /> 
    <property name="enabled" value="${cache.userGroup.enable}"/> 
    </bean> 

Je fournirai plus d'informations sur votre demande.

Merci d'avance.

Répondre

1

vous avez fait tout droit, mais juste mal à

rmiUrls=//localhost:40002/activityCache|//localhost:40002/userGroupCache|//localhost:40002/featureCache|//localhost:40002/classificationCache//localhost:40003/activityCache|//localhost:40003/userGroupCache|//localhost:40003/featureCache|//localhost:40003/classificationCache 

vous avez manqué | entre le cache de classification et l'activité

//localhost:40002/classificationCache//localhost:40003/activityCache 

C'est la raison pour laquelle ces deux caches ne fonctionnaient pas!