FileDocCategorySizeDatePackage
SupplyServer.javaAPI DocExample1851Sun Feb 08 21:33:40 GMT 2004None

SupplyServer

public class SupplyServer extends Object
author
Ian Darwin, http://www.darwinsys.com/
version
$Id: SupplyServer.java,v 1.4 2004/02/09 03:33:40 ian Exp $

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)
Execution of Java programs starts at main()

		new SupplyServer().runServer(argv);
	
protected voidrunServer(java.lang.String[] argv)
Do the work of contacting the ORB, registering with it, binding the Object, and waiting for clients.

		try {
			// Create and initialize the ORB
			ORB orb = ORB.init(argv, null);

			// create servant and register it with the ORB
			SupplyImpl imp = new SupplyImpl("Fred");
			orb.connect(imp);

			// get the root naming context
			org.omg.CORBA.Object objRef = 
				orb.resolve_initial_references("NameService");
			NamingContext ncRef = NamingContextHelper.narrow(objRef);

			// bind the Object Reference in Naming
			NameComponent nc = new NameComponent("Supply", "");
			NameComponent path[] = {nc};
			ncRef.rebind(path, imp);

			// Wait for clients to invoke us. This use of Object
			// (fully-qualified because of ORG.OMG.CORBA.Object)
			// is equivalent to a UNIX pause() system call, that is,
			// an indefinite wait.
			System.out.println("Server: Waiting for clients...");
			java.lang.Object sync = new java.lang.Object();
			synchronized (sync) {
				sync.wait();
			}

		} catch (Exception e) {
			System.err.println("ERROR: " + e);
			e.printStackTrace(System.out);
		}