


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



reference: Dave Hollinger Wenyuan Xu
Department of Computer Science and Engineering University of South Carolina
Netprog: Java RMI^2
Not concerned with the details of the actual communication between processes โ everything is just method calls.
Netprog: Java RMI^3
ย Method Call Semantics โ what does it mean to make a call to a method?
How many times is the method run?
How do we know the method ran at all?
ย RMI does a great job of providing natural call semantics for remote objects/methods.
Simply a few additional Exceptions that you need to
Netprog: Java RMI^4
ย It would be awkward if we needed to include a hostname, port and protocol with every remote method invocation. ย RMI provides a Naming Service through the RMI Registry that simplifies how programs specify the location of remote objects.
This naming service is a JDK utility called
Server App. Skeleton Remote Reference Transport
Client App. Stubs Remote Reference Transport
ย The client acquires a reference to a remote object.
This part is different from creating a local object.
ย The client calls methods on the remote object
No (syntactic) difference!
Just need to worry about a few new exceptions.
Netprog: Java RMI^7
Netprog: Java RMI^8
Netprog: Java RMI^9
end result is very similar to multiple inheritence.
Netprog: Java RMI^10
public interface Shape { public getArea(); public draw(); public fill(Color c); }
ย Create an interface the extends the java.rmi.Remote interface.
This new interface includes all the public methods
import java.rmi.*; public interface MyRemote extends Remote { public int foo(int x) throws RemoteException; public String blah(int y) throws RemoteException;
... }
Netprog: Java RMI^19
ย Naming.lookup() method takes a string parameter that holds a URL indicating the remote object to lookup. rmi://hostname/objectname
ย Naming.lookup() returns an Object!
ย Naming.lookup() can throw
RemoteException
MalformedURLException
Netprog: Java RMI^20
try { Object o = Naming.lookup(โrmi://localhost/ReMathโ);
MyRemote r = (MyRemote) o; //... Use r like any other Java object! } catch (RemoteException re) {
... } catch (MalformedURLException up) { throw up; }
RemoteMathImpl: remote integer arithmetic