|
simpappは、1クライアントと1サーバーで構成されるサンプルATMIアプリケーションです。このアプリケーションは、Oracle Tuxedoソフトウェアに同梱されています。サーバーでは、1つのサービスだけが実行されます。つまり、クライアントから小文字の英字文字列を受け取り、その文字列を大文字で返します。
ここでは、サンプルOracle Tuxedo ATMIアプリケーションを開発して実行するための手順を順に示します。図2-1は、それらの作業をまとめたものです。各作業をクリックすると、その作業を行う手順が表示されます。
このチュートリアルを実行するには、Oracle Tuxedo ATMIクライアント/サーバー・ソフトウェアがインストールされ、ここで説明するファイルやコマンドを使用できることが必要です。すでにインストールされている場合は、ソフトウェアのインストール先のディレクトリのパス名(TUXDIR)を確認する必要があります。また、simpappのファイルをコピーしたり、Oracle Tuxedoの各コマンドを実行したりするために、Oracle Tuxedoディレクトリ構造内のディレクトリとファイルに対する読取り権限と書込み権限が必要です。
ここで説明するsimpappの手順は、UNIXシステムに基づいています。UNIXオペレーティング・システム環境でのプラットフォーム固有の手順は大部分そのまま適用できますが、simpappファイルのコピーや環境変数の設定などの作業を実行する手順はWindows 2003などUNIX以外のプラットフォームでは異なる場合があります。このため、チュートリアルで使用する例が、ご使用のプラットフォームに適さない場合があります。
ここで説明する作業を行うと、ATMIクライアントおよびサーバーが実行できるタスクについて理解し、環境に応じて構成ファイルを変更でき、tmadminを呼び出してアプリケーションの動作を確認できるようになります。つまり、Oracle Tuxedoアプリケーションの基本的な要素(クライアント・プロセス、サーバー・プロセス、構成ファイルなど)を理解し、Oracle Tuxedoシステムの各コマンドを使用してアプリケーションを管理できるようになります。
| 注: | 次に示す手順は、UNIXシステムに基づいています。Windows 2003などUNIX以外のプラットフォームでは、手順が異なる場合があります。サンプル・アプリケーションで使用されているサンプル・コードは、プラットフォームによって内容が異なります。 |
simpapp用にディレクトリを作成し、そのディレクトリに移動(cd)します。mkdir simpdir
cd simpdir
| 注: | 最初からあったsimpappのファイルと手順に従って作成したファイルを確認するために、この手順は省略しないでください。cshを使用せずに、標準シェル(/bin/sh)またはKornシェルを使用してください。 |
TUXDIR=pathname of the Oracle Tuxedo system root directoryTUXCONFIG=pathname of your present working directory/tuxconfigPATH=$PATH:$TUXDIR/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TUXDIR/lib
export TUXDIR TUXCONFIG PATH LD_LIBRARY_PATH
TUXDIRおよびPATHを設定して、Oracle Tuxedoシステム・ディレクトリ構造内のファイルにアクセスでき、Oracle Tuxedoコマンドを実行できるようにします。Sun Solarisでは、PATHの最上位ディレクトリとして/usr/5binを指定する必要があります。AIX (RS/6000)では、LD_LIBRARY_PATHではなくLIBPATHを使用します。HP-UX (HP 9000)では、LD_LIBRARY_PATHのかわりにSHLIB_PATHを使用します。
構成ファイルをロードするには、TUXCONFIGを設定する必要があります。詳細は、「ステップ4 :構成ファイルの編集とロード」を参照してください。
simpappファイルをコピーします。 cp $TUXDIR/samples/atmi/simpapp/* .
| 注: | 一部のファイルは、後で編集して実行可能ファイルを作成します。そのため、ソフトウェアに同梱のオリジナルのファイルではなく、そのコピーを使用することをお薦めします。 |
$ ls
README env simpapp.nt ubbmp wsimpcl
README.as400 setenv.cmd simpcl.c ubbsimple
README.nt simpapp.mk simpserv.c ubbws
$
| 注: | READMEファイルの他に、UNIXシステム以外のプラットフォーム用のsimp*.*ファイルとubb*ファイルがあります。READMEファイルには、他のファイルの説明が記述されています。 |
ATMIクライアント・プログラムのソース・コードの内容を確認します。
$ more simpcl.c
リスト2-1に出力結果を示します。
1 #include <stdio.h>
2 #include "atmi.h" /* TUXEDO */
3
4
5
6
7 #ifdef __STDC__
8 main(int argc, char *argv[])
9
10 #else
11
12 main(argc, argv)
13 int argc;
14 char *argv[];
15 #endif
16
17 {
18
19 char *sendbuf, *rcvbuf;
20 int sendlen, rcvlen;
21 int ret;
22
23 if(argc != 2) {
24 fprintf(stderr, "Usage: simpcl string\n");
25 exit(1);
26 }
27 /* Attach to BEA TUXEDO as a Client Process */
28 if (tpinit((TPINIT *) NULL) == -1) {
29 fprintf(stderr, "Tpinit failed\n");
30 exit(1);
31 }
32 sendlen = strlen(argv[1]);
33 if((sendbuf = (char *)tpalloc("STRING", NULL, sendlen+1))== NULL){
34 fprintf(stderr,"Error allocating send buffer\n");
35 tpterm();
36 exit(1);
37 }
38 if((rcvbuf = (char *)tpalloc("STRING", NULL, sendlen+1))== NULL){
39 fprintf(stderr,"Error allocating receive buffer\n");
40 tpfree(sendbuf);
41 tpterm();
42 exit(1);
43 }
44 strcpy(sendbuf, argv[1]);
45 ret = tpcall("TOUPPER", sendbuf, NULL, &rcvbuf, &rcvlen, 0);
46 if(ret == -1) {
47 fprintf(stderr, "Can't send request to service TOUPPER\n");
48 fprintf(stderr, "Tperrno = %d, %s\n", tperrno, tpstrerror(tperrno));
49 tpfree(sendbuf);
50 tpfree(rcvbuf);
51 tpterm();
52 exit(1);
53 }
54 printf("Returned string is: %s\n", rcvbuf);
55
56 /* Free Buffers & Detach from Oracle TUXEDO */
57 tpfree(sendbuf);
58 tpfree(rcvbuf);
59 tpterm();
60 }
buildclientを実行して、ATMIクライアント・プログラムをコンパイルします。 buildclient -o simpcl -f simpcl.c
simpclは出力ファイル、simpcl.cは入力ソース・ファイルです。
$ ls -l
total 97
-rwxr-x--x 1 usrid grpid 313091 May 28 15:41 simpcl
-rw-r----- 1 usrid grpid 1064 May 28 07:51 simpcl.c
-rw-r----- 1 usrid grpid 275 May 28 08:57 simpserv.c
-rw-r----- 1 usrid grpid 392 May 28 07:51 ubbsimple
ATMIサーバー・プログラムのソース・コードの内容を確認します。
$ more simpserv.c
*/
/* #ident "@(#) apps/simpapp/simpserv.c $Revision: 1.1 $" */1#include <stdio.h>2#include <ctype.h>3#include <atmi.h> /* TUXEDO Header File */4#include <userlog.h> /* TUXEDO Header File */5/* tpsvrinit is executed when a server is booted, before it begins
processing requests. It is not necessary to have this function.
Also available is tpsvrdone (not used in this example), which is
called at server shutdown time.
9*/10#if defined(__STDC__) || defined(__cplusplus)12tpsvrinit(int argc, char *argv[])13#else14tpsvrinit(argc, argv)15int argc;16char **argv;17#endif18{19/* Some compilers warn if argc and argv aren't used.20*/21argc = argc;22argv = argv;23/* userlog writes to the central TUXEDO message log */24userlog("Welcome to the simple server");25return(0);26}27/* This function performs the actual service requested by the client.
Its argument is a structure containing, among other things, a pointer
to the data buffer, and the length of the data buffer.30*/31#ifdef __cplusplus32extern "C"33#endif34void35#if defined(__STDC__) || defined(__cplusplus)36TOUPPER(TPSVCINFO *rqst)37#else38TOUPPER(rqst)39TPSVCINFO *rqst;40#endif41{42int i;4344for(i = 0; i < rqst->len-1; i++)45rqst->data[i] = toupper(rqst->data[i]);46/* Return the transformed buffer to the requestor. */47tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);48}
buildserverを実行して、ATMIサーバー・プログラムをコンパイルします。buildserver -o simpserv -f simpserv.c -s TOUPPER
simpservは作成される実行ファイル、simpserv.cは入力ソース・ファイルです。-s TOUPPERオプションは、サーバーの起動時に通知されるサービスを指定します。
$ ls -l
total 97
-rwxr-x--x 1 usrid grpid 313091 May 28 15:41 simpcl
-rw-r----- 1 usrid grpid 1064 May 28 07:51 simpcl.c
-rwxr-x--x 1 usrid grpid 358369 May 29 09:00 simpserv
-rw-r----- 1 usrid grpid 275 May 28 08:57 simpserv.c
-rw-r----- 1 usrid grpid 392 May 28 07:51 ubbsimple
simpappの構成ファイルubbsimpleの内容を確認します。1$
2
3 #Skeleton UBBCONFIG file for the BEA Tuxedo Simple Application.
4 #Replace the <bracketed> items with the appropriate values.
5 RESOURCES
6 IPCKEY <Replace with valid IPC Key greater than 32,768>
7
8 #Example:
9
10 #IPCKEY 62345
11
12 MASTER simple
13 MAXACCESSERS 5
14 MAXSERVERS 5
15 MAXSERVICES 10
16 MODEL SHM
17 LDBAL N
18
19 *MACHINES
20
21 DEFAULT:
22
23 APPDIR="<Replace with the current pathname>"
24 TUXCONFIG="<Replace with TUXCONFIG Pathname>"
25 UXDIR="<Root directory of Tuxedo (not /)>"
26 #Example:
27 # APPDIR="/usr/me/simpdir"
28 # TUXCONFIG="/usr/me/simpdir/tuxconfig"
29 # TUXDIR="/usr/tuxedo"
30
31 <Machine-name> LMID=simple
32 #Example:
33 #tuxmach LMID=simple
34 *GROUPS
35 GROUP1
36 LMID=simple GRPNO=1 OPENINFO=NONE
37
38 *SERVERS
39 DEFAULT:
40 CLOPT="-A"
41 simpserv SRVGRP=GROUP1 SRVID=1
42 *SERVICES
43 TOUPPER
<string>を適切な値に置き換えます。tmloadcfを実行して、構成ファイルをロードします。$ tmloadcf ubbsimple
Initialize TUXCONFIG file: /usr/me/simpdir/tuxconfig [y, q] ? y
$
$ ls -l
total 216
-rwxr-x--x 1 usrid grpid 313091 May 28 15:41 simpcl
-rw-r----- 1 usrid grpid 1064 May 28 07:51 simpcl.c
-rwxr-x--x 1 usrid grpid 358369 May 29 09:00 simpserv
-rw-r----- 1 usrid grpid 275 May 28 08:57 simpserv.c
-rw-r----- 1 usrid grpid 106496 May 29 09:27 tuxconfig
-rw-r----- 1 usrid grpid 382 May 29 09:26 ubbsimple
TUXCONFIGというファイルが作成されました。TUXCONFIGファイルは、Oracle Tuxedoシステムで制御される新しいファイルです。
tmbootを実行して、アプリケーションを起動します。$ tmboot
Boot all admin and server processes? (y/n): y
Booting all admin and server processes in /usr/me/simpdir/tuxconfig
Booting all admin processes ...
exec BBL -A:
process id=24223 ... Started.
Booting server processes ...
exec simpserv -A :
process id=24257 ... Started.
2 processes started.
$
BBLは、アプリケーションの共有メモリーをモニターする管理プロセスです。simpservは、リクエストを受け取るために継続的に実行しているsimpappサーバーです。
simpappを実行するには、クライアントからリクエストを送信します。
$ simpcl “hello, world”
Returned string is: HELLO, WORLD
システム管理者はtmadminコマンド・インタプリタを使用して、アプリケーションを調べ、動的に変更を加えることができます。tmadminを実行するには、TUXCONFIG環境変数を設定する必要があります。
tmadminを使用すると、50個以上のコマンドを解釈したり実行したりできます。完全なリストは、「tmadmin(1)」を参照してください。この例では、2つのtmadminコマンドを使用します。
| 注: | 大なり記号(>)は、tmadminのプロンプトです。 |
printserver(psr)コマンドを入力して、サーバーに関する情報を出力します。> psr
a.out Name Queue Name Grp Name ID RqDone Load Done Current Service
---------- ---------- -------- -- ------ --------- ---------------
BBL 531993 simple 0 0 0 ( IDLE )
simpserv 00001.00001 GROUP1 1 0 0 ( IDLE )
>
printservice(psc)コマンドを入力して、サービスに関する情報を出力します。 > psc
Service Name Routine Name a.out Name Grp Name ID Machine # Done Status
------------ ------------ ---------- -------- -- ------- ------ ------
TOUPPER TOUPPER simpserv GROUP1 1 simple - AVAIL
>
tmshutdownを実行して、アプリケーションを停止します。$ tmshutdown
Shutdown all admin and server processes? (y/n): y
Shutting down all admin and server processes in /usr/me/simpdir/tuxconfig
Shutting down server processes ...
Server Id = 1 Group Id = GROUP1 Machine = simple: shutdown succeeded.
Shutting down admin processes ...
Server Id = 0 Group Id = simple Machine = simple: shutdown succeeded.
2 processes stopped.
$
ULOGの内容を確認します。$ cat ULOG*
$
113837.tuxmach!tmloadcf.10261: CMDTUX_CAT:879: A new file system has been created. (size = 32 4096-byte blocks)
113842.tuxmach!tmloadcf.10261: CMDTUX_CAT:871: TUXCONFIG file /usr/me/simpdir/tuxconfig has been created
113908.tuxmach!BBL.10768: LIBTUX_CAT:262: std main starting
113913.tuxmach!simpserv.10925: LIBTUX_CAT:262: std main starting
113913.tuxmach!simpserv.10925: Welcome to the simple server
114009.tuxmach!simpserv.10925: LIBTUX_CAT:522: Default tpsvrdone() function used.
114012.tuxmach!BBL.10768: CMDTUX_CAT:26: Exiting system
|