zoukankan      html  css  js  c++  java
  • Coherence Step by Step 第一篇 入门(三)配置(翻译)

    原文链接http://docs.oracle.com/cd/E24290_01/coh.371/e22837/gs_config.htm#CEGJBDJD 

    1.默认的配置文件

     
    Coherence distribution包含一个默认的xml配置文件的集合,都包含在coherence\lib\coherence.jar类里。最简单的查看这些文件和他们相关架构的方法是将coherence类解压到一个目录。
    配置文件提供了默认的安装,以允许coherence能够用最少的变化即用。这些文件只是为了演示的目的,也是为了能够根据应用程序或解决方案的需求来重用或更改。然而,推荐的方法是提供一个配置文件来覆盖默认的配置文件。
     
    默认的配置文件包含下面文件:
    • tangosol-coherence.xml-这个文件提供了operational 和run-time设置,被用来创建和配置cluster,通讯和数据管理服务。这个文件代表性的被称为operational deployment descriptor.这个文件的架构是coherence-operational-config.xsd文件。
    • tangosol-coherence-override-dev.xml 当Coherence启动在开发模式时,这个文件覆盖了tangosol-coherence.xml文件的operational 设置。默认的,Coherence启动与developer 模式,这个文件中的设置会被使用。这个文件中的设置适合开发环境。这个覆盖文件的架构文件和operational deployment descriptor的架构文件是一样的。
    • tangosol-coherence-override-eval.xml 当Coherence启动与evaluation模式时候,这个文件覆盖了在tangosol-coherence.xml文件的operational 设置。这个文件中的设置适合evaluating Coherence.这个覆盖文件的架构文件和operational deployment descriptor的架构文件是一样的。
    • tangosol-coherence-override-prod.xml当Coherence启动与evaluation模式时候,这个文件覆盖了在tangosol-coherence.xml文件的operational 设置。这个文件中的设置适合production Coherence.这个覆盖文件的架构文件和operational deployment descriptor的架构文件是一样的。
    • coherence-cache-config.xml 这个文件用来指定在cluster中使用的各种各样的缓存类型。这个文件被代表性的称为configuration deployment descriptor.这个文件的架构是coherence-cache-config.xsd文件。
    • coherence-pof-config.xm 当使用Portable Object Format(POF)来序列化对象时,这个文件用来指定自定义的数据类型。这个文件被代表性的称为POF configuration deployment descriptor.这个文件的架构是coherence-pof-config.xsd文件。
    • Management configuration files 一个用来配置coherence management reports的文件集合。这些文件在coherence.jar库的/reports目录里。文件包含了一组配置文件的报告(report-group.xml。默认的),参考了许多的报告定义文件。每个报告定义文件的结果是创建一个报告文件,该文件显示管理信息基于特定的一组度量。 这些文件的架构分别是coherence-report-config.xsd 和 coherence-report-group-config.xsd file.
     
    2.指定Operational Configuraltion文件
     
     tangosol-coherence.xml operational deployment descriptor  提供了operational 和runtime设置,被用来创建和配置cluster,通讯和数据管理服务。在run time,Coherence将使用在classpath中发现的第一个tangosol-coherence.xml实例。
    默认的operational deployment descriptor是和Coherence一起,位于coherence.jar库的根目录。这个文件可以根据需求修改。然而,当配置operational run time瘦,推荐覆盖这个文件。
     
     2.1 使用默认的operational override file
     
    用一个operational override file ,命名为tangosol-coherence-override.xml,在运行时放在classpath中,在默认的tangosol-coherence.xml文件中元素会被覆盖。覆盖文件的结构和operational deployment descriptor 是一样的,除了,所有的元素是可选的。覆盖文件包含的只是变换的元素。任何丢失的元素会从tangosol-coherence.xml文件加载。
     
    通常,使用operational override file提供了大多的广泛的方法来配置operational run time,并可以用在开发和生产环境。
     
    使用默认的operational override file:
    1.新建一个文件,名为tangosol-coherence-override.xml
    2.编辑文件,增加任意operational 元素,用来覆盖。
    下面的例子,配置了cluster的名字和,覆盖了默认的cluster名:
    <?xml version='1.0'?>
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
    xsi:schemaLocation="http://xmlns.oracle.com/coherence/
    coherence-operational-config coherence-operational-config.xsd">
        <cluster-config>
            <member-identity>
                <cluster-name system-property="tangosol.coherence.cluster">
    MyCluster</cluster-name>
            </member-identity>
        </cluster-config>
    </coherence>

    3.保存关闭文件。

    4.确定operational override file的位置在运行时在classpath中。
    下面的例子延时启动一个cache server,使用了override file,位于choherence_home,
    java -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
     
     2.2 指定Operational Override File
    tangosol.coherence.override系统属性用来指定operational override file,取代默认的tangosol-coherence-override.xml文件。覆盖文件的结构和operational deployment descriptor 是一样的,除了,所有的元素是可选的。任何丢失的元素会从tangosol-coherence.xml文件加载。
    tangosol.coherence.override系统属性提供了一个简单的在不同operational configuration之间切换的方式,在开发和测试时候很方便。
    指定operational override file:
    1.新建一个文本。
    2.编辑文件,增加operational 元素,用来覆盖
    下面的例子配置了多个端口号
    
    
    <?xml version='1.0'?>
    
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <cluster-config>
          <multicast-listener>
             <port system-property="tangosol.coherence.clusterport">3059</port>
          </multicast-listener>
       </cluster-config>
    </coherence>
    3.保存文件为XML格式,关闭文件。
    4.指定一个operational override file的名名字,作为tangosol.coherence.override系统属性的值。如果文件没有在classpath里,键入文件的完整的路径和名字。系统属性页支持使用URL,当指定operational override file的位置。
    下面的例子延时了启动cache server和使用operational override file,文件被明明为cluster.xml,位于Coherence_Home。
    
    
    java -Dtangosol.coherence.override=cluster.xml -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer


    2.3 为指定operational元素定义override file
     
    override files 能够创建来覆盖指定operational elements的内容。override files遵循operational deployment descriptor一样的结构,除了他们的根元素必须匹配被覆盖的元素。
    
    通常,用来指定opertional元素的override files提供了细粒度控制,对此,operational deployment descriptor的部分能够被修改,并且允许为不同的deployment场景创建不同的配置。
     
     
    2.4 查看当前加载的opertional override files
     
    在启动的时候,coherence节点的输出指示了位置和operational configuration files。opertional configuration 消息是启动时第一条发出的。在使用多个overrides file和当开发和测试coherence 应用、解决方案时,输出信息是特别有用的。
     
    下面的例子输出 展示了通常发出的消息。
    Loaded operational configuration from resource "jar:file:/D:/coherence/lib/
       coherence.jar!/tangosol-coherence.xml"
    Loaded operational overrides from resource "jar:file:/D:/coherence/lib/
       coherence.jar!/tangosol-coherence-override-dev.xml"
    Loaded operational overrides from resource "file:/D:/coherence/
       tangosol-coherence-override.xml"
    Optional configuration override "/cluster-config.xml" is not specified
    Optional configuration override "/custom-mbeans.xml" is not specified
    
    以上的输出表示了在conherence.jar中的operational deployment descriptor被加载了,这个文件中设置被两个加载了的override files覆盖了:tangosol-coherence-overide-dev.xml和tangosol-coherence-overrid.xml。此外,两个override files被定义了指定的operational 元素,但是在运行时没有找到。
     
     3.指定Cache Configuration File
    在cluster中,coherence-cache-config.xml  cache configuration deployment descriptor 文件被用来指定使用各种缓存的类型。在运行时,coherence 使用在classpath中找到的第一个coherence-cache-config.xml文件。一个简单的coherence-cache-config.xml文件包含在了coherence中,可以再coherence.jar的根目录下找到。这个简单的文件提供了演示的目的。能够根据需求重用和改变。然而,推荐创建一个自定义的cache configruation deployment descriptor 代替例子的文件。
     
    3.1使用默认的cache configuration file
     
    Coherence 被配置了即用配置,使用在classpath中找到的第一个coherence-cache-config.xml文件。为了使用coherence-cache-config.xml, 这个文件必须在classpath中并且限于coherence.jar库。否则,位于coherence.jar库中的coherence-cache-config.xml将会被使用。
     
    使用默认的cache configuration file:
    1.复制一份例子的coherence-cache-config.xml,位于conherence.jar中,保存在一个不同的位置。缓存定义包含在例子文件中,以便演示的目的,被用来作为创建一个指定解决方案的cache configuration的起点。
    2.确定coherence-cache-config.xml的保存位置在运行时是在classpath中,并且优先于classpath中的coherence.jar文件。
    下面的例子演示了使用位于Coherence_Home中的coherence-cache-config.xml cache configuration文件来启动缓存服务器。
    java -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
     
    3.2覆盖默认的cache configuration file
    cache configuration deployment descriptor 的默认的名字和位置被指定在operational deployment descriptor 的<configurable-cache-factory-config>元素中。这个元素能够使用不同位置的名字覆盖默认的cache configuration file.
    
    覆盖默认的cache configuration file:
    
    1.复制一份coherence.jar库中的默认的coherence-cache-config.xml cache configuration file,用一个不同的名字保存在别的位置。
    2.新建一个tangosol-coherence-override.xml文件。
    3.编辑opertional override file ,键入一个<configurable-cache-factory-config> 节点,指定一个配置文件的名字,在step1中创建的。如果cache configuration file没有在classpath中,键入完整的路径也可以。元素支持使用URL来定位一个cache configuration file.
    下面的例子指定了cache configuration deployment descriptor ,名为MyConfig.xml
    
    
    <?xml version='1.0'?>
    
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <configurable-cache-factory-config>
          <init-params>
             <init-param>
                <param-type>java.lang.String</param-type>
                <param-value system-property="tangosol.coherence.cacheconfig">
                   MyConfig.xml</param-value>
             </init-param>
          </init-params>
       </configurable-cache-factory-config>
    </coherence>
    4.保存关闭文件。
    5.确保operational override file 在运行时是在classpath中。
    下面的例子演示了使用位于Coherence_Home 中的operational override file和一个自定义的cache configuration file 启动cache server。
     
    java -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
    
    
    3.3  使用Cache Configuration File系统属性
    tangosol.coherence.cacheconfig系统属性用来指定自定义的cache configuration deployment descriptor,替代默认的cache configuration deployment descriptor,系统属性提供了一个简单的方式切换不同配置文件,方便开发和测试。
    指定自定义的cache configuration file,键入文件名作为tangosol.coherence.cacheconfig系统属性的值。这是一个通常做法,当启动一个Coherence节点时候,使用一个-D的参数。如果这个文件不再classpath中,键入完整的路径和文件名。系统属性页支持使用一个URL来定位一个指定的cache configuration file.
    下面的例子启动了一个cache servier ,并且指定了名为MyConfig.xml的位于COHERENCE_HOME 的cache configuration deployment descriptor。
    
    
    java -Dtangosol.coherence.cacheconfig=MyConfig.xml -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
    3.4 查看当前加载的Cache Confguration FIle
    Coherence节点的输出指示了在启动时, cache configuration deployment descriptor的位置和名字。这个配置信息是紧跟着版权信息输出后的第一条消息。开发和测试时候,输出是特别有用的。
    下面的例子出书展示了cache configuration 消息表明 名为MyConfig.xml的 cache configuration deployment descriptor 被加载。
    Loaded cache configuration from resource "file:/D:/coherence/Myconfig.xml"

    4.指定POF Conguration File
    pof-config.xml 当使用Portable Object Format (POF) 来序列化的时候,POF configuration deployment descriptor file 用来指定自定义的用户类型,在运行时,Coherence 使用在classpath中找到的第一个pof-config.xml实例。
    默认的POF configuration deployment descriptor 被分布在coherence.jar库中的的根目录下。这个文件是为部分应用和解决方案定制的、代替的或者是扩展的。默认的,deployment descriptor 引用了coherence-pof-config.xml文件。这是Coherence用来定义用户类型的地方,并且当扩展或者创建一个POF configuration file时应该总是被包含在其中,
     
    4.1 使用POFCongifuration File 系统属性 
    tangosol.pof.config系统属性用来指定使用自定义的POF configuration deployment descriptor ,代替默认的pof-config.xml。系统属性提供了一个简单的方式来切换不同的配置,方便开发和测试。
     
    指定自定义的POF configuration file:
    1.新建一个xml文件。
    2.编辑文件,新建一个<pof-config>节点,包含了默认的Coherence POF user types:
    <?xml version="1.0"?>
    
    <pof-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-pof-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-pof-config
       coherence-pof-config.xsd">
       <user-type-list>
          <include>coherence-pof-config.xml</include>
       </user-type-list>
    </pof-config>
    
    3.保存关闭文件。
    4.键入tangosol.pof.config系统属性的文件名作为值。这是通常的做法,当启动Coherence节点时使用-D的参数。如果文件不再classpah中,键入完整的路径和名字。系统属性页 支持使用URL定位POF configuration file。
    下面的例子使用了位于Coherence_Home的名为MyPOF.xml的指定的POF configuration deployment
    java -Dtangosol.pof.config=MyPOF.xml -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
    4.2合并多个POF configuration file
     
    <include> 元素在POF configuration deployment descriptor 中被使用,用来包含定义在不同POF configuration deployment descriptor中的用户类型。这允许了用有意义的方式来组织用户类型,如应用和开发的分组。
     
    合并多个POF configuration file:
    1.打开一个已存在的启动时候被加载的POF configuration file 
    2.增加<include>元素,值为POF configuration file的名字。如果文件不再classpath中,键入完整的路径和文件名。URL也能够被用来定位文件。
    下面的例子是合并两个POF configuration file除了默认的coherence pof configuration file:
    <?xml version='1.0'?>
    
    <pof-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-pof-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-pof-config
       coherence-pof-config.xsd">
       <user-type-list>
          <include>coherence-pof-config.xml</include>
          <include>hr-pof-config.xml</include>
          <include>crm-pof-config.xml</include>
       </user-type-list>
    </pof-config>
    3.保存并关闭文件。
    
    4.如果需要,确保POF configuration file启动时在classpath中。
    
    下面的例子演示了使用COHERENCE_HOME中的POF configuration file启动cache server。
    
    
    
    java -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
    
    4.3 查看被加载的POF configuration FIle
    Coherence及诶单的输出指示了启动时被夹在的POF configuration deployment description 的名字和路径。配置消息显示在版权信息输出后的消息中,与配置使用POF的cache service相关。当开发和测试Coherence 应用和解决方案时,输出信息特别有用。
    下面的例子输出展示了POF configuration 消息,它表明了四个POF configuration deployment descriptor 被加载了:
    Loading POF configuration from resource "file:/D:/coherence/my-pof-config.xml"
    Loading POF configuration from resource "file:/D:/coherence/coherence-pof-config.xml"
    Loading POF configuration from resource "file:/D:/coherence/hr-pof-config.xml"
    Loading POF configuration from resource "file:/D:/coherence/crm-pof-config.xml"
    
    5.指定Management Configuration Files
    有几种不同的配置文件用来配置管理。这些文件包括:
    • report group configuration file  report group configuration 文件用来列出报告定义文件和报告写入的输出目录的名字和位置。这文件的名字和位置定义在operational deployment descriptor.默认的,report-group.xml文件被使用,位置在coherence.jar的/reports目录。另外还提供了report group configuration 文件和更具需要来新建自定义report group file.
    • report configuration files  report configuration file定义了报告,报告的结果在创建一个文件更具一组特定的度量来显示管理信息。report configuration file必须在运行时被一个report group configuration file来引用使用。默认的report configuration file维护coherence.jar中的/reports文件夹内,被默认的report group configuration file引用。自定义的report configuration file能够更具需要来创建。
    • custom-mbeasn.xml 这个文件是默认的MBean configuration override file,用来在Coherence JMX管理和监控框架中定义自定义的MBeans。这允许任何application -level MBean在cluster中的任何节点来管理和监控。自定义的MBeans 能够在operational override file中定义。然后,MBean configuration override file通常被替换。
     
    5.1 指定自定义的report group configuration file
     
    默认的report group configuration file的名字和位置在opertional configuration deployment descriptorde <management-config>节点中指定。自定义的report group configuration 既能够用operational override也能用系统属性来指定。
     
    5.1.1覆盖默认的report group configuration file
    自定义的report group configuration file的位置和名字能够使用operational override file来指定。这个机制覆盖了默认的位置和名字。
    覆盖默认的report gourp configuration file:
    1.创建xml文件
    2.编辑文件,创建<report-group>节点如下,这个例子配置了一个单个report。
    <?xml version='1.0'?>
    <report-group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-report-group-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-report-group-config coherence-report-group-config.xsd">
       <frequency>1m</frequency>
       <output-directory>./</output-directory>   <report-list>      <report-config>         <location>reports/report-node.xml</location>      </report-config>
       </report-list>
    </report-group>

    3.保存关闭文件。

    4.新建一个tangosol-coherence-override.xml文件。
    5.编辑文件,键入一个<management-config>节点,指定report group configuration file的名字。如果report group configuration file不在classpath内,就键入完整的文件路径。元素支持用URL来定义一个report group configuration file.
    下面的例子开启了JMX管理,并指定了一个report group configuration deployment descriptor ,名为my-group.xml
    <?xml version='1.0'?>
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <management-config>
          <managed-nodes system-property="tangosol.coherence.management">all
          </managed-nodes>
          <reporter>
             <configuration system-property="tangosol.coherence.management.report.
                configuration">my-group.xml</configuration>
          </reporter>
       </management-config>
    </coherence>

    6.保存和关闭文件。

    7.确保operational override file运行时在classpath内。
    下面的例子演示了使用operational overrde file和在 Coherence_home中的report group configuration file来启动一个cache server。
    java -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
    
     
    5.1.2 使用report group configuration file系统属性
    tangosol.coherence.management.report.configuration 系统属性用来指定自定义的report group configuration ,代替默认的report-group.xml。系统属性提供了一个简单的方法掐换不同的配置,方便了开发和测试。
     
    为了指定一个自定义的report group configuration file,键入一个文件名作为tangosol.coherence.management.report.configuration系统属性的值。这个通常作为一个-D java参数来启动coherence 节点。如果文件不再classpath内,就键入完整的文件名和路径。系统属性支持使用URL来定位一个report group configuration file。
    下面的例子启动了一个cache server,开启了JMX管理,指定了report group configuration文件名,名为my-group.xml,位于Coherence_Home中。
    java -Dtangosol.coherence.management=all -Dtangosol.coherence.management.report.configuration=my-group.xml -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
    
     
    5.2 指定MBean Configuration File
    tangosol-coherence.xml operational deployment descriptor 定义了一个operational override file,名为custom-mbeans.xml,被用来指定使用定义自定义MBeans。override file的名字和位置也能使用MBean configuration file系统属性来指定。
     
    5.2.1 使用默认的MBean Configuration Override File
    自定义的MBean 在名为custom-mbeans.xml文件用被定义。在运行时,Coherence使用在classpath中找到的第一个custom-mbeans.xml实例。
    使用默认的MBean configuration override file:
    1.新建一个名为custome-mbeans.xml的文件。
    2.编辑文件,创建一个空的<mbeans>节点,如下
    <?xml version='1.0'?>
    <mbeans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
    </mbeans>

    3.保存关闭文件。

    4.确定自定义MBean configuration override file运行时在classpath中。
    下面的例子演示了使用一个默认的位于Coherence_Home中的MBean configuration override file。
    java -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
    
     
    5.2.2 使用MBean configuration file 系统属性
    tangosol.coherence.mbeans 系统属性指定了使用一个MBean configuration override file,代替默认的custom-mbeans.xml override fie.
    系统属性提供给了简单的方式在不同的MBean 配置中减缓,方便了开发和测试。
    为了指定MBean configuration override file,键入文件的名字作为tangosol.coherence.mbeans系统属性。这个通常作为一个java可选参数-D来启动一个coherence 节点。如果文件不再classpath中,键入完整的文件路径和名字。系统属性支持用URL定位MBean configuration overrid file。
    下面的例子启动了一个cache server,指定了一个名为my-mbeans.xml的Mbean configuration override file,位于Coherence_Home。
    java -Dtangosol.coherence.mbeans=my-mbeans.xml -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
    
      
    5.2.3 查看被加载的Management Configuration File
     
    Coherence节点的输出表明了在启动时report group configuration file和MBean configuration file的位置和名字。开发和测试Coherence应用和解决方案时,输出信息特别的有用。
     
    Report Group Configuration file
    report group configuration 消息在Coherence 版权信息输出以后显示。
    下面的例子输出真是了一个report goup configuration 消息,它表示my-group.xml被加载了
    Loaded Reporter configuration from "file:/D:/coherence/my-group.xml
    
    MBean Configuration Override File
    MBean configuration 消息和其他的opertaional override 消息一起输出,在启动一个进程时,在第一条消息发出时。当使用override files,输出非常有帮助,在开发和测试Coherence应用和解决方案时也特别有用。
    下面的例子输出展示了operational override消息,表示了默认的MBean configuration override file被加载。
    
    
    Loaded operational overrides from resource "file:/D:/coherence/custom-mbeans.xml"
    
     
    6.禁用Schema Validation
     
    coherence 使用schema validation来确保配置文件粘附在各自的架构定义上。当配置文件加载的时候,包含架构应用的配置文件会自动对架构验证。验证错误会导致立即失败,并且错误消息会输出,指示哪个元素导致了错误。作为最佳的实践,schema validation应该总是被使用。
    schema validation可以更具需求禁用。如果要禁用schema validation ,从配置文件中移除xsi:schemaLocation属性。下面的例子穿件了一个tangosol-coherence-override.xml文件,他不包含架构应用,并且加载时不进行验证:
     
    <?xml version='1.0'?>
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config">
       ...
    </coherence>
    7.理解XML覆盖特性
     
    XML覆盖特性是一种配置机制,允许不修改维护coherence.jar中的默认的tangosol-coherence.xml operational deployment descriptor ,而改变operational 设置。这种机制是配置coherence operational run time的最佳方式。
    xml覆盖特性结合xml document,通常被称为voerride file, 用一个指定的operational XML 元素。这个xml元素和他的任何一个子元素,在override file中更具需求来修改。在运行时,Coherence 加载override file,它的元会会替换tangosol-coherence.xml文件中的元素。
    override file不要求必须在运行时存在。然后,如果override file存在,它的根元素必须匹配被覆盖的元素。此外,子元素是可选则。如果子元素没有在override file中定义,就会从tangosol-coherence.xml文件中加载。通常,只有子元素在voerride file中被改变和增加。
     
    7.1 使用预定义的voerride files
    两个override file预定义了,能够覆盖operational deployment descriptor 的元素。这些文件必须手动穿件并保存在classpath中的位置。
    • tangosol-coherence-overrid.xml 这个override file 定义为<coherence>根元素,被用来覆盖 operational deployment descriptor中的任何元素。这个文件中的根元素必须是<coherence>。
    • custom-mbeans.xml 这个override file定义为<mbeans>元素,用来增加operational deployment descriptor的自定义MBeans 。这个文件中的根元素必须是<mbeans>。
    下面的例子演示了tangosol-coherence-override.xml文件被用来覆盖默认的cluster名。其它的所有的元素从tangosol-coherence.xml文件加载。
    <?xml version='1.0'?>
    
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <cluster-config>
          <member-identity>
             <cluster-name system-property="tangosol.coherence.cluster">MyCluster
             </cluster-name>
          </member-identity>
       </cluster-config>
    </coherence>

    下面的例子真是了tangosol-coherence-override.xml文件为这个节点上的distributed cache service 来禁用local storage 。注意使用id属性来区分一个元素的多次出现。这个id属性必须匹配被覆盖的元素的id属性。

    <?xml version='1.0'?>
    
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <cluster-config>
          <services>
             <service id="3">
                <init-params>
                   <init-param id="4">
                      <param-name>local-storage</param-name>
                      <param-value system-property="tangosol.coherence.distributed.
                         localstorage">false</param-value>
                   </init-param>
                </init-params>
             </service>
          </services>
       </cluster-config>
    </coherence>

    下面的例子展示了一个custom=mbean.xml文件,在Mbeans中增加一个标准的Mbean 定义

    <mbeans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <mbean id="100">
          <mbean-class>com.oracle.customMBeans.Query</mbean-class>
          <mbean-name>type=Query</mbean-name>
          <enabled>true</enabled>
       </mbean>
    </mbeans>

    7.2 定义自定义override file

    在tangosol-coherence.xml deployment descriptor 中的任何元素都能够使用预定义的tangosol-conherence-override.xml文件来覆盖。然而,也许有种情形,需要更加细粒度的配置控制。例如一个解决方案希望允许改变一个确定的元素,但是不希望允许改变全部的operational deployment descriptor.另一个例子,一个解决方案也许希望提供基于不同的案例的不同的配置。自定义的override file用来支持这些场景的情况。
     
    使用xml-override 和id 属性
    override file使用xml-override定义,如果需要,还有id属性。这两个属性是可选的,增加到operational 元素来覆盖。
     
    xml-override属性值是是一个文档的名字,它能够被coherence.jar库中的的类使用ClassLoader.getResourceAsStream(String name)这个方法访问到。通常,在运行时,classpath中,文件名包含一个/前缀。这个属性也支持使用URL来定位override file。
     
    例如,使用名为cluster-config.xml文件覆盖<cluster-config>元素,增加一个xml-override属性到tangosol-coherence-override.xml文件中的<cluster-config>元素中,如下所示:
    
    
     
    <?xml version='1.0'?>
    
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <cluster-config xml-override="/cluster-config.xml">
       ...
       </cluster-config>
    </coherence>
    使用override file,新建一个文件名为cluster-config.xml,并且确保它和基本文档(这个例子中是tangosol-coherence-override.xml)都在运行时的classpath目录中。例如,override file的根元素必须是<cluster-config>,如下所示。
    
    
    <?xml version='1.0'?>
    
    <cluster-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <multicast-listener>
          <join-timeout-milliseconds>4000</join-timeout-milliseconds>
       </multicast-listener>
    </cluster-config>
    id属性用来区分多次出现的元素。
     
    例如,定义一个自定义额override file,名为dist-service-config.xml,覆盖distributed cache service的<service>元素,在<service>元素中增加一个xml-override属性,di是号码3,如下所示
    
    
    <?xml version='1.0'?>
    
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <cluster-config>
          <services>
             <service id="3" xml-override="/dist-service-config.xml">
             </service>
          </services>
       </cluster-config>
    </coherence>
    
    
    使用这个voerride file,新建一个文件,名为dist-service-config.xml,确保它在运行时在classpath中的目录里。这个例子中。override file的根元素必须是<service>,如下所示:
    
    
    <?xml version='1.0'?>
    
    <service id="3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <init-params>
          <init-param id="1">
             <param-name>standard-lease-milliseconds</param-name>
             <param-value>2</param-value>
          </init-param>
       </init-params>
    </service>
     
    7.3为同一个元素定义多个override file
    为同一个元素定义多个override file来串联operational override file.这个是常用的做法,允许operational configuration 基于不同的部署场景,如展示和生产。
     
    例如,tangosol-coherence.xml 位于coherence.jar中的operational deployment descriptor,为<coherence>元素定义了一个operational override file,如下面:
    
    
     
    <?xml version='1.0'?>
    
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd"
       xml-override="{tangosol.coherence.override/tangosol-coherence-override-{mode}
       .xml}">
       ...
    </coherence>
    
    
    
    
    模式特定的override file也位于coherence.jar,依赖于Coherence启动模式的使用。每个模式特定的operational override file,反过来,定义了默认的operational override file,如下:
    
    
    <?xml version='1.0'?>
    
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd"
       xml-override="/tangosol-coherence-override.xml">
       ...
    </coherence>
    tangosol-coherence-override.xml文件中,为<coherence>元素定义的第四个override file。例如:
    <?xml version='1.0'?>
    
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd"
       xml-override="/tangosol-coherence-override-staging.xml">
       ...
    </coherence>
    如果需要,这个链还能继续。如果这些文件都在运行时的classpath中。在链中,高的文件总是副高低的。
    
    
    8.用系统属性改变配置
    命令行的覆盖特性允许operational 和缓存设置使用系统属性来覆盖。系统属性通常在java命令行上指定使用java -d选项。这允许为cluster中的每个节点自定义配置,而不是在跨加点时使用相同的operational configuration file 和cache configuration file。在开发是,系统属性页支持一个简单和快速的方法来设置。
    
    
    8.1  使用预定义的系统属性
    Coherence包含许多预定义的系统属性,用来覆盖不同的oeprational 和缓存设置。预定义的系统属性在tangosol-coherence.xml和coherence-cache-config.xml默认的deployment descriptor,各自的,使用system-property属性来顶了。
    例如,预定义的tangosol-coherence.log.level系统属性定义在tangosol-coherence.xml文件中,如下:
    <logging-config>
       ...   <severity-level system-property="tangosol.coherence.log.level">5
       </severity-level>
       ...</logging-config>
    使用预定义的系统属性,在启动时增加系统属性如java -D选项。如上面的例子,log level系统属性使用以下的指定来启动一个cache server
    java -Dtangosol.coherence.log.level=3 -cp COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
    
    8.2 创建自定义的系统属性
    任何一个operational 和cache configuration 元素能够创建自定义的系统属性。预定义的系统属性的名字也能够根据需求改变。
    系统属性通过增加一个system-property属性来定义,用来覆盖。system-property属性的值可以使任何的user-defined 名。自定义系统属性通常定义在一个operational override file和一个自定义的cache configuration file.
    为operational 元素定义系统属性
    下面的例子为<join -timeout-milliseconds> operational元素顶一个了一个名为multicast.join.timeout的系统属性,被添加到opertional override file:
    
    
    <?xml version='1.0'?>
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <cluster-config>
          <multicast-listener>
             <join-timeout-milliseconds system-property="multicast.join.timeout">30000
             </join-timeout-milliseconds>
          </multicast-listener>
       </cluster-config>
    </coherence>
    
    
    
    为chache configuration 元素定义一个系统属性
    下面的例子为<cache-name>定义了一个名为cache.name的系统属性,被添加到自定义的cache configuration file:
     
    
    
    <?xml version='1.0'?>
    
    <cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config
       coherence-cache-config.xsd">
       <caching-scheme-mapping>
        <cache-mapping>
          <cache-name system-property="cache.name"></cache-name>
          ...
    
    
    改变一个预定义的系统属性
    下面的例子是为<cluster-name> operational 元素改变预定义的系统属性名,被添加到operational override file:
    <?xml version='1.0'?>
    
    <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
       xsi:schemaLocation="http://xmlns.oracle.com/coherence/
       coherence-operational-config coherence-operational-config.xsd">
       <cluster-config>
          <member-identity>
             <cluster-name system-property="myapp.cluster.name"></cluster-name>
          </member-identity>
       </cluster-config>
    </coherence>
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    Css Hack
    flex 兼容 ie9
    js 阻止父级元素的事件向子级元素传递
    php正则表达式的匹配与替换
    php的匿名类的使用
    解决php的单继承问题,实现php的多继承,trait的使用
    php的抽象类和接口的总结和区别
    eclipse的maven项目Java Resources有红叉问题
    IntelliJ全家桶IDEA Webstorm 2020 永久破解方法(说是可以任何版本)
    电脑能ping 通 ip,但是不能ping通 域名
  • 原文地址:https://www.cnblogs.com/danye/p/coherence.html
Copyright © 2011-2022 走看看