server.java

来自「java的客户端程序」· Java 代码 · 共 62 行

JAVA
62
字号
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import java.io.*;
import ssd8exercise5creator.*;
import ssd8exercise5.*;

/**
 * class <em>Server</em> represents the server for the SSD8 
 * Corba distributed to do list system.  The server binds an to do list factory
 * object using Corba naming.  The to do list factory object is used to
 * create new to do lists for each user that registers.
 *
 * @author iCarnegie, Inc (VP)
 * @version 1.0
 */
public class Server {

    public static void main( String [] args ) {
	
	try {

	    /*
	     * Create and initialize the orb.
	     */
	    ORB orb = ORB.init( args, null );

	    /*
	     * Create the TodolistCreator and register it
	     * with the orb.
	     */
	    TodolistCreatorInterfaceImpl todolistCreator = new TodolistCreatorInterfaceImpl( args );
	    orb.connect( todolistCreator );

	    /*
	     * 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("TodolistCreator","");	       
	    System.out.println( "To Do List Creator is bound!" );
	    NameComponent path[] = { nc };	       
	    ncRef.rebind( path, todolistCreator );
	    
	    /*
	     * Wait for client invocations.
	     */
	    java.lang.Object sync = new java.lang.Object();
	    synchronized(sync) {
		sync.wait();
	    }
	} catch( Exception e ) {
	    e.printStackTrace();
	}

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?