Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 Design Documentation - CORBA Auction Server - Phase III 1. Description 2. Application Specification - IDL Specification ( Auction.IDL and Bank.IDL) - Auction Server and Bank Server Class Diagrams - Compiling the IDL Specification 3. Implementing Objects 4. Building Server - Initializing the ORB - Creating and Activating a Servant 5. Building Client - Login Panel - Bank Panel - Auction Panel 6. 1. 2. Installation and Operation Instructions - Before the Deployment - Deploying the Application Description - Auction Server with Support for Financial Transactions. Phase 3 Description Note: The "group" deliverables for Phase 3 are the design documents (class diagrams, description of your GUI, documented IDL files), complete and fully documented source code, complete set of class files packaged into client and server components, and installation instructions (for the purpose of testing). Your group should also submit a one page document containing the detailed task breakdown among group members for the project. These items should be submitted by email as a compressed archive. Application Specification The Auction server system allows the buying and selling of individual items, using an English auction protocol (increasing proce, current price visible to all parties). In the previous phases, the “object factory” technique that generates new auctions and returns remote references to clients was implemented. The dynamic user interfaces were deployed as Java applets. The multiple simultaneous auctions are involved with providing each user with an integrated seller’s and bidder’s interface. By using the callback technique , the bidder will be notified in a timely manner when a bidder’s bid is topped by another bidder, or when the seller sells the item. In this final phase, we extended the multiple-auction server of previous phase with a Bank server. Banks have accounts, and accounts have balances. When users bid in an auction, the user must have enough money in his account to cover the bid. If someone tops this user’s bid, the user then have additional uncommitted money available to support more bids. When an item is sold, the money is transferred from buyer’s account 1 DS520 Project Phase 3 J.Qiu – [email protected] Design Documentation M.Wan – [email protected] Group 4 S.Gu – [email protected] to the seller’s account automatically. Deposits may be made at any time, while withdrawals must not exceed the “uncommitted” balance. The following key decisions were made during the design: Using Visibroker and its Gatekeeper. VBJ4.5 with Portable Object Adapter(POA) and JDK1.2.2 are used as development environment. The server will kick out user automatically after 10 minutes idle. Separate bank and auction services. It is possible to run the bank and auction services on different platforms in separate file systems. Users must establish accounts in the Bank before registering for the Auction. Using JDBC to provide a persistent storage on the server-side, including bank account, auctions, and all the user’s information (Id, password). Using “session id” as online user’s input identification instead of the “user name”. Therefore the security of the system is improved. Multiple active auctions hosted in the server., each with one seller and potentially many bidders. A given user may be playing seller and bidder roles in separate auctions. The single applet client supports both bidder and seller interfaces. Changes in auction status should be delivered to the user interface in a reasonably timely fashion without the need for user initiative. 2.1 IDL Specification The IDL specification of the Auction system is contained three interfaces specification: Auction, Callback and AuctionManager. AUCTION.IDL: CORBA IDL Definition of the Auction Interface. module AuctionModule{ interface Auction{ exception DoAuctionException {string explanation;}; /** * bid this auction. * @param sid The online user session Id identifies an online user. * @param price The price that the bidder wants to bid. */ void bid(in long sid, in float price) raises (DoAuctionException); /** * Sell this auction. * @param sid The online user session Id identifies an online user. */ void sell(in long sid) raises (DoAuctionException); /** * Offer a new auction. * @param sid The online user session Id identifies an online user. * @param item The item description. * @param price The price that the seller wants to sell. */ void offer(in long sid, in string itemDesc, in float price) raises (DoAuctionException); 2 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 /** * Check if the user is seller. * @param sid The online user session Id identifies an online user. * @return True if he/she is seller. */ boolean isSeller(in long sid) raises (DoAuctionException); /** * Get the name of the bidder only if the requester is the seller or the highest bidder. * @param sid The online user session Id identifies an online user. * @return The name of the bidder if this user have enough rights. Return null if * he does not have enough rights. */ string getBidder(in long sid) raises (DoAuctionException); /** * check if the auction is active. * @return true if it is active, false if it is not active. */ boolean isActive(); /** * Get the item description of the auction. * @return Item description for this auction. */ string getItemDesc() raises (DoAuctionException); /** * Get the price of the auction. * @return price for this auction. */ float getPrice() raises (DoAuctionException); /** * @return The ID of the auction. */ string getAuctionId() raises (DoAuctionException); //This method is used to insert or update information to //the account table of the database. void newAuction(); // }; interface Callback{ /** * The callback method that is called by the server. * @param msg The message that the server send to the client. */ oneway void sendMessage(in string msg); }; interface AuctionManager{ exception AuctionFailureException {string explanation;}; /** * The array of the Auctions. */ typedef sequence <Auction> AuctionSeq; /** * @return A new auction remote pointer that created by the manager server. 3 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 */ Auction createAuction() raises (AuctionFailureException); /** * @param sid The session id of the online user. * @return The Auction[] array that the user is not the seller. */ AuctionSeq getAllItems(in long sid) raises (AuctionFailureException); /** * @param sid The session id of the online user. * @return The Auction[] array that the user is the seller. */ AuctionSeq getSellItems(in long sid) raises (AuctionFailureException); /** * @param auctionId The auction id of the auction. * @return The Auction remote pointer. */ Auction getAuction(in string auctionId); void restoreAuctions(); /** * Register a new user, and open a bank account for him/her. * @param userId The user Id that the user want to use. * @param password The password the user ant to use. * @return True if succeed. False if fail. */ boolean register(in string userId, in string password) raises (AuctionFailureException); /** * Login the server. * @param userId The online user Id. * @param password The password of the user. * @param cbRef The callback reference. * @return The online session Id, it is a integer generated by userManager. * It is the unique identification for this online user. It will be invalid if the * user logout or be kicked out by the system. */ long login(in string userId, in string password, in Callback callback) raises (AuctionFailureException); /** * Logout the server. * @param sid Unique online user session Id assigned by the userManager when it logged in. * @return True if succeeds, false if fails. */ boolean logout(in long sid); }; }; The separated IDL specification of the Bank system is contained two interfaces specification: Account and AccountManager. BANK.IDL: CORBA IDL Definition of the Auction Interface. module BankModule{ interface Account{ exception AccountFailureException {string explanation;}; /** * * Get the current balance fromt this account. @return The amount of current pure balance. 4 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 */ float currentBalance(); /** * Get the commit balance fromt this account. * @return The amount of commit balance. */ float commitBalance(); /** * Withdraw the amount from this account. * @param amount The amount of the transaction. */ void withdraw(in float amount) raises (AccountFailureException); /** * Deposit the amount to this account. * @param amount The amount of the transaction. */ void deposit(in float amount) raises (AccountFailureException); /** * Increase the commit balance. It was called when the owner "bid". * @param amount The amount of the transaction. */ void produceCommit(in float amount) raises (AccountFailureException); /** * Decrease the commit balance. It was called when the seller "sell" the item to the owner * or was high bidden by the other user. * @param amount The amount of the transaction. */ void consumeCommit(in float amount) raises (AccountFailureException); /** * If the owner of this account is in the table, get the balance out; * if it is not in the table, put it into the table. */ void createAccount(); }; /** * AccountManager is used to manage all the accounts. */ interface AccountManager{ exception BankFailureException {string explanation;}; /** * Open a new account for the user. * @param userId The idenfication of the user. */ void open(in string userId) raises (BankFailureException); /** * Return the account to the user. * @param userId The idenfication of the user. * @return The account remote pointer to the user. */ Account getAccount(in string userId) raises (BankFailureException); }; }; 5 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 2.2 Auction Server Class Diagrams The class diagrams for Auction Server and Bank Server are illustrated in the next page. 6 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 Class Diagrams Interface Implement _AuctionStub AuctionPOA Auction Extends * AuctionImpl Interface Implement _AuctionManagerStub has AuctionManagerPOA AuctionManager Extends 1 has UserManagerFactory has UserManagerFactoryImpl AuctionManagerImpl UserManager UserManagerFactoryImpl has (Online) UserInfo has UserFactory UserDB UserInfoImpl JDBC AuctionClient has ClientLogic has has Callback 7 UserFactoryImpl J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 Class Diagrams - cont. Bank Server: Interface Implement _AccountStub AccountPOA JDBC Account Extends AccountImpl AccountDB 1 Create Interface Implement _AccountManagerStub AccountManagerPOA AccountManager Extends Create AccountManagerImpl 2.3 Compiling the IDL Specification When we compile the IDL specification with IDL compiler – VisiBroker4.5, the compiler generates different Java interfaces and classes depending on the compiler flags chosen. When compiler Auction.idl, it generates a Java package called AuctionModule that contains several Java classes and three Java interface: Client side used classes: _AuctionStub.java - Client Stub AuctionHelper.java AuctionHolder.java _AuctionManagerStub. java - Client Stub AuctionManagerHelper.java AuctionManagerHolder.java _CallbackStub. java - Client Stub CallbackPOA.java Callback.java CallbackHelper.java 8 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 CallbackHolder.java Server side used classes: AuctionPOA.java – Implementation Skeleton Auction.java AuctionHelper.java AuctionHolder.java AuctionManagerPOA.java – Implementation Skeleton AuctionManager.java AuctionManagerHelper.java AuctionManagerHolder.java User object are created at run time by a UserManager Factory, which is specified in the interface UserManagerFactory. Additionally, there are classes for the exceptions are defined within the IDL that are in the Java package AuctionModule. When compiler Bank.idl, it generates a Java package called BankModule that contains several Java classes and three Java interface: Client side used classes: _AccountStub.java - Client Stub AccountHelper.java AccountHolder.java _AccountManagerStub. java - Client Stub AccountManagerHelper.java AccountManagerHolder.java _CallbackStub. java - Client Stub CallbackPOA.java Callback.java CallbackHelper.java CallbackHolder.java Server side used classes: AccountPOA.java – Implementation Skeleton Account.java AccountHelper.java AccountHolder.java AccountManagerPOA.java – Implementation Skeleton AccountManager.java AccountManagerHelper.java AccountManagerHolder.java Additionally, there are classes for the exceptions are defined within the IDL that are in the Java package BankModule . 9 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 3. Implementing Objects Every CORBA server must have some kind of main program that initializes the ORB environment and start objects. The class called Server was created to implement this main function. In addition, the server must provide implementation of the CORBA interfaces that are defined in the IDL. There are six interfaces to be implemented: AuctionModule.Auction AuctionModule.AuctionManager AuctionModule.Callback, BankModule.Account BankModule.AccountManager BankModule.Callback . The following classes are created to implemented above interfaces by extending the generated POA skeleton AuctionImpl AuctionManagerImpl AccountImpl AccountManagerImpl CallbackImpl Additionally, UserManagerFactory interface implemented UserMangerFactoryImpl class and UserManager interface implemented UserManagerImpl class. 4. Building Server To instantiated the object implementations and to make them available to the clients , we have to implement a sever. The Server is a class that provides the main function on the server side. The main program should do 1) initialize the ORB, 2) create auctionPOA with the right policies 3) create the servant 4) activate the servant with the ID on my POA 5) activate the POA manager 6) wait for incoming requests. AuctionServer: The Main Server for Auction // Server.java import java.io.FileInputStream; import java.util.Properties; import org.omg.CORBA.*; import org.omg.PortableServer.*; public class Server { public static void main(String[] args){ try { // Initialize the ORB. ORB orb = ORB.init(args, null); // get a reference to the root POA POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); Policy[] policies = new org.omg.CORBA.Policy[] { rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT) }; // Create bankPOA with the right policies, this POA is used for registering AocountManager POA auctionManagerPOA = rootPOA.create_POA("manager_agent_poa", rootPOA.the_POAManager(), policies); policies = new org.omg.CORBA.Policy[] { rootPOA.create_lifespan_policy(LifespanPolicyValue.TRANSIENT) }; // Create accountPOA with the right policies, this POA is used for registering Account POA auctionPOA = rootPOA.create_POA("auction_agent_poa", rootPOA.the_POAManager(), policies); 10 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 // Create the servant AuctionManagerImpl managerServant = new AuctionManagerImpl(); // Activate the servant with the ID on myPOA byte[] managerId = "AuctionManager".getBytes(); auctionManagerPOA.activate_object_with_id(managerId, managerServant); // Activate the POA manager rootPOA.the_POAManager().activate(); System.out.println("Auction Server is ready."); // Wait for incoming requests orb.run(); } catch (Exception e) { e.printStackTrace(); } } } Bank Server: The Main Server for Bank // Server.java import java.io.FileInputStream; import java.util.Properties; import import import import import org.omg.CORBA.*; org.omg.PortableServer.*; Bank.*; Bank.AccountManagerPackage.*; Bank.AccountPackage.*; public class Server { public static void main(String[] args){ try { // Initialize the ORB. ORB orb = ORB.init(args, null); // Get the manager Id byte[] managerId = "WanBankManager".getBytes(); // Locate an account manager. AccountManager manager = Bank.AccountManagerHelper.bind(orb, "/bank_agent_poa", managerId); // get a reference to the root POA POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); Policy[] policies = new org.omg.CORBA.Policy[] { rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT) }; // Create bankPOA with the right policies, this POA is used for registering AocountManager POA auctionManagerPOA = rootPOA.create_POA("manager_agent_poa", rootPOA.the_POAManager(), policies); policies = new org.omg.CORBA.Policy[] { rootPOA.create_lifespan_policy(LifespanPolicyValue.TRANSIENT) }; // Create accountPOA with the right policies, this POA is used for registering Account POA auctionPOA = rootPOA.create_POA("auction_agent_poa", rootPOA.the_POAManager(), policies); // Create the servant AuctionManagerImpl managerServant = new AuctionManagerImpl(manager); // Activate the servant with the ID on myPOA managerId = "AuctionManager".getBytes(); auctionManagerPOA.activate_object_with_id(managerId, managerServant); // Activate the POA manager rootPOA.the_POAManager().activate(); System.out.println("Auction Server is ready."); managerServant.restoreAuctions(); // Wait for incoming requests orb.run(); } catch (Exception e) { e.printStackTrace(); } } } 11 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 5. Building Client The client interfaces were divided into three panels: Login Panel, Bank Panel and Auction Panel. The Login Panel using the applet to do the registration. Login names are required to be unique; they will be the identifiers that associate Sellers and Bidders with Auctions. Users may be either logged in or logged out. When logged in, their displays will be automatically updated. The Bank Panel provides the interface for user working with bank account. The Auction Panel provides the auction interface and supporting both bidder and seller interfaces. The client interface diagrams are illustrated in the below. Login Panel: 12 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 Bank Panel: 13 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 Auction Panel: 14 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 6. Installation and Operation Instructions Visibroke for Java 4.5 and JDK1.2.2 are used as development and deployment environment. Client and Server shall be deployed on two different machines. Before the deployment: 1. Set Path variable PATH=%PATH%; c:\jdk1.2.2\bin; c:\inprise\vbroker\bin; 2. Set the CLASSPATH variable SET CLASSPATH=%CLASSPATH%; .; c:\jdk1.2.2\lib\classes.zip; c:\jdk1.2.2\lib\servlet.jar; c:\inprise\vbroker\lib\vbdev.jar; c:\inprise\vbroker\lib\vbjdev.jar; c:\inprise\vbroker\lib\vbjorb.jar; c:\inprise\vbroker\lib\vbjmigration.jar; 3. Also add the directories in which the class files for the Auction and Bank applications will reside. 4. Pre-compile the .idl file > idl2java Auction.idl > idl2java Bank.idl 5. Compile the .java files At the Auction application side: vbjc –d c:\classes AuctionImpl.java vbjc –d c:\classes AuctionManagerImpl.java vbjc –d c:\classes CallbackImpl.java vbjc –d c:\classes AuctionDB.java vbjc –d c:\classes Server.java vbjc –d c:\classes AuctionClient.java vbjc –d c:\classes ClientLogic.java vbjc –d c:\classes ClientTest.java At the Bank application side: vbjc –d c:\classes AccountImpl.java vbjc –d c:\classes AcoountManagerImpl.java vbjc –d c:\classes CallbackImpl.java vbjc –d c:\classes AccountServer.java vbjc –d c:\classes AccountDB.java vbjc –d c:\classes AuctionClient.java vbjc –d c:\classes AccountClient.java vbjc –d c:\classes ClientLogic.java vbjc –d c:\classes ClientTest.java After this step, c:\classes will contain the class files . 15 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 Deploying the application on client and server machines 1. Copy .class files to client and server machines On the Client Side: C:\Client\AuctionClient.html C:\Client\AuctionClient.class C:\Client\ClientLogic.class C:\Client\CallbackImpl.class C:\AuctionModule\_AuctionManagerStub.class C:\AuctionModule\_AuctionStub.class C:\AuctionModule\_CallbackStub.class C:\AuctionModule\Auction.class C:\AuctionModule\AuctionHelper.class C:\AuctionModule\AuctionHolder.class C:\AuctionModule\AuctionManager.class C:\AuctionModule\AuctionManagerHelper.class C:\AuctionModule\AuctionManagerHolder.class C:\AuctionModule\AuctionManagerOperations.class C:\AuctionModule\AuctionManagerPOA.class C:\AuctionModule\AuctionOperations.class C:\AuctionModule\AuctionPOA.class C:\AuctionModule\AuctionPOATie.class C:\AuctionModule\Callback.class C:\AuctionModule\CallbackHelper.class C:\AuctionModule\CallbackHolder.class C:\AuctionModule\CallbackOperations.class C:\AuctionModule\CallbackPOA.class C:\AuctionModule\AuctionPackage\DoAuctionException.class C:\AuctionModule\AuctionPackage\DoAuctionException Helper.class C:\AuctionModule\AuctionPackage\DoAuctionException Holder.class C:\AuctionModule\AuctionManagerPackage\AuctionFailureException.class C:\AuctionModule\AuctionManagerPackage\AuctionFailureExceptionHelper.class C:\AuctionModule\AuctionManagerPackage\AuctionFailureExceptionHolder.class C:\AuctionModule\AuctionManagerPackage\AuctionSeqHelper.class C:\AuctionModule\AuctionManagerPackage\AuctionSeqHolder.class C:\BankModule\_AccountManagerStub.class C:\BankModule\_AccountStub.class C:\BankModule\Account.class C:\BankModule\AccountHelper.class C:\BankModule\AccountHolder.class C:\BankModule\AccountManager.class C:\BankModule\AccountManagerHelper.class C:\BankModule\AccountManagerHolder.class C:\BankModule\AccountManagerOperations.class C:\BankModule\AccountManagerPOA.class C:\Client\BankModule\AccountOperations.class 16 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 C:\BankModule\AccountPOA.class C:\BankModule\AccountPackage\AccountFailureException.class C:\BankModule\AccountPackage\AccountFailureExceptionHelper.class C:\BankModule\AccountPackage\AccountFailureExceptionHolder.class C:\BankModule\AccountManagerPackage\BankFailureException.class C:\BankModule\AccountManagerPackage\BankFailureExceptionHelper.class C:\BankModule\AccountManagerPackage\BankFailureExceptionHolder.class On the Server Side of Auction Application: C:\AuctionServer\AuctionImpl.class C:\AuctionServer\AuctionManagerImpl.class C:\AuctionServer\AuctionServer.class C:\AuctionServer\AuctionModule\Auction.class C:\AuctionServer\AuctionModule\AuctionManager.class C:\AuctionServer\AuctionModule\AuctionManagerOperations.class C:\AuctionServer\AuctionModule\AuctionManagerPOA.class C:\AuctionServer\AuctionModule\AuctionManagerPOATie.class C:\AuctionServer\AuctionModule\AuctionOperations.class C:\AuctionServer\AuctionModule\AuctionPOA.class C:\AuctionServer\AuctionModule\AuctionPOATie.class C:\BankServer\AccountImpl.class C:\BankServer\AccountManagerImpl.class C:\BankServer\AccounServer.class C:\BankModule\Account.class C:\BankModule\AccountManager.class C:\BankModule\AccountManagerOperations.class C:\BankModule\AccountManagerPOA.class C:\ankModule\AccountManagerPOATie.class C:\BankModule\AccountOperations.class C:\BankModule\AccountPOA.class C:\BankModule\AccountPOATie.class C:\usermanager\UserDB.class C:\usermanager\UserDBFactory.class C:\usermanager\UserDBFactoryImpl.class C:\usermanager\UserDBImpl.class C:\usermanager\UserInfo.class C:\usermanager\UserInfoFactory.class C:\usermanager\UserInfoFactoryImpl.class C:\usermanager\UseInfoImpl.class C:\usermanager\UserManager.class C:\usermanager\UserManagerFactory.class C:\usermanager\UserManagerImpl$1.class C:\usermanager\UserManagerImpl.class 2. On the server: First start the Visibroker SmartAgent > osagent –c 17 J.Qiu – [email protected] M.Wan – [email protected] S.Gu – [email protected] DS520 Project Phase 3 Design Documentation Group 4 To run the bank Server > start vbj bankserver.AccountServer To run the Auction Server > start vbj auctionServer.AuctionServer Start Gatekeeper > gatekeeper 3. On the client: Be sure to set the PATH and CLASSPATH variables correctly Run the Application > start appletviewer AuctionClient.html 18