accountserver.java

来自「corba的java的快速开发实例」· Java 代码 · 共 54 行

JAVA
54
字号
package com.hcycom.corba.example.bank;

import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import org.omg.CosNaming.NamingContextPackage.*;

public class AccountServer {

	public static void main(String args[]) {
		try{
		  // create and initialize the ORB
		  ORB orb = ORB.init(args, null);

		  // create an implementation and register it with the ORB
		  AccountImpl impl = new AccountImpl(orb);

		  // get reference to rootpoa & activate the POAManager
		  POA rootpoa = POAHelper.narrow(
			orb.resolve_initial_references("RootPOA"));
		  rootpoa.the_POAManager().activate();

		  // get object reference from the servant
		  org.omg.CORBA.Object ref = 
			rootpoa.servant_to_reference(impl);
		  Account href = AccountHelper.narrow(ref);
		  
		  // get the root naming context
		  // NameService invokes the name service
		  org.omg.CORBA.Object objRef = 
			orb.resolve_initial_references("NameService");
		  // Use NamingContextExt which is part of the Interoperable
		  // Naming Service (INS) specification.
		  NamingContextExt ncRef = 
			NamingContextExtHelper.narrow(objRef);

		  // bind the Object Reference in Naming
		  String name = "Account";
		  NameComponent path[] = ncRef.to_name( name );
		  ncRef.rebind(path, href);

		  System.out.println(
			  "AccountServer ready to serve your request ....");

		  // wait for invocations from clients
		  orb.run();
		} catch (Exception e) {
			System.err.println("ERROR: " + e);
			e.printStackTrace(System.out);
		}
		System.out.println("AccountServer Exiting ....");
	}
}

⌨️ 快捷键说明

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