Package

Source Code of ItemServer

import java.util.Properties;

import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.CosNaming.NamingContextPackage.CannotProceed;
import org.omg.CosNaming.NamingContextPackage.NotFound;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.PortableServer.POAPackage.ServantNotActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;

public class ItemServer {
  private static ORB theOrb;
  private static Properties props;
  private static POA thePoa;

  public static void main(String[] args) {

    try {
      props = new Properties();
      //props.put("org.omg.CORBA.ORBInitialPort", "900");
      //props.put("org.omg.CORBA.ORBInitialHost", "stolas69.servequake.com");
      props.setProperty("org.omg.CORBA.ORBInitialPort", "900");
      props.setProperty("org.omg.CORBA.ORBInitialHost", "stolas69.servequake.com");

      // init ORB
      theOrb = ORB.init(args, props);
      // init POA
      thePoa = POAHelper.narrow(theOrb
          .resolve_initial_references("RootPOA"));
      thePoa.the_POAManager().activate();
    } catch (Exception e) {
      System.out.println(e);
    }

    Items items = Items.getInstance();
   
    // create Servant objects
    CustomerImpl customers = new CustomerImpl(items);
    AdminImpl admins = new AdminImpl(items);

    // init root context
    NamingContextExt nc;
    try {
      nc = NamingContextExtHelper.narrow(theOrb
          .resolve_initial_references("NameService"));
      System.out.println("resolved initial reference to NameService ...");

      nc.rebind(nc.to_name("admin"), thePoa.servant_to_reference(admins));
      nc.rebind(nc.to_name("customer"),
          thePoa.servant_to_reference(customers));
      System.out.println("resolved references to NameService");
    } catch (InvalidName e) {
      e.printStackTrace(System.err);
    } catch (NotFound e) {
      e.printStackTrace(System.err);
    } catch (CannotProceed e) {
      e.printStackTrace(System.err);
    } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
      e.printStackTrace(System.err);
    } catch (ServantNotActive e) {
      e.printStackTrace(System.err);
    } catch (WrongPolicy e) {
      e.printStackTrace(System.err);
    }
    theOrb.run();
  }
}
TOP

Related Classes of ItemServer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.