Table of Contents Previous Next PDF


Oracle Tuxedo Distributed Caching (TDC) Samples

Oracle Tuxedo Distributed Caching (TDC) Samples
This topic contains the following samples:
Sample: Using Data Caching for Clients and Servers
Suppose ${APPDIR} is /home/scott/tuxedo/dom1.
Sample: Configure Oracle Coherence
Prepare tangosol-coherence-override.xml in ${APPDIR}/config. See Listing 4‑1.
Configure Oracle Coherence cluster coherence_tux whose multicast port number is 51697 and unicast port number is 51687.
Prepare coherence-cache-config.xml in ${APPDIR}/config. See Listing 4‑2.
Configure Oracle Coherence cache tux_distributed.
Listing 4‑1 Prepare 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>
 
Listing 4‑2 Prepare 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>
 
Sample: Start Oracle Coherence Cluster
If no Oracle Coherence cluster is running, you can start your own cluster.
java -server -showversion $JAVA_OPTS -Dtangosol.coherence.mode=prod -cp ${APPDIR}/config: ${COHERENCE_HOME}/lib/coherence.jar com.tangosol.net.DefaultCacheServer
Sample: Configure Oracle Tuxedo Caching Server Module
Preparing tdcsvr_coh.xml for Oracle Tuxedo Caching Server Module
Preparing tdcsvr_coh.xml for Oracle Tuxedo Caching Server Module in ${APPDIR}/config.
See Listing 4‑3, where the <server-clopt>-f /home/scott/tuxedo/dom1/config/tdcsvr_coh.conf</server-clopt> property specifies the TDC property file.
Listing 4‑3 Configure Oracle Tuxedo Caching Server Module in Oracle Tuxedo Java Server Configuration File
<?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>
 
Note:
The class path ${APPDIR}/config</classpath> must be prior to the class path ${COHERENCE_HOME}/lib/coherence.jar.
Prepare tdcsvr_coh.conf for TDC Property File
Prepare tdcsvr_coh.conf for TDC property file in ${APPDIR}/config.
See Listing 4‑4, where it configures Oracle Tuxedo cache tc, which actually uses Oracle Coherence cache tux_distributed.
Listing 4‑4 Configure Oracle Tuxedo Distributed Caching (TDC) Property File
#* 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
 
Sample: Configure TMJAVASVR in UBBCONFIG
Configure TMJAVASVR in UBBCONFIG.
See Listing 4‑5, where multi-threaded configuration is enabled and TMJAVASVR configuration file tdcsvr_coh.xml is set.
Listing 4‑5 Configure TMJAVASVR in UBBCONFIG
*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"
...
 
Sample: Put An Oracle Tuxedo Buffer to Cache
Put an Oracle Tuxedo STRING buffer associated with a key mykey into an Oracle Tuxedo cache tc.
Listing 4‑6 Put an Oracle Tuxedo buffer
...
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);
...
 
Sample: Get An Oracle Tuxedo Buffer from Cache
Get an Oracle Tuxedo typed buffer from an Oracle Tuxedo cache tc according to a key mykey.
Listing 4‑7 Get an Oracle Tuxedo buffer
...
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);
...
 
Sample: Remove An Oracle Tuxedo Buffer from Cache
Remove an Oracle Tuxedo buffer associated with the key mykey from Oracle Tuxedo cache tc.
Listing 4‑8 Remove An Oracle Tuxedo Buffer Associated with A Key from An Oracle Tuxedo Cache
...
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);
...
 
Sample: Using Result Caching for Oracle Tuxedo Services
Sample: Configure VIEWTABLE
Configure your VIEWTABLE. See Listing 4‑9, where the buffer type is VIEW and the subtype is mystruct1.
Listing 4‑9 Configure VIEWTABLE
...
VIEW mystruct1
# type cname fbname count flag size null
string name - 1 - 31 -
string address - 1 - 255 -
char age - 1 - - -
END
...
 
Sample: Configure UBBCONFIG
Configure your UBBCONFIG. See Listing 4‑10, where
TMJAVASVR is configured
Multi-threaded configuration is enabled and the configuration file tdcsvr_coh.xml is set.
Oracle Tuxedo service mysvc1 uses caching entry svccache1 to improve performance. svccache1 uses Oracle Tuxedo cache tc1 to cache the service result. The corresponding key of the response is the value of the request data.
Listing 4‑10 Configure 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
...
 
Sample: Set on Server Side
Configure on server side. See Listing 4‑11, where the request of mysvc1 is set as STRING and the response of mysvc1 is a VIEW32 mystruct1.
Listing 4‑11 Configure on Server Side
...
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);
}
...
 
Sample: Set on Client Side
Assume a data file is like this:
Listing 4‑12 Data File Example
...
Scott
Mike
Andy
Scott
Ben
Brian
Scott
Clark
...
 
Set on your client set like Listing 4‑13.
At the first time where Scott is taken as the request, mysvc1 is invoked and the response is sent back and the response is cached into Oracle Tuxedo cache tc1 with a key Scott. As long as the data in the cache tc1 is not expired, all following requests for Scott to service mysvc1 will get response from the cache tc1 instead of invoking the service itself.
Listing 4‑13 Set on Client Set
...
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.