Содержание
- 2. Remote Method Invocation Client Server Client Remote Object Interface Stub Skeleton Remote Object Interface Remote Object
- 3. Interfaces (Transparency) To client, remote object looks exactly like a local object (except that you must
- 4. RMI Registry RMI needs a port mapper too: servers can register contact address information clients can
- 5. Example Simple program: write interface for remote object: Remote.java implementation of object: RemoteImpl.java server to run
- 6. Example Step 1: write interface Calculator.java import java.rmi.Remote; import java.rmi.RemoteException; public interface Calculator extends Remote {
- 7. Example Step 2: write remote object CalculatorImpl.java import java.rmi.server.UnicastRemoteObject; import java.rmi.RemoteException; public class CalculatorImpl extends UnicastRemoteObject
- 8. Example Implementation class must respect a few constraints: must implement the interface (of course) must inherit
- 9. Example Step 3: generate stub and skeleton RMI compiler: $ rmic CalculatorImpl Generates CalculatorImpl_Stub.class and CalculatorImpl_Skel.class
- 10. Example Step 4: write server CalculatorServer.java import java.rmi.Naming; public class CalculatorServer { public CalculatorServer() { try
- 11. Example Server program creates CalculatorImpl object. Registers object to local RMI registry (‘rebind()’): rebind(String name, Remote
- 12. Example Step 5: write CalculatorClient.java import java.net.MalformedURLException; public class CalculatorClient { public static void main(String[] args)
- 13. Example Before invoking the server, the client must ‘lookup’ the registry: must provide the URL for
- 14. Example Step 6: test it! Start the RMI registry: rmiregistry registry must have access to your
- 15. Using RMI in a Distributed Context First, test your program on a single host. To use
- 17. Скачать презентацию