The Java Program: rmi2/ActionTest.java
1 package rmi2;
2
3 import java.rmi.*;
4 import java.rmi.server.*;
5
6 // ActionTest creates two objects that implement the Action
7 // interface. One is a remote object of type ClientActionImpl.
8 // The other is a non-remote object of type ServerAction.
9 // When the ClientActionImpl instance is passed to a
10 // RemoteCaller, its execute() method will run in the same
11 // process as the ActionTest main() method. When the
12 // ServerAction instance is passed, its execute() method
13 // will run in the same process as the RemoteCaller call
14 // method.
15
16 public class ActionTest {
17 public static void main(String[] args) {
18 System.setSecurityManager(new RMISecurityManager());
19
20 try {
21
22 // Create a new remote action object.
23
24 ClientActionImpl cai = new ClientActionImpl();
25
26 // Create a new non-remote action object.
27
28 ServerAction sa = new ServerAction();
29
30 // Find an instance of RemoteCaller in the local
31 // registry.
32
33 RemoteCaller rc =
34 (RemoteCaller)Naming.lookup("caller");
35
36 // Pass the remote action object to the remote caller.
37
38 rc.call(cai);
39
40 // Pass the non-remote action object to the remote
41 // caller.
42
43 rc.call(sa);
44
45 } catch (Exception x) {
46 x.printStackTrace();
47 System.exit(-1);
48 }
49 }
50 }
51