public static void main(String[] args) { try { // init ORB ORB orb = ORB.init(args, null); // init POA POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); poa.the_POAManager().activate(); // create a Adder object AdderImpl adderImpl = new AdderImpl(); // create the object reference org.omg.CORBA.Object adderRef = poa.servant_to_reference(adderImpl); org.omg.CORBA.Object nsObject = orb.resolve_initial_references("NameService"); NamingContextExt nc = NamingContextExtHelper.narrow(nsObject); nc.rebind(nc.to_name("Adder"), adderRef); // wait for requests orb.run(); } catch (Exception e) { System.out.println(e); } }
public void run() { try { ORB orb = ORB.init(args, null); // get reference to rootpoa & activate the POAManager POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); poa.the_POAManager().activate(); // 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); DomainParticipantFactoryImpl impl = new DomainParticipantFactoryImpl(orb, poa); // get object reference from the servant (and implicitly register // it) org.omg.CORBA.Object oref = poa.servant_to_reference(impl); DomainParticipantFactory ref = DomainParticipantFactoryHelper.narrow(oref); if (ncRef != null) { // bind the Object Reference in Naming NameComponent path[] = ncRef.to_name("DomainParticipantFactory"); ncRef.rebind(path, ref); } System.out.println("Server ready and waiting ..."); orb.run(); } catch (Exception e) { System.out.println("e" + e); e.printStackTrace(); } }
public static void main(String args[]) { if (args.length == 0) { System.out.println("Koordinator Namen eingeben..."); } else { try { // ORB Eigenschaften setzen Properties props = new Properties(); props.put("org.omg.CORBA.ORBInitialPort", "1050"); props.put("org.omg.CORBA.ORBInitialHost", "localhost"); orb = ORB.init(args, props); // Referenz von rootPOA holen und POA Manager aktivieren POA rootPoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootPoa.the_POAManager().activate(); // NamingContext besorgen NamingContextExt nc = NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService")); // Objektreferenz mit Namen "koordinator" besorgen org.omg.CORBA.Object obj = nc.resolve_str(args[1]); // Referenz fuer den Servant besorgen ggt.Koordinator koord = KoordinatorHelper.narrow(obj); // Servant erzeugen StarterImpl starter = new StarterImpl(args[0], koord, rootPoa); // Referenz fuer den Servant besorgen org.omg.CORBA.Object ref = rootPoa.servant_to_reference(starter); // Downcast Corba-Objekt -> koordinator ggt.Starter href = StarterHelper.narrow(ref); // starter bei koordinator anmelden koord.activateStarter(href, args[0]); // binde die Object Reference an einen Namen String name = args[0]; NameComponent path[] = nc.to_name(name); nc.rebind(path, href); System.out.println("Koordinator laeuft ..."); // Orb starten und auf Clients warten orb.run(); } catch (Exception e) { System.err.println("Fehler: " + e); e.printStackTrace(System.out); } System.out.println("BankServer Exit"); } }