Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1791222
  • 博文数量: 600
  • 博客积分: 10581
  • 博客等级: 上将
  • 技术积分: 6205
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-06 10:13
文章分类
文章存档

2016年(2)

2015年(9)

2014年(8)

2013年(5)

2012年(8)

2011年(36)

2010年(34)

2009年(451)

2008年(47)

分类:

2009-08-22 13:31:45

bankapp的会话服务器

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;

}

4.集成到服务器中的应用

bankapp中用到了两个C语言的源程:

appint.c:包含应用程序定义版的tpsvrinit()tpsvrdown()过程,它们被包含到Tuxedo系统的main()中。缺省版的tpsvrinit()调用了两个函数:tpopen()userlog()tpopen()用于打开资源管理器,userlog()用于记录各类消息。帛省版的tpsvrdown()同样调用了两个函数:tpclose()userlog(),分别用于关闭资源管理器和记录关闭过程中的各类事件。你可以修改这两个过程,以完成各类初始化或应用程序结束时的收尾工作。

util.c:包含了一个叫getstr()的过程,bankapp中用它来SQL的错误消息。

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