Java Reference
In-Depth Information
Example 5.11 The Session server implementation
package net.multitool.RMIDemo;
import net.multitool.RMIDemo.*;
import java.rmi.*;
import java.rmi.server.*;
/** SessionImpl is the server class for the Session RMI interface.
*/
public class
SessionImpl
extends UnicastRemoteObject
implements Session
{
/** Constructor needed to ensure call to UnicastRemoteObject
* constructor and to thus propagate the possible exception.
*/
public SessionImpl() throws RemoteException {
super();
}
/** A static main() for the server. */
public static void main(String[] arglist)
{
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
String rmiName = "//penfold/Session";
try {
Session adder = new SessionImpl();
Naming.rebind(rmiName, adder);
} catch (Exception e) {
e.printStackTrace();
}
}
/** Implementation of the RMI method, add. */
public int add(int x, int y) throws java.rmi.RemoteException
{
return x+y;
}
}
Search WWH ::




Custom Search