1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.newsclub.net.unix.demo.rmi;
19
20 import java.io.IOException;
21 import java.rmi.NotBoundException;
22 import java.rmi.registry.Registry;
23 import java.rmi.server.RemoteObject;
24
25 import org.newsclub.net.unix.demo.rmi.services.HelloWorld;
26 import org.newsclub.net.unix.demo.rmi.services.World;
27 import org.newsclub.net.unix.rmi.AFUNIXNaming;
28 import org.newsclub.net.unix.rmi.RemotePeerInfo;
29
30
31
32
33
34
35
36 @SuppressWarnings("CatchAndPrintStackTrace" )
37 public final class SimpleRMIClientActingAsServer {
38 public static void main(String[] args) throws IOException, NotBoundException {
39 AFUNIXNaming naming = AFUNIXNaming.getInstance();
40
41 System.out.println("Locating registry...");
42 final Registry registry = naming.getRegistry();
43 System.out.println(registry);
44 System.out.println();
45 HelloWorld obj = (HelloWorld) registry.lookup("helloWorld");
46 System.out.println("HelloWorld instance:");
47 System.out.println(" " + obj);
48 System.out.println(" " + RemotePeerInfo.remotePeerCredentials(obj));
49 System.out.println();
50
51 World world = new WorldImpl("everybody");
52 naming.exportAndRebind("world", world);
53 System.out.println("Exporting our own World instance:");
54 System.out.println(" " + RemoteObject.toStub(world));
55 System.out.println(" " + RemotePeerInfo.remotePeerCredentials(world));
56 System.out.println();
57
58 System.out.println("Calling HelloWorld...");
59 System.out.println(obj.hello() + " " + obj.world() + "!");
60
61
62
63
64
65
66 naming.unexportAndUnbind("world", world);
67
68
69
70
71
72
73
74
75 }
76 }