package bank; import org.omg.CORBA.*; import org.omg.PortableServer.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; public class BankServer { public static void main(String[] args) { try { DBUtils.init(); // create and initialize the ORB ORB orb = ORB.init(args, null); // get reference to rootpoa & activate the POAManager POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); // create the BankPOA Policy[] policies = new Policy[3]; policies[0] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT); policies[1] = rootPOA.create_request_processing_policy(RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY ); policies[2] = rootPOA.create_servant_retention_policy(ServantRetentionPolicyValue.RETAIN); POA bankPOA = rootPOA.create_POA("BankPOA",null,policies); // create the AccountPOA and set its ServantActivator policies[0] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT); policies[1] = rootPOA.create_request_processing_policy(RequestProcessingPolicyValue.USE_SERVANT_MANAGER); policies[2] = rootPOA.create_servant_retention_policy(ServantRetentionPolicyValue.RETAIN); POA accountPOA = rootPOA.create_POA("AccountPOA",null,policies); AccountServerActivatorImpl asa = new bank.AccountServerActivatorImpl(); rootPOA.activate_object(asa); accountPOA.set_servant_manager(asa._this(orb)); // create bank servant and associate it with the Bank POA BankImpl bankImpl = new BankImpl(); byte[] objectID = new String("CORBABank").getBytes(); bankPOA.activate_object_with_id(objectID,bankImpl); org.omg.CORBA.Object ref = bankPOA.create_reference_with_id(objectID,"IDL:bank/Bank:1.0"); Bank bref = BankHelper.narrow(ref); // get the root naming context 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 = "BankServer"; NameComponent path[] = ncRef.to_name( name ); ncRef.rebind(path, bref); // Start the POAs accountPOA.the_POAManager().activate(); bankPOA.the_POAManager().activate(); rootPOA.the_POAManager().activate(); // Ready, Set, and Go... System.out.println("BankServer ready and waiting ..."); // wait for invocations from clients orb.run(); } catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } DBUtils.cleanUp(); System.out.println("BankServer Exiting ..."); } }