Download CS3283 - CityU CS

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Team Foundation Server wikipedia , lookup

Dependency injection wikipedia , lookup

Java (programming language) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Java performance wikipedia , lookup

Java ConcurrentMap wikipedia , lookup

Transcript
CS4273
Distributed System Technologies and Programming I
Tutorial on RMI (remote method invocation)
1. a) Discuss the advantages of using RMI;
answer: RMI eases programmers work by automatically generating stub / skeleton
programs for communication between clients and the server.
b) Describe the client-server binding method in RMI.
Answer: 1) you need to run “rmiregistry” software at the server site;
2) server will register itself to the rmiregistry when the server starts;
3) client always looks up the “rmiregistry” for a reference to the server.
2. List the program files (both client & server programs) involved in designing a
banking system using RMI. Suppose the interface file is “Bank.java”. The interface
has two methods, balance(int accnt) and transfer(int from_accnt, to_accnt, amnt).
a) Write the interface, Bank.java.
Answer:
Bank.java
public interface Bank extends Remote {
int balance (int accnt) throws RemoteException;
void transfer (int from_accnt, to_accnt, amnt) throws RemoteException;
}
b) Describe the steps of compiling the client & server programs.
Answer:
At server side:
 javac BankImpl.java
 javac BankSvr.java
At client side:
 javac BankClnt.java
c) How do you run them?
Answer:
At server side:
 rmiregistry &
 java BankSvr
At client side:
 java BankClnt
3. The client program of “UpperCase” demo-ed during lecture time is given below.
a) Change the client to a Java Applet. Suppose the web server is on “sus12.cs”.
b) What changes you need to make to the server program?
c) List the steps to run the above applet and the server.
public class UpperCaseClient {
public static void main(String[] args) {
String url = "rmi://ue3k1.cs.cityu.edu.hk/";
try {
UpperCase upper = (UpperCase)Naming.lookup(url+"upper_case");
for (int i = 0; i < args.length; i++)
// for each string given in cmd line as params
System.out.println(upper.toUpper(args[i]));
} catch (Exception e) { System.exit(-1); }
}
}
Answer:
a) you only need to change the url address of the server to the web-server address:
String url = "rmi://sus12.cs.cityu.edu.hk/";
b) no change is needed.
c) Steps of running the server is the same as question 2c.
Steps of running the client is to use an “html” file to embed the applet, and then
use browser to run the applet.