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 ,而改變oper ational 設置。這種機制是配置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>

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM