目次 前 次 PDF


Oracle Tuxedo Distributed Caching (TDC)のサンプル

Oracle Tuxedo Distributed Caching (TDC)のサンプル
ここでは、次のサンプルについて説明します。
サンプル: クライアントとサーバーのデータ・キャッシュの使用
${APPDIR}/home/scott/tuxedo/dom1であるとします。
サンプル: Oracle Coherenceの構成
${APPDIR}/configtangosol-coherence-override.xmlを準備します。リスト4-1を参照してください。
マルチキャスト・ポート番号が51697で、ユニキャスト・ポート番号が51687であるOracle Coherenceクラスタcoherence_tuxを構成します。
${APPDIR}/configcoherence-cache-config.xmlを準備します。リスト4-2を参照してください。
Oracle Coherenceキャッシュtux_distributedを構成します。
リスト4-1 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"
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">coherence_tux</cluster-name>
</member-identity>
<unicast-listener>
<address system-property="tangosol.coherence.localhost">localhost</address>
<port system-property="tangosol.coherence.localport">51687</port>
</unicast-listener>
<multicast-listener>
<port system-property="tangosol.coherence.clusterport">51697</port>
</multicast-listener>
</cluster-config>
</coherence>
 
リスト4-2 coherence-cache-config.xmlの準備
<?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>tux_distributed</cache-name>
<scheme-name>distributed</scheme-name>
</cache-mapping>
</caching-scheme-mapping>
 
<caching-schemes>
<distributed-scheme>
<scheme-name>distributed</scheme-name>
<service-name>DistributedCache</service-name>
<lease-granularity>member</lease-granularity>
<backing-map-scheme>
<local-scheme/>
</backing-map-scheme>
<autostart>true</autostart>
</distributed-scheme>
</caching-schemes>
</cache-config>
 
サンプル: Oracle Coherenceクラスタの起動
実行中のOracle Coherenceクラスタがない場合は、独自のクラスタを起動できます。
java -server -showversion $JAVA_OPTS -Dtangosol.coherence.mode=prod -cp ${APPDIR}/config: ${COHERENCE_HOME}/lib/coherence.jar com.tangosol.net.DefaultCacheServer
サンプル: Oracle Tuxedo Caching Serverモジュールの構成
Oracle Tuxedo Caching Serverモジュールのtdcsvr_coh.xmlの準備
${APPDIR}/configにOracle Tuxedo Caching Serverモジュールのtdcsvr_coh.xmlを準備します。
リスト4-3を参照してください。<server-clopt>-f /home/scott/tuxedo/dom1/config/tdcsvr_coh.conf</server-clopt>プロパティにTDCプロパティ・ファイルを指定しています。
リスト4-3 Oracle Tuxedo Javaサーバー構成ファイルでのOracle Tuxedo Caching Serverモジュールの構成
<?xml version="1.0" encoding="UTF-8"?>
<TJSconfig version="2.0">
<java-config>
<jvm-options>-XX:MaxPermSize=192m</jvm-options>
<jvm-options>-server</jvm-options>
<jvm-options>-Dtangosol.coherence.distributed.localstorage=false</jvm-options>
<jvm-options>-Dtangosol.coherence.mode=prod</jvm-options>
</java-config>
<tux-config>
<server-clopt>-f /home/scott/tuxedo/dom1/config/tdcsvr_coh.conf</server-clopt>
</tux-config>
<classpath-config>
</classpath-config>
<tux-resources>
</tux-resources>
<jdbc-resources>
</jdbc-resources>
<tux-server-config>
<classpath>${TUXDIR}/udataobj/tuxj/tdc/com.oracle.tuxedo.tjtdc.jar </classpath>
<classpath>${TUXDIR}/udataobj/tuxj/tdc/dms.jar</classpath>
<classpath>${TUXDIR}/udataobj/tuxj/tdc/ojdl.jar</classpath>
<classpath>${APPDIR}/config</classpath>
<classpath>${COHERENCE_HOME}/lib/coherence.jar</classpath>
<server-class name="com.oracle.tuxedo.tdc.TCache4Coherence">
</server-class>
</tux-server-config>
</TJSconfig>
 
注意:
クラス・パス${APPDIR}/config</classpath>は、クラス・パス${COHERENCE_HOME}/lib/coherence.jarよりも前にある必要があります。
TDCプロパティ・ファイルのtdcsvr_coh.confの準備
${APPDIR}/configにTDCプロパティ・ファイルのtdcsvr_coh.confを準備します。
リスト4-4を参照してください。Oracle Tuxedoキャッシュtcを構成していますが、実際にはOracle Coherenceキャッシュtux_distributedを使用しています。
リスト4-4 Oracle Tuxedo Distributed Caching (TDC)プロパティ・ファイルの構成
#* global option encoding setting
#options.encoding=no
 
#* configurations for Tuxedo cache "tc"
 
#* option encoding setting
cache.options.encoding.tc=no
#* physical cache used in Oracle Coherence
coh.cache.name.tc=tux_distributed
 
サンプル: UBBCONFIGでのTMJAVASVRの構成
UBBCONFIGTMJAVASVRを構成します。
リスト4-5を参照してください。マルチスレッド構成を有効にし、TMJAVASVR構成ファイルtdcsvr_coh.xmlを設定しています。
リスト4-5 UBBCONFIGでのTMJAVASVRの構成
*RESOURCES
...
MODEL SHM
...
*MACHINES
"m1" LMID=L1
...
*GROUPS
JGRP1 LMID=L1 GRPNO=10
 
...
TMJAVASVR SRVGRP=JGRP1 SRVID=10
MINDISPATCHTHREADS=4 MAXDISPATCHTHREADS=4 MIN=2 MAX=2
CLOPT="-- -c /home/scott/tuxedo/dom1/config/tdcsvr_coh.xml"
...
 
サンプル: キャッシュへのOracle Tuxedoバッファの格納
mykeyキーに関連付けられたOracle Tuxedo STRINGバッファをOracle Tuxedoキャッシュtcに格納します。
リスト4-6 Oracle Tuxedoバッファの配置
...
TCACHE* mycache = NULL;
char mykey[128];
char* databuf = NULL;
 
tpinit(NULL);
databuf = tpalloc("STRING", NULL, 256);
 
mycache = tpgetcache("tc");
strcpy(mykey, "myname");
strcpy(databuf, "scott");
tpcacheput(mycache, mykey, databuf, 0, 0L);
 
tpfree(databuf);
...
 
サンプル: キャッシュからのOracle Tuxedoバッファの取得
キーmykeyに従ってOracle TuxedoキャッシュtcからOracle Tuxedo型付きバッファを取得します。
リスト4-7 Oracle Tuxedoバッファの取得
...
TCACHE* mycache = NULL;
char mykey[128];
char* databuf = NULL;
 
tpinit(NULL);
databuf = tpalloc("STRING", NULL, 256);
 
mycache = tpgetcache("tc");
strcpy(mykey, "myname");
tpcacheget(mycache, mykey, &databuf, NULL, 0L);
tpfree(databuf);
...
 
サンプル: キャッシュからのOracle Tuxedoバッファの削除
Oracle Tuxedoキャッシュtcからキーmykeyに関連付けられたOracle Tuxedoバッファを削除します。
リスト4-8 キーに関連付けられたOracle TuxedoバッファのOracle Tuxedoキャッシュからの削除
...
TCACHE* mycache = NULL; char mykey[128];
char* databuf = NULL;
 
tpinit(NULL);
databuf = tpalloc("STRING", NULL, 256);
 
mycache = tpgetcache("tc"); strcpy(mykey, "myname");
tpcacheremove(mycache, mykey,0L);
 
tpfree(databuf);
...
 
サンプル: Oracle Tuxedoサービスの結果キャッシュの使用
サンプル: VIEWTABLEの構成
VIEWTABLEを構成します。リスト4‑9を参照してください。ここで、バッファ・タイプはVIEWであり、サブタイプはmystruct1です。
リスト4-9 VIEWTABLEの構成
...
VIEW mystruct1
# type cname fbname count flag size null
string name - 1 - 31 -
string address - 1 - 255 -
char age - 1 - - -
END
...
 
サンプル: UBBCONFIGの構成
UBBCONFIGを構成します。リスト4-10を参照してください。次のような内容になります
TMJAVASVRを構成
マルチスレッド構成を有効にし、構成ファイルtdcsvr_coh.xmlを設定しています。
キャッシュを有効化
Oracle Tuxedoサービスmysvc1では、キャッシュ・エントリsvccache1を使用して、パフォーマンスを高めます。svccache1では、Oracle Tuxedoキャッシュtc1を使用して、サービス結果をキャッシュに格納します。レスポンスの対応するキーは、リクエスト・データの値です。
リスト4-10 UBBCONFIGの構成
...
*GROUPS
JGRP1 LMID=L1 GRPNO=10
 
...
TMJAVASVR SRVGRP=JGRP1 SRVID=10
MINDISPATCHTHREADS=4 MAXDISPATCHTHREADS=4 MIN=2 MAX=2
CLOPT="-- -c /home/scott/tuxedo/dom1/config/tdcsvr_coh.xml"
...
*SERVICES
mysvc1
...
CACHING="svccache1"
...
*CACHING
svccache1
CACHENAME="tc1"
KEY=$request
...
 
サンプル: サーバー側での設定
サーバー側で構成します。リスト4-11を参照してください。mysvc1のリクエストをSTRINGとして設定し、mysvc1のレスポンスがVIEW32 mystruct1となっています。
リスト4-11 サーバー側での構成
...
struct mystruct1* rsp;
int tpsvrinit(int argc, char *argv[])
{
rsp = tpalloc("VIEW32", "mystruct1", sizeof(struct mystruct1));
}
...
void mysvc1(TPSVCINFO *rqst)
{
int ret = 0;
/*rqst->data is the name, getrsp will get data from the database and store into rsp*/
ret = getrsp(rqst->data, rsp);
if(ret < 0){
tpreturn(TPFAIL, 0, NULL, 0L, 0);
}
tpreturn(TPSUCCESS, 0, rsp, 0L, 0);
}
...
 
サンプル: クライアント側での設定
データ・ファイルが次のようになっていると想定としています。
リスト4-12 データ・ファイル例
...
Scott
Mike
Andy
Scott
Ben
Brian
Scott
Clark
...
 
リスト4-13のように設定されたクライアントで設定します。
最初にScottがリクエストとして取得されると、mysvc1が呼び出されてレスポンスが返されます。レスポンスは、Oracle Tuxedoキャッシュtc1にキーScottとともに格納されます。キャッシュtc1内のデータが期限切れになっていないかぎり、以後Scottからサービスmysvc1にリクエストを送ると、サービス自体が呼び出されるのではなく、キャッシュtc1からレスポンスが取得されます。
リスト4-13 クライアント側での設定
...
struct mystruct1* rsp;
char* req;
int main(int argc, char *argv[])
{
int ret;
long olen = 0;
rsp = tpalloc("VIEW32", "mystruct1", sizeof(struct mystruct1));
req = tpalloc("STRING", NULL, 32);
/*get name from the data file*/
while(getname(req) == 0){
tpcall("mysvc1",req, 0, &rsp, &olen,0);
}
}
...
 

Copyright ©1994, 2017,Oracle and/or its affiliates. All rights reserved