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);
    }
  }
Example #2
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
  public org.omg.CORBA.Object resolve(NameComponent[] nc)
      throws NotFound, CannotProceed, InvalidName {
    if (this.destroyed) throw new CannotProceed();

    if (nc == null || nc.length == 0) throw new InvalidName();

    Name n = new Name(nc[0]);
    if (nc.length > 1) {
      org.omg.CORBA.Object next_context = (org.omg.CORBA.Object) this.contexts.get(n);
      if ((next_context == null) || (isDead(next_context)))
        throw new NotFound(NotFoundReason.missing_node, nc);

      NameComponent[] nc_prime = new NameComponent[nc.length - 1];
      System.arraycopy(nc, 1, nc_prime, 0, nc_prime.length);

      // try first to call the context implementation object directly.
      String contextOID = this.getObjectOID(next_context);
      JBossNamingContext jbossContext = (contextOID == null ? null : contextImpls.get(contextOID));
      if (jbossContext != null) return jbossContext.resolve(nc_prime);
      else return NamingContextExtHelper.narrow(next_context).resolve(nc_prime);
    } else {
      org.omg.CORBA.Object result = (org.omg.CORBA.Object) this.contexts.get(n);

      if (result == null) result = (org.omg.CORBA.Object) this.names.get(n);

      if (result == null) throw new NotFound(NotFoundReason.missing_node, n.components());

      if (!noPing && isDead(result))
        throw new NotFound(NotFoundReason.missing_node, n.components());

      return result;
    }
  }
  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);
    }
  }
Example #5
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();
    }
  }
Example #6
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();
    }
  }
Example #7
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");
    }
  }
  protected void startService() throws Exception {
    Context ctx;
    ORB orb;
    POA rootPOA;

    try {
      ctx = new InitialContext();
    } catch (NamingException e) {
      throw new RuntimeException("Cannot get intial JNDI context: " + e);
    }
    try {
      orb = (ORB) ctx.lookup("java:/" + CorbaORBService.ORB_NAME);
    } catch (NamingException e) {
      throw new RuntimeException("Cannot lookup java:/" + CorbaORBService.ORB_NAME + ": " + e);
    }
    try {
      rootPOA = (POA) ctx.lookup("java:/" + CorbaORBService.POA_NAME);
    } catch (NamingException e) {
      throw new RuntimeException("Cannot lookup java:/" + CorbaORBService.POA_NAME + ": " + e);
    }

    // Create the naming server POA as a child of the root POA
    Policy[] policies = new Policy[2];
    policies[0] = rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
    policies[1] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
    namingPOA = rootPOA.create_POA("Naming", null, policies);
    namingPOA.the_POAManager().activate();

    // initialize the static naming service variables.
    JBossNamingContextImpl.init(orb, rootPOA);

    // create and initialize the root context instance according to the configuration.
    JBossNamingContextImpl ns = new JBossNamingContextImpl();
    Configuration configuration = ((org.jacorb.orb.ORB) orb).getConfiguration();
    boolean doPurge = configuration.getAttribute("jacorb.naming.purge", "off").equals("on");
    boolean noPing = configuration.getAttribute("jacorb.naming.noping", "off").equals("on");
    ns.init(namingPOA, doPurge, noPing);

    // create and activate the root context.
    byte[] rootContextId = "root".getBytes();
    namingPOA.activate_object_with_id(rootContextId, ns);
    namingService =
        NamingContextExtHelper.narrow(
            namingPOA.create_reference_with_id(
                rootContextId, "IDL:omg.org/CosNaming/NamingContextExt:1.0"));

    // bind the root context to JNDI.
    bind(NAMING_NAME, "org.omg.CosNaming.NamingContextExt");
    getLog().info("CORBA Naming Started");
    getLog().debug("Naming: [" + orb.object_to_string(namingService) + "]");
  }
Example #9
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;
    }
  }
 public NamingContext new_context() {
   try {
     // create and initialize a new context.
     JBossNamingContext newContextImpl = new JBossNamingContext();
     newContextImpl.init(this.poa, this.doPurge, this.noPing);
     // create the oid for the new context and activate it with the naming service POA.
     String oid = new String(this.poa.servant_to_id(this)) + "/ctx" + (++this.childCount);
     this.poa.activate_object_with_id(oid.getBytes(), newContextImpl);
     // add the newly-created context to the cache.
     contextImpls.put(oid, newContextImpl);
     return NamingContextExtHelper.narrow(
         this.poa.create_reference_with_id(
             oid.getBytes(), "IDL:omg.org/CosNaming/NamingContextExt:1.0"));
   } catch (Exception e) {
     log.error("Cannot create CORBA naming context", e);
     return null;
   }
 }
  public void bind(NameComponent[] nc, org.omg.CORBA.Object obj)
      throws NotFound, CannotProceed, InvalidName, AlreadyBound {
    if (this.destroyed) throw new CannotProceed();

    if (nc == null || nc.length == 0) throw new InvalidName();

    if (obj == null) throw new org.omg.CORBA.BAD_PARAM();

    Name n = new Name(nc);
    Name ctx = n.ctxName();
    NameComponent nb = n.baseNameComponent();

    if (ctx == null) {
      if (this.names.containsKey(n)) {
        // if the name is still in use, try to ping the object
        org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.names.get(n);
        if (isDead(ref)) {
          rebind(n.components(), obj);
          return;
        }
        throw new AlreadyBound();
      } else if (this.contexts.containsKey(n)) {
        // if the name is still in use, try to ping the object
        org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.contexts.get(n);
        if (isDead(ref)) unbind(n.components());
        throw new AlreadyBound();
      }

      if ((this.names.put(n, obj)) != null) throw new CannotProceed(_this(), n.components());

      log.debugf("Bound name: " + n.toString());
    } else {
      NameComponent[] ncx = new NameComponent[] {nb};
      org.omg.CORBA.Object context = this.resolve(ctx.components());

      // try first to call the context implementation object directly.
      String contextOID = this.getObjectOID(context);
      JBossNamingContext jbossContext = (contextOID == null ? null : contextImpls.get(contextOID));
      if (jbossContext != null) jbossContext.bind(ncx, obj);
      else NamingContextExtHelper.narrow(context).bind(ncx, obj);
    }
  }
  public void rebind_context(NameComponent[] nc, NamingContext obj)
      throws NotFound, CannotProceed, InvalidName {
    if (this.destroyed) throw new CannotProceed();

    if (nc == null || nc.length == 0) throw new InvalidName();

    if (obj == null) throw new org.omg.CORBA.BAD_PARAM();

    Name n = new Name(nc);
    Name ctx = n.ctxName();
    NameComponent nb = n.baseNameComponent();

    if (ctx == null) {
      // the name is bound, but it is bound to an object - the client should have been using
      // rebind().
      if (this.names.containsKey(n))
        throw new NotFound(NotFoundReason.not_context, new NameComponent[] {nb});

      // try to remove an existing context binding.
      org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.contexts.remove(n);
      if (ref != null) {
        ref._release();
        // remove the old context from the implementation cache.
        String oid = this.getObjectOID(ref);
        if (oid != null) contextImpls.remove(oid);
      }

      this.contexts.put(n, obj);
      log.debugf("Re-Bound context: " + n.baseNameComponent().id);
    } else {
      // rebind in the correct context
      NameComponent[] ncx = new NameComponent[] {nb};
      org.omg.CORBA.Object context = this.resolve(ctx.components());

      // try first to call the context implementation object directly.
      String contextOID = this.getObjectOID(context);
      JBossNamingContext jbossContext = (contextOID == null ? null : contextImpls.get(contextOID));
      if (jbossContext != null) jbossContext.rebind_context(ncx, obj);
      else NamingContextExtHelper.narrow(context).rebind_context(ncx, obj);
    }
  }
Example #13
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);
    }
  }
  public void unbind(NameComponent[] nc) throws NotFound, CannotProceed, InvalidName {
    if (this.destroyed) throw new CannotProceed();

    if (nc == null || nc.length == 0) throw new InvalidName();

    Name n = new Name(nc);
    Name ctx = n.ctxName();
    NameComponent nb = n.baseNameComponent();

    if (ctx == null) {
      if (this.names.containsKey(n)) {
        org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.names.remove(n);
        ref._release();
        log.debugf("Unbound: " + n.toString());
      } else if (this.contexts.containsKey(n)) {
        org.omg.CORBA.Object ref = (org.omg.CORBA.Object) this.contexts.remove(n);
        ref._release();
        // remove the context from the implementation cache.
        String oid = this.getObjectOID(ref);
        if (oid != null) contextImpls.remove(oid);

        log.debugf("Unbound: " + n.toString());
      } else {
        if (log.isEnabled(Level.WARN)) log.warnf("Unbind failed for " + n.toString());
        throw new NotFound(NotFoundReason.not_context, n.components());
      }
    } else {
      NameComponent[] ncx = new NameComponent[] {nb};
      org.omg.CORBA.Object context = this.resolve(ctx.components());

      // try first to call the context implementation object directly.
      String contextOID = this.getObjectOID(context);
      JBossNamingContext jbossContext = (contextOID == null ? null : contextImpls.get(contextOID));
      if (jbossContext != null) jbossContext.unbind(ncx);
      else NamingContextExtHelper.narrow(context).unbind(ncx);
    }
  }