import java.rmi.registry.Registry; import java.rmi.registry.LocateRegistry; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; /** This server program instantiates two remote objects, registers them with the naming service, and waits for clients to invoke methods on the remote objects. */ public class ProductServer { public static void main(String args[]) { try { System.out.println ("Constructing server implementations..."); ProductImpl p1 = new ProductImpl("Blackwell Toaster"); Product stub1 =(Product) UnicastRemoteObject.exportObject(p1, 0); // Bind the remote object's stub in the registry Registry registry = LocateRegistry.getRegistry(); registry.bind("toaster", stub1); ProductImpl p2 = new ProductImpl("ZapXpress Microwave Oven"); Product stub2 =(Product) UnicastRemoteObject.exportObject(p2, 0); // Bind the remote object's stub in the registry registry = LocateRegistry.getRegistry(); registry.bind("microwave", stub2); System.out.println ("Binding server implementations to registry..."); System.out.println ("Waiting for invocations from clients..."); } catch(Exception e) { System.err.println("Server exception: " + e.toString()); e.printStackTrace(); } } }