12.07.2015 Views

VisiBroker Edition

VisiBroker Edition

VisiBroker Edition

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

import org.omg.PortableServer.*;import java.util.*;public class AccountManagerImpl implements Bank.AccountManagerOperations {public AccountManagerImpl(POA poa) {_accountPOA = poa;}public synchronized Bank.Account open(String name) {// 在 帐 户 字 典 中 查 找 帐 户 。Bank.Account account = (Bank.Account) _accounts.get(name);// 如 果 字 典 中 没 有 帐 户 , 则 创 建 一 个 。if(account == null) {// 计 算 帐 户 余 额 ( 在 0 到 1000 元 之 间 )。float balance = Math.abs(_random.nextInt()) % 100000 / 100f;// 创 建 委 托 给 AccountImpl 实 例 的 帐 户 tieBank.AccountPOATie tie =new Bank.AccountPOATie(new AccountImpl(balance));try{// 在 默 认 POA 上 激 活 它 , 该 POA 是 该 服 务 对 象 的 根 POAaccount =Bank.AccountHelper.narrow(_accountPOA.servant_to_reference(tie));} catch (Exception e) {e.printStackTrace();}// 打 印 新 帐 户 。System.out.println("Created " + name + "'s account:" + account);// 将 帐 户 存 储 在 帐 户 字 典 中 。_accounts.put(name, account);}// 返 回 帐 户 。return account;}private Dictionary _accounts = new Hashtable();private Random _random = new Random();private POA _accountPOA = null;}实 例 程 序对 Account 类 所 作 的 更 改Java:对 Account 类 所 作 的 更 改 ( 与 Bank 实 例 相 比 ) 是 它 不 再 扩 展 Bank.AccountPOA。// Server.javapublic class AccountImpl implements Bank.AccountOperations {public AccountImpl(float balance) {_balance = balance;}public float balance() {return _balance;}private float _balance;}使 用 tie 机 制 9-5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!