Beruflich Dokumente
Kultur Dokumente
2
Netprog: Java RMI
3 4
Netprog: Java RMI Netprog: Java RMI
Stubs Skeleton
The client calls methods on the remote object
Remote Reference Remote Reference
No (syntactic) difference!
Transport Transport
Just need to worry about a few new exceptions.
5 6
Netprog: Java RMI Netprog: Java RMI
Overview of RMI Programming Java Interfaces
Similar to Class
Define an interface that declares the methods that No implementation! All methods are
will be available remotely. abstract (virtual for C++ folks).
The server program must include a class that
implements this interface. Everything is public.
The server program must create a remote object and No fields defined, just Methods.
register it with the naming service. No constructor
an Interface is an API that can be
The client program creates a remote object by asking
the naming service for an object reference. implemented by a Class.
7 8
Netprog: Java RMI Netprog: Java RMI
9 10
Netprog: Java RMI Netprog: Java RMI
provides methods
Create a class that implements the
extends extends
needed by
interface.
Your Interface UnicastRemoteObject
The class should also extend
UnicastRemoteObject*
implements
extends This class needs a constructor that throws
RemoteException !
Class for your Remote
Object This class is now used by rmic to create
the stub and skeleton code.
*It doesn’t have to extend UnicastRemoteObject, there is another way…
13 14
Netprog: Java RMI Netprog: Java RMI
17 18
Netprog: Java RMI Netprog: Java RMI
Using The Naming service Getting a Remote Object
Naming.lookup() method takes a string try {
parameter that holds a URL indicating the Object o =
remote object to lookup. Naming.lookup(“rmi://localhost/ReMath”);
rmi://hostname/objectname
MyRemote r = (MyRemote) o;
// . . . Use r like any other Java object!
Naming.lookup() returns an Object!
} catch (RemoteException re) {
Naming.lookup() can throw . . .
RemoteException } catch (MalformedURLException up) {
MalformedURLException throw up;
}
19 20
Netprog: Java RMI Netprog: Java RMI
21 22
Netprog: Java RMI Netprog: Java RMI