public static void main(String args[]) { // public void run() { String nomOffice = args[0]; // Tableau des id/nom des sites OfficeDBManager db = new OfficeDBManager(); Hashtable<Short, String> codeSite = new Hashtable<Short, String>(); // Table des id des sites short[] idSite = db.getIdSites(); for (int i = 0; i < idSite.length; i++) { codeSite.put(idSite[i], db.getCodeSite(idSite[i])); } try { org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null); // Gestion du POA // **************** // Recuperation du POA POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); // Creation du servant // ********************* OfficeImpl monOffice = new OfficeImpl(orb, codeSite); // Activer le servant au sein du POA et recuperer son ID byte[] monOfficeId = rootPOA.activate_object(monOffice); // Activer le POA manager rootPOA.the_POAManager().activate(); /** ****** Enregistrement dans le service de nommage ******* */ // Recuperation du naming service NamingContext nameRoot = org.omg.CosNaming.NamingContextHelper.narrow( orb.resolve_initial_references("NameService")); // Construction du nom a enregistrer org.omg.CosNaming.NameComponent[] nameToRegister = new org.omg.CosNaming.NameComponent[1]; nameToRegister[0] = new org.omg.CosNaming.NameComponent(nomOffice, ""); // Enregistrement de l'objet CORBA dans le service de noms nameRoot.rebind(nameToRegister, rootPOA.servant_to_reference(monOffice)); System.out.println("==> Nom '" + nomOffice + "' est enregistre dans le service de noms."); String IORServant = orb.object_to_string(rootPOA.servant_to_reference(monOffice)); System.out.println("L'objet possede la reference suivante :"); System.out.println(IORServant); // Lancement de l'ORB et mise en attente de requete // ************************************************** orb.run(); } catch (Exception e) { e.printStackTrace(); } }
public static void main(String[] args) { Properties props = System.getProperties(); props.setProperty("org.omg.CORBA.ORBClass", "com.sun.corba.se.internal.POA.POAORB"); props.setProperty( "org.omg.CORBA.ORBSingletonClass", "com.sun.corba.se.internal.corba.ORBSingleton"); try { // Initialize the ORB. org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, props); // get a reference to the root POA org.omg.CORBA.Object obj = orb.resolve_initial_references("RootPOA"); POA poaRoot = POAHelper.narrow(obj); // Create policies for our persistent POA org.omg.CORBA.Policy[] policies = { // poaRoot.create_lifespan_policy(LifespanPolicyValue.PERSISTENT), poaRoot.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID), poaRoot.create_thread_policy(ThreadPolicyValue.ORB_CTRL_MODEL) }; // Create myPOA with the right policies POA poa = poaRoot.create_POA("DRSCommonServiceServerImpl_poa", poaRoot.the_POAManager(), policies); // Create the servant servant = new DRSCommonServiceServerImpl(SvrInfo.SVR3_NAME_VANCOUVER); // Activate the servant with the ID on myPOA byte[] objectId = servant.svrName.getBytes(); poa.activate_object_with_id(objectId, servant); // Activate the POA manager poaRoot.the_POAManager().activate(); // Get a reference to the servant and write it down. obj = poa.servant_to_reference(servant); // ---- Uncomment below to enable Naming Service access. ---- // org.omg.CORBA.Object ncobj = orb // .resolve_initial_references("NameService"); // NamingContextExt nc = NamingContextExtHelper.narrow(ncobj); // nc.bind(nc.to_name(servant.svrName), obj); PrintWriter ps = new PrintWriter(new FileOutputStream(new File(servant.svrName))); ps.println(orb.object_to_string(obj)); ps.close(); System.out.println("RM3: " + servant.svrName + " is ready..."); // Wait for incoming requests orb.run(); } catch (Exception ex) { ex.printStackTrace(); } }