public String frob(ClientOp o) throws RemoteException {
int localCalls;
ClientOp ci = (ClientOp)o;
String
request = ci.getString();
String
selfName = Thread.currentThread().getName();
String
reply;
synchronized (this) {
localCalls = nCalls++;
}
if (Server.DEBUG) {
System.out.println("Server[" + selfName +
"]\t Starting:  '" + request + "'");
}
InterruptibleThread.sleep(Server.serverDelay);
reply = "[Server" + selfName + "] Reply: " +
localCalls + " to: " + request;
if (Server.DEBUG) {
System.out.println("Server[" + selfName +
"]\t Processed: '" + reply + "'");
}
if ((localCalls%100) == 0) {
System.out.println("Server[" + selfName +
"]\t Processed: " + localCalls + " requests.");
}
return(reply);
}
public String getName() throws RemoteException {
return("<ServerImpl: " + nCalls +">");
}
}
//
ServerRMI/ServerOp.java
import java.rmi.*;
// A remote interface for an object that supports the "call"
// operation.
public interface ServerOp extends Remote {
public String getName() throws RemoteException;
public String frob(ClientOp o) throws RemoteException;
}
In the server, main() establishes a security manager (this is required--we use
RMISecurityManager, but any security manager will do) and then calls Naming.rebind()
to register with the rmiregistry. That's all. [The method rebind() will overwrite previous
registration of an object, whereas bind() will throw an error if there is a previous registration.]
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks
Home