![]() |
![]() |
|
|
Examining the bankapp Servers and Services
This topic provides the following information:
Servers are executable processes that offer one or more services. In the BEA Tuxedo system, they continually accept requests (from processes acting as clients) and dispatch them to the appropriate services. Services are subroutines of C language code written specifically for an application. BEA Tuxedo's applications are written to make services available and capable of accessing resource managers. Service routines must be written by BEA Tuxedo application programmers.
All bankapp services are coded in C with embedded SQL except for the TRANSFER service, which does not interact directly with the database. The TRANSFER service is offered by the XFER server and is a C program (that is, its source file is a .c file rather than a .ec file).
All bankapp services of bankapp use functions provided in the Application Transaction Management Interface (ATMI) for performing the following tasks:
bankapp Request/Response Servers
Five bankapp servers operate in request/response mode. Four of the five use embedded SQL statements to access a resource manager; the names of the source files for these servers (located in the bankapp sample application subdirectory), include a .ec filename extension.
The fifth server, XFER, for transfer, makes no calls to the resource manager itself; it calls the WITHDRAWAL and DEPOSIT services (offered by the TLR server) to transfer funds between accounts. The source file for XFER is a .c file, because XFER makes no resource manager calls and contains no embedded SQL statements.
AUDITC is an example of a conversational server. It offers one service, which is also called AUDITC. The conversational client, auditcon, establishes a connection to AUDITC and sends it requests for auditing information.
AUDITC evaluates requests and calls an appropriate service (ABAL, TBAL, ABAL_BID, or TBAL_BID) to get the appropriate information. When a reply is received from the service called, AUDITC sends it back to auditcon. A service in a conversational server can make calls to request/response services. It can also initiate connections to other conversational servers, but this functionality is not provided by AUDITC.
bankapp Services
bankapp offers 12 request/response services. The name of each bankapp service matches the name of a C function in the source code of a server.
Algorithms of bankapp Services
The following listings show pseudo-code for the algorithms used for the bankapp services: BR_ADD, TLR_ADD, OPEN_ACCT, CLOSE_ACCT, WITHDRAWAL, DEPOSIT, INQUIRY, TRANSFER, ABAL, TBAL, ABAL_BID, and TBAL_BID. You can use them as road maps through the source code of the bankapp servers.
BR_ADD Pseudo-code
void BR_ADD (TPSVCINFO *transb)
{
-set pointer to TPSVCINFO data buffer;
-get all values for service request from field buffer;
-insert record into BRANCH;
-tpreturn() with success;
}
TLR_ADD Pseudo-code
void TLR_ADD (TPSVCINFO *transb)
{
-set pointer to TPSVCINFO data buffer;
-get all values for service request from fielded buffer;
-get TELLER_ID by reading branch's LAST_ACCT;
-insert teller record;
-update BRANCH with new LAST_TELLER;
-tpreturn() with success;
}
OPEN_ACCT Pseudo-code
void OPEN_ACCT(TPSVCINFO *transb)
{
-Extract all values for service request from fielded buffer using Fget()and Fvall();
-Check that initial deposit is positive amount and tpreturn() with failure
if not;
-Check that branch ID is a legal value and tpreturn() with failure if it is
not;
-Set transaction consistency level to read/write;
-Retrieve BRANCH record to choose new account based on branch's LAST_ACCT
field;
-Insert new account record into ACCOUNT file;
-Update BRANCH record with new value for LAST_ACCT;
-Create deposit request buffer with tpalloc(); initialize it for FML with
Finit();
-Fill deposit buffer with values for DEPOSIT service request;
-Increase priority of coming DEPOSIT request since call is from a service;
-Do tpcall() to DEPOSIT service to add amount of initial balance;
-Prepare return buffer with necessary information;
-Free deposit request buffer with tpfree();
tpreturn() with success;
}
CLOSE_ACCT Pseudo-code
void CLOSE_ACCT(TPSVCINFO *transb)
{
-Extract account ID from fielded buffer using Fvall();
-Check that account ID is a legal value and tpreturn() with failure if it
is not;
-Set transaction consistency level to read/write;
-Retrieve ACCOUNT record to determine amount of final withdrawal;
-Create withdrawal request buffer with tpalloc(); initialize it for FML with
Finit();
-Fill withdrawal buffer with values for WITHDRAWAL service request;
-Increase priority of coming WITHDRAWAL request since call is from a service;
-Do tpcall() to WITHDRAWAL service to withdraw balance of account;
-Delete ACCOUNT record;
-Prepare return buffer with necessary information;
-Free withdrawal request buffer with tpfree();
tpreturn with success;
}
WITHDRAWAL Pseudo-code
void WITHDRAWAL(TPSVCINFO *transb)
{
-Extract account id and amount from fielded buffer using Fvall() and Fget();
-Check that account id is a legal value and tpreturn() with failure if not;
-Check that withdraw amount (amt) is positive and tpreturn() with failure
if not;
-Set transaction consistency level to read/write;
-Retrieve ACCOUNT record to get account balance;
-Check that amount of withdrawal does not exceed ACCOUNT balance;
-Retrieve TELLER record to get teller's balance and branch id;
-Check that amount of withdrawal does not exceed TELLER balance;
-Retrieve BRANCH record to get branch balance;
-Check that amount of withdrawal does not exceed BRANCH balance;
-Subtract amt to obtain new account balance;
-Update ACCOUNT record with new account balance;
-Subtract amt to obtain new teller balance;
-Update TELLER record with new teller balance;
-Subtract amt to obtain new branch balance;
-Update BRANCH record with new branch balance;
-Insert new HISTORY record with transaction information;
-Prepare return buffer with necessary information;
tpreturn with success;
}
DEPOSIT Pseudo-code
void DEPOSIT(TPSVCINFO *transb)
{
-Extract account id and amount from fielded buffer using Fvall() and Fget();
-Check that account ID is a legal value and tpreturn() with failure if not;
-Check that deposit amount (amt) is positive and tpreturn() with failure if
not;
-Set transaction consistency level to read/write;
-Retrieve ACCOUNT record to get account balance;
-Retrieve TELLER record to get teller's balance and branch ID;
-Retrieve BRANCH record to get branch balance;
-Add amt to obtain new account balance;
-Update ACCOUNT record with new account balance;
-Add amt to obtain new teller balance;
-Update TELLER record with new teller balance;
-Add amt to obtain new branch balance;
-Update BRANCH record with new branch balance;
-Insert new HISTORY record with transaction information;
-Prepare return buffer with necessary information;
tpreturn() with success;
}
INQUIRY Pseudo-code
void INQUIRY(TPSVCINFO *transb)
{
-Extract account ID from fielded buffer using Fvall();
-Check that account ID is a legal value and tpreturn() with failure if not;
-Set transaction consistency level to read only;
-Retrieve ACCOUNT record to get account balance;
-Prepare return buffer with necessary information;
tpreturn() with success;
}
TRANSFER Pseudo-code
void TRANSFER(TPSVCINFO *transb)
{
-Extract account ID's and amount from fielded buffer using Fvall() and Fget();
-Check that both account IDs are legal values and tpreturn() with failure
if not;
-Check that transfer amount is positive and tpreturn() with failure if it
is not;
-Create withdrawal request buffer with tpalloc(); initialize it for FML with
Finit();
-Fill withdrawal request buffer with values for WITHDRAWAL service request;
-Increase priority of coming WITHDRAWAL request since call is from a service;
-Do tpcall() to WITHDRAWAL service;
-Get information from returned request buffer;
-Reinitialize withdrawal request buffer for use as deposit request buffer
with Finit();
-Fill deposit request buffer with values for DEPOSIT service request;
-Increase priority of coming DEPOSIT request;
-Do tpcall() to DEPOSIT service;
-Prepare return buffer with necessary information;
-Free withdrawal/deposit request buffer with tpfree();
tpreturn() with success;
}
ABAL Pseudo-code
void ABAL(TPSVCINFO *transb)
{
-Set transaction consistency level to read only;
-Retrieve sum of all ACCOUNT file BALANCE values for the
database of this server group (A single ESQL
statement is sufficient);
-Place sum into return buffer data structure;
tpreturn( ) with success;
}
TBAL Pseudo-code
void TBAL(TPSVCINFO *transb)
{
-Set transaction consistency level to read only;
-Retrieve sum of all TELLER file BALANCE values for the
database of this server group (A single ESQL
statement is sufficient);
-Place sum into return buffer data structure;
tpreturn( ) with success;
}
ABAL_BID Pseudo-code
void ABAL_BID(TPSVCINFO *transb)
{
-Set transaction consistency level to read only;
-Set branch_ID based on transb buffer;
-Retrieve sum of all ACCOUNT file BALANCE values for records
having BRANCH_ID = branch_ID (A single ESQL
statement is sufficient);
-Place sum into return buffer data structure;
tpreturn( ) with success;
}
TBAL_BID Pseudo-code
void TBAL_BID(TPSVCINFO *transb)
{
-Set transaction consistency level to read only;
-Set branch_ID based on transb buffer;
-Retrieve sum of all TELLER file BALANCE values for records
having BRANCH_ID = branch_ID (A single ESQL
statement is sufficient);
-Place sum into return buffer data structure;
tpreturn( ) with success;
}
Utilities Incorporated into Servers
Two C subroutines are included among the source files for bankapp: appinit.c and util.c:
Alternative Way to Code Services
In the bankapp source files all the services were incorporated into files that are referred to as the source code for servers. These files have the same names as the bankapp servers, but are not really servers because they do not contain a main() section. A standard main() is provided by the BEA Tuxedo system at buildserver time.
An alternative organization for a BEA Tuxedo system application is to keep each service subroutine in a separate file. Suppose, for example, that you want to use this alternative structure for the TLR server. The TLR.ec file contains three services that you maintain in three separate .ec files: INQUIRY.ec, WITHDRAW.ec, and DEPOSIT.ec. Follow these steps.
buildserver -r TUXEDO/SQL \
-s DEPOSIT -s WITHDRAWAL -s INQUIRY \
-o TLR \
-f DEPOSIT.o -f WITHDRAW.o -f INQUIRY.o \
-f util.o -f -lm
Note: The backslash in the preceding command-line entry is a documentation convention that indicates a line break for presentation purposes only. You should enter the command and options on one line
As this example illustrates, you do not need to code all the service functions in a single source file. In other words, a server does not need to exist as a source program file at all. It can be derived from various source files and exist as a server executable through the files specified on the buildserver command line. This can give you greater flexibility in building servers.
See Also
![]() |
![]() |
![]() |
|
Copyright © 2000 BEA Systems, Inc. All rights reserved.
|