Chinaunix首页 | 论坛 | 博客
  • 博客访问: 170325
  • 博文数量: 77
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 990
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-21 18:13
文章分类

全部博文(77)

文章存档

2011年(1)

2009年(76)

我的朋友

分类:

2009-07-08 21:47:15

§3.3 检查bankapp的服务器和服务

服务器是一些可执行的进程,它们提供一个或多个服务。在Tuxedo系统中,服务器始终接受来自客户端的服务请求,并将它们分配给某些服务,让它们来处理请求。所有bankapp的服务都是用C语言写的,包含有嵌入式SQL语句的C程序扩展名不是C而是ECTRANSFERXFER服务器来提供,它是唯一一个不包含嵌入式SQL的服务。所有bankapp服务使用ATMI的函数来管理类型缓冲区、和其它服务进行同步或异不通信、定义全局事务、一般地访问资源服务器、把响应发送回客户端。

1bankapp的请求/响应服务器

bankapp5个服务器中,有4个用到了嵌入式SQL访问资源管理器,这些服务器的扩展名为ECXFER是一个转账的服务器,本身不调用资源管理器,而调用了其它服务器中的WITHDRAWALDEPOSIT两个服务。5个服务器的描述如下:

服务器

提供的功能

BTADD.EC

允许任何一个站的支行和出纳员的记录添加到数据库中

ACCT.EC

提供一些账号相关的有代表性的服务,如OPEN_ACCT, CLOSE_ACCT

TLR.EC

为出纳员提供服务,如WITHDRAWAL, DEPOSIT, INQUIRY,每一个TLR进程标识着它本身是TELLER文件中的一个真实的出纳员

XFER.C

在账号之间进行转账业务

BAL.EC

计算所有支行或某个支行的余额

2bankapp的会话服务器

AUDITC是一个会话服务器的例子,它提供了一个服务,名字也叫AUDITC。客户机auditcon建立一个与服务AUDITC的会话连接,然后发出请求。AUDITC分析请求,并调用适当的服务(ABALTBALABAL_BIDTBAL_BID),当AUDITC从这些服务获得响应后,再将它们送回auditcon。会话服务器可以以客户机的身份请求其它服务,也可以连接到其它会话服务器。

3bankapp的服务

bankapp提供了12个请求/响应服务。服务名和C语言函数名相同:

服务名

提供服务器

输入

执行功能

BR_ADD

BTADD

FML缓冲区

添加一个新支行记录

TLR_ADD

BTADD

FML缓冲区

添加一条新出纳员记录

OPEN_ACCT

ACCT

FML缓冲区

ACCOUNT文件中插入一条记录并调用DEPOSIT存入开户金额;在支行代号BRANCH_ID的基础上选择一个ACCOUNT_ID

CLOSE_ACCT

ACCT

FML缓冲区

删除一个ACCOUNT记录;验证ACCOUNT_ID

调用WITHDRAWAL取走所有余额

WITHDRAWAL

TLR

FML缓冲区

从一个指定的支行、出纳员、账号取款;

验证ACCOUNT_IDSAMOUNT字段

DEPOSIT

TLR

FML缓冲区

向某个支行、出纳员、账号存款;

验证ACCOUNT_IDSAMOUNT字段

INQUIRY

TLR

FML缓冲区

查询账号余额;验证ACCOUNT_ID

TRANSFER

XFER

FML缓冲区

执行一个tpcall()调用,先后请求WITHDRAWALDEPOSIT服务

ABAL

BAL

aud.vVIEW缓冲区

计算某一个站点所有账号的余额

TBAL

BAL

aud.vVIEW缓冲区

计算某个站点所有支行出纳员的余额

ABAL_BID

BAL

aud.vVIEW缓冲区

计算BRANCH_ID的账号余额

TBAL_BID

BAL

aud.vVIEW缓冲区

计算BRANCH_ID的出纳员余额

bankapp服务的算法

⑴.BR_ADD

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

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

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 withFinit();

-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

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

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

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

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

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

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

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

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;

}

⑿.ABAL_BID

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;

}

阅读(1291) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~