标签:
经过上篇 coherence初识 ,最近算是和coherence杠上了,针对coherence3.5.3这个版本,把学到的东西整理下
1. 这个jar包有点大,4M多,首先打开coherence.jar,可以发现里面有许多的配置xml文件,就从这些xml说起
<coherence xml-override="{tangosol.coherence.override /tangosol-coherence-override-{mode}.xml}">
。。。。 </coherence>
<coherence xml-override="/tangosol-coherence-override.xml">
。。。。 </coherence>
<coherence xml-override="/tangosol-coherence-override.xml">
。。。。 </coherence>
<coherence xml-override="/tangosol-coherence-override.xml">
。。。。 </coherence>
默认,使用tangosol-coherence-override.xml这个文件覆盖jar包中的配置,我们可以在自己的项目中加一个tangosol-coherence-override.xml,然后将它加入到classpath中,也可以设置tangosol.coherence.override系统参数指定xml文件,使用coherence不可避免要用集群,以上就是集群的相关配置文件
<configurable-cache-factory-config>
<class-name>com.tangosol.net.DefaultConfigurableCacheFactory</class-name>
<init-params>
<init-param>
<param-type>java.lang.String</param-type>
<param-value system-property="tangosol.coherence.cacheconfig">coherence-cache-my.xml</param-value>
</init-param>
</init-params>
</configurable-cache-factory-config>
或者,设置tangosol.coherence.cacheconfig系统参数指定配置
2. 配置集群
在tangosol-coherence-override.xml中简单配置集群名称,成员名称,组播/单播地址,缓存配置等:
<coherence>
<cluster-config>
<member-identity>
<cluster-name system-property="tangosol.coherence.cluster">ProductClusterV3</cluster-name> <!--集群名称-->
<member-name system-property="tangosol.coherence.member">ctas-node</member-name> <!--成员节点名称-->
</member-identity>
<!--单播-->
<unicast-listener>
<well-known-addresses>
<socket-address id="1">
<address system-property="tangosol.coherence.wka">10.6.53.83</address>
<port system-property="tangosol.coherence.wka.port">23401</port>
</socket-address>
<socket-address id="2">
<address system-property="tangosol.coherence.wka">10.6.53.83</address>
<port system-property="tangosol.coherence.wka.port">23403</port>
</socket-address>
<socket-address id="3">
<address system-property="tangosol.coherence.wka">10.6.53.84</address>
<port system-property="tangosol.coherence.wka.port">23401</port>
</socket-address>
<socket-address id="4">
<address system-property="tangosol.coherence.wka">10.6.53.84</address>
<port system-property="tangosol.coherence.wka.port">23403</port>
</socket-address>
</well-known-addresses>
<!--<address system-property="tangosol.coherence.localhost">localhost</address>
<port system-property="tangosol.coherence.localport">33414</port> -->
</unicast-listener>
<!--组播-->
<multicast-listener>
<address system-property="tangosol.coherence.clusteraddress">224.3.3.1</address>
<port system-property="tangosol.coherence.clusterport">35301</port>
<time-to-live system-property="tangosol.coherence.ttl">4</time-to-live>
<join-timeout-milliseconds>10000</join-timeout-milliseconds>
</multicast-listener>
</cluster-config>
<configurable-cache-factory-config>
<class-name>com.tangosol.net.DefaultConfigurableCacheFactory</class-name>
<init-params>
<init-param>
<param-type>java.lang.String</param-type>
<param-value system-property="tangosol.coherence.cacheconfig">coherence-cache-config.xml</param-value> <!--缓存配置-->
</init-param>
</init-params>
</configurable-cache-factory-config>
</coherence>
单播要比组播的优先级高,一个集群应该保证名称,组播ip和端口一样,成员节点名称(member-name)可以一样,因为要确定一个节点还有好多其他信息(site-name、machine-name、process-name、role-name等)会默认设置的
实践证明:要想使用自定义配置文件,配置文件的classpath要优先于jar包,否则不会生效,千万注意
标签:
原文地址:http://www.cnblogs.com/yhzh/p/5045235.html