NonStop Server for Java (NSJ) Programmer's Guide (NSJ 2.0+)
// Register an instance of RemImpl.
Naming.rebind("My_Server", new RemImpl());
}
catch (Exception x) {
x.printStackTrace();
return;
}
}
public RemImpl() throws RemoteException {
super();
}
public void call() throws RemoteException {
System.out.println(getName());
System.out.println("Location: " +
System.getProperty("LOCATION"));
}
public String getString() throws RemoteException {
return new String("Hello from Server!");
}
public void sendString(String str) throws RemoteException {
System.out.println("Get client message :[" + str + "]");
}
public long doAdd(long l, int i) throws RemoteException {
return l + i;
}
public String getName() {
return "Remote operation: " + hashCode();
}
}
3. Create a client, OpTest.java, that uses the remote interface:
package rmi1;
import java.rmi.*;
import java.rmi.server.*;
public class OpTest {
public static void main(String[] args) {
System.setSecurityManager(new RMISecurityManager());
try {
RemOp ro = (RemOp) Naming.lookup("My_Server");
ro.call();
System.out.println("Get server message:["+ro.getString()+"]");
System.out.println("Sending string [client test] to server...");
ro.sendString("client test");
System.out.println("Calling server func doAdd(), send 5 and 3 ...");
System.out.println("the result is " + ro.doAdd(5, 3));
}
catch (Exception x) {