ehcache缓存集群

本文介绍Ehcache 1.5.0版本中RMI与JGroups两种分布式缓存配置方法。包括PeerProvider与CacheEventListener的具体设置,并提供一个完整的ehcache.xml配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ehcache支持的分布式缓存支持有三种RMI,JGroups,JMS,这里介绍下MRI和JGrpups两种方式,Ehcache使用版本为1.5.0,关于ehcache的其他信息请参考http://ehcache.sourceforge.net/EhcacheUserGuide.html,关于jgroups的信息请参考http://www.jgroups.org/manual/html_single/index.html。

 

环境为两台机器 server1 ip:192.168.2.154,server2 ip:192.168.2.23

 

1. RMI方式:

rmi的方式配置要点(下面均是server1上的配置,server2上的只需要把ip兑换即可)

 

a. 配置PeerProvider:

 

Xml代码 复制代码
  1. <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"    
  2. properties="peerDiscovery=manual,rmiUrls=//192.168.2.23:40001/userCache|//192.168.2.23:40001/resourceCache" />  

配置中通过手动方式同步sever2中的userCache和resourceCache。

 

b. 配置CacheManagerPeerListener:

 

Xml代码 复制代码
  1. <cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"    
  2. properties="hostName=192.168.2.154, port=40001,socketTimeoutMillis=2000" />  

 配置中server1监听本机40001端口。

 

c. 在每一个cache中添加cacheEventListener,例子如下:

 

Xml代码 复制代码
  1. <cache name="userCache" maxElementsInMemory="10000" eternal="true" overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0" diskPersistent="false" diskExpiryThreadIntervalSeconds="120">  
  2.         <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"     properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= false, replicateRemovals= true " />  
  3. </cache>  

 

2. JGroups方式:

ehcache 1.5.0之后版本支持的一种方式,配置起来比较简单,要点:

 

a. 配置PeerProvider,使用tcp的方式,例子如下:

 

Xml代码 复制代码
  1. <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"  
  2.         properties="connect=TCP(start_port=7800):   
  3.         TCPPING(initial_hosts=192.168.2.154[7800],192.168.2.23[7800];port_range=10;timeout=3000;   
  4.         num_initial_members=3;up_thread=true;down_thread=true):   
  5.         VERIFY_SUSPECT(timeout=1500;down_thread=false;up_thread=false):   
  6.         pbcast.NAKACK(down_thread=true;up_thread=true;gc_lag=100;retransmit_timeout=3000):   
  7.         pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;   
  8.         print_local_addr=false;down_thread=true;up_thread=true)"    
  9.         propertySeparator="::" />  

 b.为每个cache添加cacheEventListener:

 

Xml代码 复制代码
  1. <cache name="userCache" maxElementsInMemory="10000" eternal="true"  
  2.         overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"  
  3.         diskPersistent="false" diskExpiryThreadIntervalSeconds="120">  
  4.         <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"  
  5.             properties="replicateAsynchronously=truereplicatePuts=true,   
  6.                 replicateUpdates=truereplicateUpdatesViaCopy=falsereplicateRemovals=true"/>  
  7. </cache>  

 JGroup方式配置的两个server上的配置文件一样,若有多个server,在initial_hosts中将server ip加上即可。

一个完整的ehcache.xml文件:

Xml代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xsi:noNamespaceSchemaLocation="http://ehcache.sf.net/ehcache.xsd">  
  4.     <diskStore path="java.io.tmpdir" />  
  5.   
  6.     <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"  
  7.         properties="connect=TCP(start_port=7800):   
  8.         TCPPING(initial_hosts=192.168.2.154[7800],192.168.2.23[7800];port_range=10;timeout=3000;   
  9.         num_initial_members=3;up_thread=true;down_thread=true):   
  10.         VERIFY_SUSPECT(timeout=1500;down_thread=false;up_thread=false):   
  11.         pbcast.NAKACK(down_thread=true;up_thread=true;gc_lag=100;retransmit_timeout=3000):   
  12.         pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;   
  13.         print_local_addr=false;down_thread=true;up_thread=true)"    
  14.         propertySeparator="::" />  
  15.   
  16.     <defaultCache maxElementsInMemory="10000" eternal="true"  
  17.         overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"  
  18.         diskPersistent="false" diskExpiryThreadIntervalSeconds="120">  
  19.         <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"  
  20.             properties="replicateAsynchronously=truereplicatePuts=true,   
  21.                 replicateUpdates=truereplicateUpdatesViaCopy=falsereplicateRemovals=true"/>  
  22.     </defaultCache>  
  23.   
  24.     <cache name="velcroCache" maxElementsInMemory="10000" eternal="true"  
  25.         overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"  
  26.         diskPersistent="false" diskExpiryThreadIntervalSeconds="120">  
  27.         <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"  
  28.             properties="replicateAsynchronously=truereplicatePuts=true,   
  29.                 replicateUpdates=truereplicateUpdatesViaCopy=falsereplicateRemovals=true"/>  
  30.     </cache>  
  31.     <cache name="userCache" maxElementsInMemory="10000" eternal="true"  
  32.         overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"  
  33.         diskPersistent="false" diskExpiryThreadIntervalSeconds="120">  
  34.         <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"  
  35.             properties="replicateAsynchronously=truereplicatePuts=true,   
  36.                 replicateUpdates=truereplicateUpdatesViaCopy=falsereplicateRemovals=true"/>  
  37.     </cache>  
  38.     <cache name="resourceCache" maxElementsInMemory="10000"  
  39.         eternal="true" overflowToDisk="true" timeToIdleSeconds="0"  
  40.         timeToLiveSeconds="0" diskPersistent="false"  
  41.         diskExpiryThreadIntervalSeconds="120">  
  42.         <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"  
  43.             properties="replicateAsynchronously=truereplicatePuts=true,   
  44.                 replicateUpdates=truereplicateUpdatesViaCopy=falsereplicateRemovals=true"/>  
  45.     </cache>  
  46. </ehcache>
内容概要:本文探讨了在MATLAB/SimuLink环境中进行三相STATCOM(静态同步补偿器)无功补偿的技术方法及其仿真过程。首先介绍了STATCOM作为无功功率补偿装置的工作原理,即通过调节交流电压的幅值和相位来实现对无功功率的有效管理。接着详细描述了在MATLAB/SimuLink平台下构建三相STATCOM仿真模型的具体步骤,包括创建新模型、添加电源和负载、搭建主电路、加入控制模块以及完成整个电路的连接。然后阐述了如何通过对STATCOM输出电压和电流的精确调控达到无功补偿的目的,并展示了具体的仿真结果分析方法,如读取仿真数据、提取关键参数、绘制无功功率变化曲线等。最后指出,这种技术可以显著提升电力系统的稳定性与电能质量,展望了STATCOM在未来的发展潜力。 适合人群:电气工程专业学生、从事电力系统相关工作的技术人员、希望深入了解无功补偿技术的研究人员。 使用场景及目标:适用于想要掌握MATLAB/SimuLink软件操作技能的人群,特别是那些专注于电力电子领域的从业者;旨在帮助他们学会建立复杂的电力系统仿真模型,以便更好地理解STATCOM的工作机制,进而优化实际项目中的无功补偿方案。 其他说明:文中提供的实例代码可以帮助读者直观地了解如何从零开始构建一个完整的三相STATCOM仿真环境,并通过图形化的方式展示无功补偿的效果,便于进一步的学习与研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值