您的位置:首页 > 其它

Ehcache集群

2015-08-03 16:14 148 查看

Ehcache集群的两种方式:组播方式和点对点方式

一、   组播方式

1)    配置cacheManagerPeerProviderFactory<cacheManagerPeerProviderFactoryclass="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="" /><cacheManagerPeerProviderFactoryclass="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"/><cacheManagerPeerListenerFactoryclass="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"properties="hostName=192.168.0.50,port=40002,socketTimeoutMillis=2000"//><defaultCachemaxElementsInMemory="10000"eternal="false"        timeToIdleSeconds="600"overflowToDisk="false">        <cacheEventListenerFactoryclass="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><cachename="sessionCache"maxElementsInMemory="10000"eternal="true"        timeToIdleSeconds="600"overflowToDisk="false">        <cacheEventListenerFactoryclass="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><cachename="customCache"maxElementsInMemory="10000"eternal="false"        timeToIdleSeconds="600"        timeToLiveSeconds="1800"overflowToDisk="false">        <cacheEventListenerFactoryclass="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">        <cacheEventListenerFactoryclass="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"      >        <cacheEventListenerFactoryclass="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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: