Ehcache集群的两种方式:组播方式和点对点方式
一、 组播方式
1) 配置cacheManagerPeerProviderFactory
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic,multicastGroupAddress=230.0.0.2,multicast groupPort=4447,timeToLive=1”
propertySeparator=","
/>
作用:当缓存发生变化,进行广播
属性: peerDiscovery:atutomatic为自动;
multicastGroupAddress:广播组地址,指定D类IP地址空间,范围从 224.0.1.0 到 238.255.255.255 中的任何一个地址
mulicastGroupPort广播组端口
timeToLive:搜索范围
0是同一台服务器
1是同一个子网
32是指同一站点
64是指同一块地域
128是同一块大陆
256是任何
2) 配置cacheManagerPeerListenerFactory
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
/>
作用:监听本服务器所有端口
二、 点对点方式
1) 配置cacheManagerPeerProviderFactory
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,rmiUrls=//192.168.4.50:40002/com.pccw.kernel.dic.vo.ArchDicKindVOImpl|//192.168.4.50:40002/com.pccw.kernel.dic.vo.ArchDicItemVOImpl"
/>
作用:当缓存发生变化,通知集群中其他节点。
属性: peerDiscovery:manual为手动
rmiUrls:通知需要同步的缓存
3) 配置cacheManagerPeerListenerFactory
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=192.168.4.24,port=40001,socketTimeoutMillis=2000"
/>
作用:监听本服务器指定端口
缓存的配置(共同部分)
cacheEventListenerFactory:注册相应的的缓存监听类,用于处理缓存事件,如put,remove,update,和expire bootstrapCacheLoaderFactory:指定相应的BootstrapCacheLoader,用于 在初始化缓存(从硬盘读取,overflowToDisk为false时,此配置失效),以及自动设置。
p2p方式
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd"> <!-- Caches in this file can be clustered and are configured to be clustered. --> <diskStore path="java.io.tmpdir/arch" /> <cacheManagerEventListenerFactory class="" properties="" /> <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" properties="peerDiscovery=manual,rmiUrls=//192.168.4.24:40001/com.pccw.kernel.dic.vo.ArchDicKindVOImpl|//192.168.4.24:40001/com.pccw.kernel.dic.vo.ArchDicItemVOImpl" /> <cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" properties="hostName=192.168.0.50,port=40002,socketTimeoutMillis=2000"/ /> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="600" overflowToDisk="false" > <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" propertySeparator="," /> <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" /> </defaultCache> <cache name="sessionCache" maxElementsInMemory="10000" eternal="true" timeToIdleSeconds="600" overflowToDisk="false" > <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" propertySeparator="," /> <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" /> </cache> <cache name="customCache" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="600" timeToLiveSeconds="1800" overflowToDisk="false" > <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" propertySeparator="," /> <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" /> </cache> <cache name="com.pccw.kernel.dic.vo.ArchDicItemVOImpl" maxElementsInMemory="100000" eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="1200" overflowToDisk="false" > <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" propertySeparator="," /> <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" /> </cache> <cache name="com.pccw.kernel.dic.vo.ArchDicKindVOImpl" maxElementsInMemory="100000" eternal="true" timeToIdleSeconds="1200" timeToLiveSeconds="1200" overflowToDisk="false" > <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true" propertySeparator="," /> <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" /> </cache> </ehcache>