Documentation Roadmap
In addition to describing how to bring up and run a
sample application, in this book we hope to familiarize you
with the rest of the System/T documentation set.
To that end, most chapters in the book close with a section
that refers to other guides where the topics
of that chapter are dealt with in more detail.
In most cases, we do not think you will have to refer to
other documents to bring
bankapp
up successfully, but when you do run into topics on which
you would like more information, you can follow those
pointers.
This chapter contains a tutorial that describes a simple
one-client, one-server application called
simpapp.
An interactive form of this application is distributed with the
TUXEDO System/T software.
If you follow the ten steps of the tutorial you will;
learn how
a System/T application is organized
see how clients and servers are written and compiled
understand how an application is described in the
configuration file
actually create an executable version of
simpapp
boot, run and shutdown the application
Some Preliminaries
Before you can run this tutorial the TUXEDO System/T software must
be installed so that the files and commands
referred to in this chapter are available.
If you are personally responsible for installing the TUXEDO System/T
software, consult the
BEA TUXEDO Installation Guide
for information about how to install System/T.
If the installation has already been done by someone else,
you need to know the pathname of the directory
of the installed software (TUXDIR).
You also need to have read and execute permissions
on the directories and
files in the TUXEDO System/T directory structure
so you can copy
simpapp
files and execute System/T commands.
The simpapp Tutorial
simpapp
is a very basic TUXEDO System/T application.
It has one client and one server.
The server performs only one service;
it accepts a string from the client and returns
the same string in upper case.
The tutorial consists of ten steps designed to introduce
you to TUXEDO System/T by showing how an application is developed
and by encouraging you to bring the application up and run
it.
Each of the ten steps includes one or more smaller steps.
Step 1: Copy the simpapp files
- Step 1.1
- Make a directory for
simpapp
and
cd
to it:
mkdir simpdir
cd simpdir
This is suggested so you will be able to see clearly the
simpapp
files you have at the start and the additional files you
create along the way.
Use the standard shell (
/bin/sh)
or the Korn shell; not
csh.
- Step 1.2
- Set and export environment variables
TUXDIR=<pathname of the TUXEDO System/T root directory>
TUXCONFIG=<pathname of your present working directory>/tuxconfig
PATH=$PATH:$TUXDIR/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TUXDIR/lib
export TUXDIR TUXCONFIG PATH LD_LIBRARY_PATH
You need
TUXDIR
and
PATH
to be able to access files in the TUXEDO System/T directory structure
and to execute TUXEDO System/T commands.
On SunOS,
/usr/5bin
must be the first directory in your
PATH.
With AIX on the RS6000, LIBPATH is used instead of LD_LIBRARY_PATH.
With HPUX on the HP9000, SHLIB_PATH is used instead of LD_LIBRARY_PATH.
You need to set
TUXCONFIG
to be able to load the configuration file,
which is described in Step 7.
- Step 1.3
- Copy the
simpapp
files.
cp $TUXDIR/apps/simpapp/* .
Later on you will be editing some
of the files and making them
executable, so it is best to begin with a copy of the
files rather than the originals delivered with the software.
- Step 1.4
- List the files.
$ ls
README env simpapp.nt ubbmp wsimpcl
README.as400 setenv.cmd simpcl.c ubbsimple
README.nt simpapp.mk simpserv.c ubbws
$
The three files that are central to the application are:
simpcl.c -- the source code for the client program
simpserv.c -- the source code for the server
program
ubbsimple -- the ASCII form of the configuration
file for the application
The other files are variations of these for platforms other than Unix.
The README files explain.
Step 2: Examine the Client Program
- Step 2.1
-
Page through the client program source code:
$ more simpcl.c
The output is shown in Figure 1.
Fig. 1: Source code of simpcl.c
1 #include <stdio.h> /* UNIX */
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 System/T 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,
49 tmemsgs[tperrno]);
50 tpfree(sendbuf);
51 tpfree(rcvbuf);
52 tpterm();
53 exit(1);
54 }
55 printf("Returned string is: %s\n", rcvbuf);
56
57 /* Free Buffers & Detach from System/T */
58 tpfree(sendbuf);
59 tpfree(rcvbuf);
60 tpterm();
61 }
Here are eight important things to see in this file:
| line 2
| atmi.h
| header file needed whenever System/T
ATMI calls are used
|
| line 28
| tpinit()
| the ATMI
call used by a client program to join an application
|
| line 33
| tpalloc()
| the
ATMI
call used to allocate a typed buffer.
STRING
is one of the four basic System/T buffer types,
NULL indicates there is no sub-type argument.
The remaining argument,
sendlen + 1
specifies the length of the buffer plus 1 for the null
character that ends the string.
|
| line 38
| tpalloc()
| allocates another buffer for the return message
|
| line 45
| tpcall()
| sends the message buffer to the service specified in
the first argument.
Also includes the address of the return buffer.
tpcall
waits for a return message.
|
| lines 35, 41, 52 & 60
| tpterm()
| the
ATMI
call used to leave an application.
A call to
tpterm()
is used to leave the application
prior to taking an exit due to an error condition
(lines 36, 42 & 53).
The final
tpterm()
(line 59) comes after the message has been printed.
|
| lines 40, 50, 51, 58 & 59
| tpfree()
| the counterpart of tpalloc() to free allocated
buffers.
|
| line 55
| printf()
| This is the successful conclusion of the program.
It prints out the message returned from the server.
|
References
The
ATMI
calls cited above are documented in
the
BEA TUXEDO Reference Manual: Section 3c
Step 3: Compile the Client
- Step 3.1
- Run
buildclient
to compile the client program:
buildclient -o simpcl -f simpcl.c
where the output file is
simpcl,
and
the input source file is
simpcl.c.
- Step 3.2
-
Check the results:
$ 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
As can be seen, we now have an executable module called
simpcl.
The file sizes shown above may not be what you see on your system.
References
buildclient
is documented in
buildclient(1)
Step 4: Examine the server
- Step 4.1
-
Page through the server program source code:
$ more simpserv.c
Fig. 2: Source code of simpserv.c
#include <stdio.h>
#include <ctype.h>
#include <atmi.h> /* TUXEDO Header File */
#include <userlog.h> /* TUXEDO Header File */
/* 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.
*/
#if defined(__STDC__) || defined(__cplusplus)
Note 1. tpsvrinit(int argc, char *argv[])
#else
tpsvrinit(argc, argv)
int argc;
char **argv;
#endif
{
/* Some compilers warn if argc and argv aren't used. */
argc = argc;
argv = argv;
/* userlog writes to the central TUXEDO message log */
userlog("Welcome to the simple server");
return(0);
}
/* 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.
*/
#ifdef __cplusplus
extern "C"
#endif
void
#if defined(__STDC__) || defined(__cplusplus)
Note 2. TOUPPER(TPSVCINFO *rqst)
#else
TOUPPER(rqst)
TPSVCINFO *rqst;
#endif
{
int i;
Note 3. for(i = 0; i len-1; i++)
rqst->data[i] = toupper(rqst->data[i]);
/* Return the transformed buffer to the requester. */
Note 4. tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);
}
Here are five important things to see in this file:
| whole file
|
| notice that a TUXEDO System/T server
does not contain a main().
The main() is provided by System/T when the server
is built.
|
| Note 1.
| tpsvrinit()
| this subroutine is called during server initialization,
before the server begins processing service requests.
A default is provided by System/T that
writes a message to userlog indicating that
the server has been booted.
userlog(3c) is a log that is used by System/T and can
be used by applications.
We'll see the format in Step 10.
|
| Note 2.
| TOUPPER
| the declaration of a service (the only one offered by
simpserv).
The sole argument expected by the service is a pointer
to a
TPSVCINFO
structure, which contains the data string to be converted
to uppercase.
|
| Note 3.
| for loop
| converts the input to uppercase by repeated calls to
toupper.
|
| Note 4.
| tpreturn
| returns the converted string
to the client with the
TPSUCCESS
flag set.
|
References
The
ATMI
calls and structure
cited above are documented in
the
BEA TUXEDO Reference Manual: Section 3c
Step 5: Compile the Server
- Step 5.1
- Run
buildserver
to compile the server program:
buildserver -o simpserv -f simpserv.c -s TOUPPER
where the executable file to be created is named
simpserv,
and
simpserv.c
is the input source file.
The
-s TOUPPER
option specifies the service to be advertised when the
server is booted.
- Step 5.2
- Check the results:
$ 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
As can be seen, we now have an executable module called
simpserv.
The file sizes shown above may not be what you see on your system.
References
buildserver
is documented in
buildserver(1).
Step 6: Edit the Configuration File
- Step 6.1
-
Edit the file
Fig. 3: The simpapp configuration file
$vi ubbsimple
#Skeleton UBBCONFIG file for the TUXEDO Simple Application.
#Replace the <bracketed> items with the appropriate values.
*RESOURCES
IPCKEY <Replace with valid IPC Key greater than 32,768>
#Example:
#IPCKEY 62345
MASTER simple
MAXACCESSERS 5
MAXSERVERS 5
MAXSERVICES 10
MODEL SHM
LDBAL N
*MACHINES
DEFAULT:
APPDIR="<Replace with the current pathname>"
TUXCONFIG="<Replace with TUXCONFIG Pathname>"
TUXDIR="<Root directory of TUXEDO (not /)>"
#Example:
# APPDIR="/usr/me/simpdir"
# TUXCONFIG="/usr/me/simpdir/tuxconfig"
# TUXDIR="/usr/tuxedo"
<Machine-name> LMID=simple
#Example:
#tuxmach LMID=simple
*GROUPS
GROUP1
LMID=simple GRPNO=1 OPENINFO=NONE
*SERVERS
DEFAULT:
CLOPT="-A"
simpserv SRVGRP=GROUP1 SRVID=1
*SERVICES
TOUPPER
:
- Step 6.2
-
Change values enclosed in angle brackets
to your own local values:
| IPCKEY
| use a value that will not conflict with any other
users
|
| TUXCONFIG
| provide the full pathname of the binary tuxconfig file
to be created in Step 7
|
| TUXDIR
| provide the full pathname of your TUXEDO System/T root directory
|
| APPDIR
| provide the full pathname of the directory where you intend
to boot the application; in this case, the current
directory
|
| Machine-name
| provide the machine name as returned by
uname -n
|
- Step 6.3
-
The pathnames for
TUXCONFIG
and
TUXDIR
must be identical to those you set and exported in Step 1.2.
The strings must be the actual values; environment
variables (like $TUXCONFIG, for example) are not
acceptable.
Don't forget to remove the angle brackets.
References
The configuration file
is documented in
ubbconfig(5).
Step 7: Load the Configuration File
- Step 7.1
-
Run
tmloadcf
to load the configuration file:
$ tmloadcf ubbsimple
Initialize TUXCONFIG file: /usr/me/simpdir/tuxconfig [y, q] ? y
$
- Step 7.2
- Check the results:
$ 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
We see that we now have a file called
tuxconfig.
The
tuxconfig
file is a new file system under the control of TUXEDO System/T.
References
tmloadcf
is documented in
tmloadcf(1).
Step 8: Boot the Application
- Step 8.1
-
Execute
tmboot
to bring up the application:
$ 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 is the administrative process that monitors the
application shared memory structures.
simpserv
is our server that runs continuously awaiting requests.
References
tmboot
is documented in
tmboot(1).
Step 9: Enter a Request
- Step 9.1
-
Run the client program to submit a request:
$ simpcl "hello, world"
Returned string is: HELLO, WORLD
We are successful!!!
Step 10: Using tmadmin
tmadmin
is an interactive program that an administrator can use to
check an application and make dynamic changes.
It requires the
TUXCONFIG
variable to be set.
We will show you just two of the many
tmadmin
commands.
- Step 10.1
-
Enter the command:
$ tmadmin
You will see the lines:
tmadmin - Copyright (c) 1997 BEA Systems, Inc. All rights reserved.
>
The greater-than sign (>) is the tmadmin
prompt.
- Step 10.2
-
Enter the
printserver(psr)
command to display information about the servers:
> 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 )
>
- Step 10.3
-
Enter the
printservice(psc)
command to display information about the services:
> psc
Service Name Routine Name a.out Name Grp Name ID Machine # Done Status
------------ ------------ ---------- -------- -- ------- ------ ------
TOUPPER TOUPPER simpserv GROUP1 1 simple - AVAIL
>
- Step 10.4
-
Leave
tmadmin
by entering a
q
at the prompt.
You can boot and shut down the application from within
tmadmin.
We have done those functions with shell commands in Step 8
and Step 11, respectively.
References
tmadmin
is documented in
tmadmin(1).
Step 11: Shutdown the Application
- Step 11.1
-
Run
tmshutdown
to bring the application down:
$ 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.
$
- Step 11.2
-
Check the
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
Each line of the ULOG for this session contains something of interest.
Most are self-explanatory, but we want to add some explanation
for a couple of them.
First let's look at the format of a ULOG line:
time (hhmmss).machine_uname!process_name.process_id: log message
Now let's look at some individual lines:
113913. Message from tpsvrinit() in simpserv
114009. When simpserv is shutdown the System/T main sends this message
References
tmshutdown
is documented in
tmshutdown(1).
The
userlog
is documented in
userlog(3c).
Summary
If you have reached this point,
you have successfully brought up, run and brought down
a TUXEDO System/T application.
You have seen what a client program
and a server look like.
You have edited a configuration file to refer to your
own environment.
You have invoked
tmadmin
to check on the activity of your application.
In all the applications you may work on in the future the
basic elements of client processes, server processes and a
configuration file will be present, and you will have
all of the System/T shell commands at your fingertips.
Good luck!