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

      System.out.println("ORB initialised\n");

      // get the root naming context
      org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");

      // Use NamingContextExt instead of NamingContext,
      // part of the Interoperable naming Service.
      NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

      // resolve the Object Reference in Naming
      String name = "Hello1";
      helloImpl = HelloHelper.narrow(ncRef.resolve_str(name));

      System.out.println("Obtained a handle on server object: " + helloImpl);
      System.out.println(helloImpl.sayHello());
      helloImpl.shutdown();

    } catch (Exception e) {
      System.out.println("ERROR : " + e);
      e.printStackTrace(System.out);
    }
  } // end main
Esempio n. 2
0
  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 static void main(String[] args) {
    try {
      String tableID = "Test-Tafel2";
      ORB _orb;
      Properties props = new Properties();

      props.put("org.omg.CORBA.ORBInitialPort", "1050");
      props.put("org.omg.CORBA.ORBInitialHost", "192.168.2.20");

      _orb = ORB.init(new String[0], props);

      org.omg.CORBA.Object objRef = _orb.resolve_initial_references("NameService");
      NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

      BoardService boardServiceObj =
          (BoardService) BoardServiceHelper.narrow(ncRef.resolve_str(tableID + "/BoardService"));

      User _user1 = new User("Yumo");
      boardServiceObj.sendMessage(
          _user1,
          new Message("Hallo Test-Tafel no. 1", _user1.name, new Date().toString()),
          tableID);

    } catch (InvalidName ex) {
      Logger.getLogger(BoardServiceTestbench.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NotFound ex) {
      Logger.getLogger(BoardServiceTestbench.class.getName()).log(Level.SEVERE, null, ex);
    } catch (CannotProceed ex) {
      Logger.getLogger(BoardServiceTestbench.class.getName()).log(Level.SEVERE, null, ex);
    } catch (org.omg.CosNaming.NamingContextPackage.InvalidName ex) {
      Logger.getLogger(BoardServiceTestbench.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnknownUser ex) {
      Logger.getLogger(BoardServiceTestbench.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Esempio n. 4
0
  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();
    }
  }
Esempio n. 5
0
  GrmWrapperCorba(ORB orb) {
    try {

      org.omg.CORBA.Object ns = orb.resolve_initial_references("NameService");
      NamingContextExt nameService = NamingContextExtHelper.narrow(ns);
      grm = GrmHelper.narrow(nameService.resolve(nameService.to_name("GRM")));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 6
0
  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");
    }
  }
Esempio n. 7
0
  private void onSellItemClick() {
    try {
      // Determine which seller auction is selected
      String auctionName = (String) sellList.getSelectedValue();

      if (auctionName != null) {
        // resolve the Object Reference in Naming
        Auction auctionImpl = AuctionHelper.narrow(ncRef.resolve_str(auctionName));

        // Sell item
        auctionImpl.sellItem(userName);
        appletDisplay(auctionName + " has ended");

        // Update the auction lists
        updateAuctionLists(false);
      }
      ;

    } catch (NumberFormatException e1) {
      appletDisplay("Invalid bid price");
    } catch (AuctionFailure e2) {
      appletDisplay(e2.description);
    } catch (Exception e3) {
      appletDisplay("Unable to place bid");
      System.out.println("ERROR : " + e3);
      e3.printStackTrace(System.out);
    }
  }
Esempio n. 8
0
  private void onBidClicked() {
    try {
      // Determine which bidder auction is selected
      String auctionName = (String) bidList.getSelectedValue();

      // Determine what the bid is
      int bidPrice = Integer.parseInt(txtBidPrice.getText());

      if (auctionName != null) {
        // resolve the Object Reference in Naming
        Auction auctionImpl = AuctionHelper.narrow(ncRef.resolve_str(auctionName));

        // Place bid
        auctionImpl.bid(userName, bidPrice);
        appletDisplay("Placed bid of $" + Integer.toString(bidPrice) + " on " + auctionName);

        // Update the auction lists
        updateAuctionLists(false);
      }
      ;

    } catch (NumberFormatException e1) {
      appletDisplay("Invalid bid price");
    } catch (AuctionFailure e2) {
      appletDisplay(e2.description);
    } catch (Exception e3) {
      appletDisplay("Unable to place bid");
      System.out.println("ERROR : " + e3);
      e3.printStackTrace(System.out);
    }
  }
Esempio n. 9
0
  private void onCreateNewAuctionClicked() {
    try {
      int startingPrice;
      String description = txtDescription.getText();

      if (txtStartingPrice.getText().equals("")) {
        startingPrice = 0;
      } else {
        startingPrice = Integer.parseInt(txtStartingPrice.getText());
      }

      // Get a reference to an inactive auction from the auction manager.
      String auctionRef = auctionFactoryImpl.getInactiveAuction();

      // resolve the Object Reference in Naming
      Auction auctionImpl = AuctionHelper.narrow(ncRef.resolve_str(auctionRef));

      // Put an item up for sale
      auctionImpl.offerItem(userName, description, startingPrice);

      // Update the auction lists
      updateAuctionLists(false);

      appletDisplay("Started new auction");

    } catch (NumberFormatException e1) {
      appletDisplay("Invalid starting price");
    } catch (AuctionFailure e2) {
      appletDisplay(e2.description);
    } catch (Exception e3) {
      appletDisplay("Unable to create a new auction");
      System.out.println("ERROR : " + e3);
      e3.printStackTrace(System.out);
    }
  }
Esempio n. 10
0
  private MyServer.MyService getBoxOfficeByShowID(String desiredShowID)
      throws InvalidName, NotFound, CannotProceed,
          org.omg.CosNaming.NamingContextPackage.InvalidName {

    String boxOffice = desiredShowID.substring(0, 3);

    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");
    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(new String[1], props);

    org.omg.CORBA.Object ncobj = orb.resolve_initial_references("NameService");
    NamingContextExt nc = NamingContextExtHelper.narrow(ncobj);

    org.omg.CORBA.Object obj = nc.resolve_str("BO_" + boxOffice);

    MyServer.MyService target = MyServer.MyServiceHelper.narrow(obj);

    return target;
  }
  public static void main(String args[]) {
    try {
      // 创建和初始化ORB
      ORB orb = ORB.init(args, null);

      // 获得命名服务的Context
      org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
      NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

      // 获得名为“HelloService”的HelloService对象的远程引用
      String name = "HelloService";
      helloServiceImpl = HelloServiceHelper.narrow(ncRef.resolve_str(name));

      // 调用HelloService对象的远程方法
      System.out.println("Obtained a handle on server object: " + helloServiceImpl);
      System.out.println(helloServiceImpl.sayHello());
      helloServiceImpl.shutdown();
    } catch (Exception e) {
      System.out.println("ERROR : " + e);
      e.printStackTrace(System.out);
    }
  }
Esempio n. 12
0
  // Set up the client
  private void onConnectClicked() {
    // Create the arguments array
    String args[] = {
      "-ORBInitialHost", serverAddressField.getText(), "-ORBInitialPort", serverPortField.getText()
    };

    try {
      // create and initialize the ORB
      ORB orb = ORB.init(args, null);

      // get the root naming context
      org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");

      // Use NamingContextExt instead of NamingContext. This is
      // part of the Interoperable naming Service.
      ncRef = NamingContextExtHelper.narrow(objRef);

      // resolve the Object Reference in Naming
      String name = "AuctionFactory";
      auctionFactoryImpl = AuctionFactoryHelper.narrow(ncRef.resolve_str(name));

      appletDisplay("Connected to server");

      // Activate the login functionality
      btnLogIn.setEnabled(true);
      usernameField.setEnabled(true);
      passwordField.setEnabled(true);

    } catch (Exception e) {
      appletDisplay("Unable to connect to server");
      System.out.println("ERROR : " + e);
      e.printStackTrace(System.out);

      // Deactivate functionality
      btnLogIn.setEnabled(false);
      usernameField.setEnabled(false);
      passwordField.setEnabled(false);
      btnRefresh.setEnabled(false);
      sellList.setEnabled(false);
      bidList.setEnabled(false);
      btnCreateNewAuction.setEnabled(false);
      txtDescription.setEnabled(false);
      txtStartingPrice.setEnabled(false);
      btnSellItem.setEnabled(false);
      btnBid.setEnabled(false);
      txtBidPrice.setEnabled(false);
      loggedIn = false;
    }
  }
Esempio n. 13
0
  private AuctionStatus getAuctionStatus(String auctionServerName) throws Exception {

    BooleanHolder isActive = new BooleanHolder();
    StringHolder itemDesc = new StringHolder();
    IntHolder price = new IntHolder();
    StringHolder highBidder = new StringHolder();

    // resolve the Object Reference in Naming
    Auction auctionImpl = AuctionHelper.narrow(ncRef.resolve_str(auctionServerName));

    // Get the auction status
    auctionImpl.viewAuctionStatus(userName, isActive, itemDesc, price, highBidder);

    // Return the status
    return new AuctionStatus(isActive.value, itemDesc.value, price.value, highBidder.value);
  }
  private static void rlist(NamingContext ctx, NameComponent[] base, StringBuffer buf) {
    BindingListHolder listHolder = new BindingListHolder(new Binding[0]);
    BindingIteratorHolder iterHolder = new BindingIteratorHolder();
    ctx.list(0, listHolder, iterHolder);
    BindingHolder bindingHolder = new BindingHolder();

    if (iterHolder.value == null) return;

    NameComponent[] name = new NameComponent[base.length + 1];
    for (int i = 0; i < base.length; i++) name[i] = base[i];

    while (iterHolder.value.next_one(bindingHolder)) {
      Binding binding = bindingHolder.value;
      name[name.length - 1] = binding.binding_name[0];
      try {
        String stringName = namingService.to_string(name);
        buf.append(stringName);
      } catch (Exception e) {
        buf.append(e.getMessage());
      }

      if (binding.binding_type.value() == BindingType._ncontext) {
        // this entry is for a subcontext
        // add trailing '/' just to distinguish
        // a subcontext from a regular object
        buf.append('/');
        buf.append('\n');

        // recursively list the subcontext contents
        try {
          NamingContext subCtx = NamingContextHelper.narrow(ctx.resolve(binding.binding_name));
          rlist(subCtx, name, buf);
        } catch (Exception e) {
          buf.append(e.getMessage());
        }
      } else {
        buf.append('\n');
      }
    }
  }