SADP Module 5
SADP Module 5
SADP Module 5
Book must be
compiled using
the RMI compiler
by invoking the
command rmic as
below.
rmic Book
Passing of remote objects as references:
• When an exported remote object is
passed as a parameter or returned
from a remote method call, the stub
for that remote object is passed
instead of the object itself.
• The stub itself contains a reference to
the serialized object and implements
all of the remote interfaces that the
remote object implements.
• All calls to the remote interface go
through the stub to the remote
object.
• Parameters or return values that are not remote objects are passed by value.
• Any changes to the object’s state by the client are reflected only in the client’s
copy, not in the server’s instance.
• Similarly, if the server updates its instance, the changes are not reflected in the
client’s copy.
3. Creating the Server
• Before a remote object can be accessed, it must be instantiated and stored
in an object registry, so that clients can obtain its reference.
• Such a registry is provided in the form of the class java.rmi.Naming.
• The method bind is used to register an object and has the following
signature:
The client can invoke remote methods on the object. the BookInterface object
are called and displayed
2. Commands to place a hold, remove a hold, print transactions, and renew books
are available to members of the library (not superusers) from anywhere.
3.Certain commands are available only to superusers who log in from a library
terminal: these are for returning or deleting books, adding members and books,
processing holds, and saving data to and retrieving data from disk.
Add Book: State transition diagram for add book
• In the first case, the system already has the user’s member id, so that should
not be asked again.
• In the second case, the library staff member needs to input the member id to
the system followed by the book id.
• After receiving a book id, the system must attempt to check out the book.
Whether the operation is successful or not, the system enters the Book Id
Processed state.
State transition diagram for renewing books
2. Design and Implementation
To deploy the system on the web, we need the following:
1. Classes associated with the library, create classes such as Library, Member,
Book, Catalog, and so on.
2. Permanent data (created by the save command) that stores information
about the members, books, who borrowed what, holds, etc.
3. HTML files that support a GUI for displaying information on a browser and
collecting data entered by the user.
• For example, when a book is to be returned, a screen that asks for the
book id should pop up on the browser. This screen will have a prompt
to enter the book id, a space for typing in the same, and a button to
submit the data to the system.
4. A set of files that interface between the GUI and the objects that actually
do the processing. Servlets will be used to accomplish this task.
Structuring the files
HTML code for delivery to the browser can be generated in one of two ways:
1. Embed the HTML code in the servlets. This has the disadvantage of
making the servlets hard to read, but more dynamic code can be
produced.
2. Read the HTML files from disk as a string and send the string to the
browser. This is less flexible because the code remains static.
➢ Create a separate HTML file for every type of page that needs to be
displayed. For example, create a file for entering the id of the book to be
returned, a second file for displaying the result of returning the book, a
third file for inputting the id of the book to be removed, a fourth one for
displaying the result of removing the book, etc.
➢ Exploit the commonalities between the commands and create a number
of HTML code fragments, a subset of which can be assembled to form an
HTML file suitable for a specific context.
Examples of HTML file fragments
BMS Institute
BMS Institute of Technology
Technology and
andMgmt
Mgmt
Structure of servlets in the web-based library system
• A servlet receives data from a
browser through a
HttpServletRequest object.
• This involves parameter names
and their values, IP address of the
user, and so on.
• For example, when the form to
add book is filled and the Add
button is clicked, the servlet’s
doPost method is invoked.
• This method has two parameters:
a request parameter of type
HttpServletRequest and a
response parameter of type
HttpServletResponse.
• These methods and doPost and
doGet are collected into a class
named LibraryServlet.
BMS Institute of Technology and Mgmt
Most of the methods of LibraryServlet fall into one of five
categories:
1. One group contains methods that store information about the
user.
2. Methods to validate users and help assess access rights.
3. The getFile method reads an HTML file and returns its contents
as a String object.
4. The fourth group of methods are used for handling users who
may have invoked a command without actually logging in.
5. The final group of commands deal with processing the request
and responding to it. Refer page number 414