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);
    }
  }
Beispiel #2
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");
    }
  }
  /**
   * Returns the CORBA Object which represents this object.
   *
   * @param
   * @return The CORBA object.
   * @see
   */
  final synchronized RecoveryCoordinator object() {

    if (thisRef == null) {
      if (poa == null) {
        poa = Configuration.getPOA("RecoveryCoordinator" /*#Frozen*/);
        recoverable = Configuration.isRecoverable();
      }

      try {

        if (recoverable && globalTID != null) {
          // Create the object id from the global transaction
          // identifier and the internal sequence number.

          byte[] tidBytes = globalTID.toBytes();
          byte[] id = new byte[tidBytes.length + 4];
          System.arraycopy(tidBytes, 0, id, 4, tidBytes.length);
          id[0] = (byte) internalSeq;
          id[1] = (byte) (internalSeq >> 8);
          id[2] = (byte) (internalSeq >> 16);
          id[3] = (byte) (internalSeq >> 24);

          // Activate the object and create the reference.

          poa.activate_object_with_id(id, this);

          org.omg.CORBA.Object obj =
              poa.create_reference_with_id(id, RecoveryCoordinatorHelper.id());
          thisRef = RecoveryCoordinatorHelper.narrow(obj);
          // thisRef = (RecoveryCoordinator) this;
        } else {
          poa.activate_object(this);
          org.omg.CORBA.Object obj = poa.servant_to_reference(this);
          thisRef = RecoveryCoordinatorHelper.narrow(obj);
          // thisRef = (RecoveryCoordinator)this;
        }
      } catch (Exception exc) {
        _logger.log(Level.SEVERE, "jts.create_recoverycoordinator_error");
        String msg =
            LogFormatter.getLocalizedMessage(_logger, "jts.create_recoverycoordinator_error");
        throw new org.omg.CORBA.INTERNAL(msg);
      }
    }

    return thisRef;
  }
  /**
   * Destroys the RecoveryCoordinatorImpl object.
   *
   * @param
   * @return
   * @see
   */
  final synchronized void destroy() {

    try {
      if (poa != null && thisRef != null) {
        poa.deactivate_object(poa.reference_to_id(thisRef));
        thisRef = null;
      } else {
        // BUGFIX(Ram J) It is possible that the
        // RecoveryCoordinator object was activated via the activation
        // daemon. In that case, there is no guarantee
        // that poa and thisRef are set to a meaningful value.
        // So, try to deactivate the RecoveryCoordinator object anyway.

        POA rcPoa = null;
        if (poa == null) {
          rcPoa = Configuration.getPOA("RecoveryCoordinator" /*#Frozen*/);
        } else {
          rcPoa = poa;
        }

        if (thisRef == null) {
          rcPoa.deactivate_object(rcPoa.servant_to_id(this));
        } else {
          rcPoa.deactivate_object(rcPoa.reference_to_id(thisRef));
          thisRef = null;
        }
      }
    } catch (Exception exc) {
      _logger.log(Level.WARNING, "jts.object_destroy_error", "RecoveryCoordinator");
    }

    // finalize();
    globalTID = null;
    internalSeq = 0;
  }