OOPortal OOPortal


Mapping Clients  «Prev  Next»

Delegation based implementation - Exercise

Course project: Use the delegation (TIE) approach to implement a server


Objective:Code a server that accesses the BookStore interface.

Exercise scoring


You will receive 10 points for this exercise. This exercise is auto-scored; when you have completed the exercise, click the Submit button to receive full credit.

Background/overview

Previously, you wrote a client that interacts with two back-end servers to get book and price information. These servers are not meant for client access, however. In this exercise, you will implement the BookStore interface. This server will act just like your previous client in collecting information from the BookStoreInv and Pricer objects. This server will use the back-end servers to provide an interface for client access.
The lookUpBookPrice() method takes in a book title. If the book doesn’t exist in the BookStoreInv server, then the method returns false. Otherwise, it fills in the out parameters with the inventory and pricing information from the BookStoreInv and Pricer servers.
The buyBook() method takes a book title and the current amount of the buyer’s credit account. It makes sure the book is in stock and prices the book. If the book is not in stock or there is not enough money in the account, the method returns false. Otherwise, it removes a copy from BookStoreInv, subtracts the cost from the client credit, and returns the new amount through the inout parameter.

module BookShopModule {
 interface BookStoreInv {
  readonly attribute long totalBooksInStock;
  long getNumCopiesOfBook(in string title);
  boolean isBookInStock(in string title);
  boolean removeCopy(in string title);
 };
 interface Pricer {
  float priceBook(in string title);
  boolean isBookOnSale(in string title,out float percentage);
 };
 
 interface BookStore { 
 boolean lookUpBookPrice(in string title,
out float price,
out long numcopies,
out float discount);
  boolean buyBook(in string title,
inout float currentCredit); 
 }
};

Your job is to create a class that implements the BookStore interface.
The two servers for the new IDL have been implemented for you. The servers will place references into the Naming Service upon startup. You are also given a shell of the client application that calls the Naming Service and gets references to the two server objects you will need.

Download files

First, download the Module3ExerciseA.zip file, and then unzip it into a work directory. It should create two subdirectories: an exercise directory and a solution subdirectory
Edit the env.bat file to reflect your local work directory.

Instructions

  1. Modify the bookStore.BookStoreImpl class.

a) Change the declaration to implement the BookShopModule.BookStoreOperations interface.
i) Leave the predefined constructor as is.
b) Implement the lookUpBookPrice() operation.
i) Use the inventory and pricer instance variables to call the appropriate methods.
c) Implement the buyBook() operation.
i) Use the inventory and pricer instance variables to call the appropriate methods.
  1. Modify the bookStore.Server class.

a) Modify the init method.
i) Create an instance of the bookStore.BookStoreImpl class, passing the inventory and pricer in the constructor for the object.
ii) Create an instance of the BookShopModule.POA_BookStore_tie class, passing the instance of the imple class created in (i) to the constructor for the tie.
  1. Run the IDL compiler on the exer3.idl file.
  2. Compile the classes.
  3. Then run:
    > java client.Client 2001
    on the command line to execute the client, which will try to buy the book 2001.

Hints


If you get stuck, you can run the IDL compiler on exer1.idl and look at the generated classes BookShopModule.BookStoreInv and BookShopModule.Pricer to see the method signatures for all the operations.

Completing the exercise


When you have completed the exercise, click the Submit button.