The Java Program: rmi2/RemoteCallerImpl.java
1 package rmi2;
2
3 import java.rmi.*;
4 import java.rmi.server.*;
5
6 // The RemoteCallerImpl class implements the RemoteCaller
7 // interface. An instance of RemoteCallerImpl is registered
8 // with the registry on the local host under the name "caller"
9 // when main() is invoked.
10
11 public class RemoteCallerImpl extends UnicastRemoteObject
12 implements RemoteCaller {
13
14 // Register an instance of RemoteCallerImpl with the
15 // local registry under the name "caller".
16
17 public static void main(String[] args) {
18 System.setSecurityManager(new RMISecurityManager());
19
20 try {
21 Naming.rebind("caller", new RemoteCallerImpl());
22 } catch (Exception x) {
23 x.printStackTrace();
24 return;
25 }
26 }
27
28 // All remote implementation classes must have a
29 // zero-argument constructor that declares itself
30 // capable of throwing RemoteException.
31
32 public RemoteCallerImpl() throws RemoteException {
33 }
34
35 // Return the unique name of a RemoteCallerImpl.
36
37 public String getName() throws RemoteException {
38 return "Remote operation: " + this;
39 }
40
41 // Invoke execute() on the Action object passed as
42 // an argument.
43
44 public void call(Action a) throws RemoteException {
45 a.execute(this);
46 }
47 }
48
49
50