예제 #1
0
  public static void initOA() {
    _oa = OA.getRootOA(ORBInterface.getORB());

    try {
      _oa.initPOA();
    } catch (Exception e) {
      System.err.println("Failed to initialise OA: " + e);
    }
  }
예제 #2
0
  /**
   * Create a new bank account and store it in the bank. Return a CORBA object representation of the
   * account.
   *
   * @param name The name to associate with the account.
   * @return The <CODE>Account</CODE> CORBA object.
   */
  public Account create_account(String name) {
    // Create a new account with name "name"
    AccountImpl acc = new AccountImpl(name);
    // Store the object locally
    _accounts.put(name, acc);

    // Create a CORBA object representing the account
    System.out.println("create account ...........");
    // Return this to the caller
    return com.arjuna.demo.jts.explicitremotebank.AccountHelper.narrow(_oa.corbaReference(acc));
  }
예제 #3
0
  /**
   * Gain access to the bank account reference name of "name".
   *
   * @param name The name of the account to access.
   * @return The suitable account reference.
   * @throws NotExistingAccount If the account did not exist.
   */
  public Account get_account(String name) throws NotExistingAccount {
    // Gain a local reference to the account
    AccountImpl acc = (AccountImpl) _accounts.get(name);
    // If the account does not exist throw an exception to the user
    if (acc == null) throw new NotExistingAccount("The Account requested does not exist");

    // Print out a message to indicate that the <CODE>Account</CODE> local reference is being
    // converted to a
    // CORBA reference
    System.out.println("get account information ...........");
    // "Convert" the reference
    return com.arjuna.demo.jts.explicitremotebank.AccountHelper.narrow(_oa.corbaReference(acc));
  }
예제 #4
0
  @Test
  public void test() {
    org.omg.CosTransactions.Status status = Status.StatusUnknown;
    tranobject_i localObject = null;
    demosync sync = null;
    ORB myORB = null;
    RootOA myOA = null;

    try {
      myORB = ORB.getInstance("test");

      myOA = OA.getRootOA(myORB);

      myORB.initORB(new String[] {}, null);
      myOA.initOA();

      ORBManager.setORB(myORB);
      ORBManager.setPOA(myOA);

      Control myControl = null;
      org.omg.CosTransactions.Current current = OTSManager.get_current();
      Coordinator coord = null;

      sync = new demosync();
      localObject = new tranobject_i();

      current.begin();

      myControl = current.get_control();

      coord = myControl.get_coordinator();

      coord.register_resource(localObject.getReference());
      coord.register_synchronization(sync.getReference());

      try {
        current.commit(true);
      } catch (TRANSACTION_ROLLEDBACK e1) {
        System.out.println("Transaction rolledback");
      }

      try {
        status = coord.get_status();
      } catch (SystemException ex) {
        // assume reference no longer valid!

        status = Status.StatusUnknown;
      }
    } catch (UserException e1) {
      fail("Caught UserException: " + e1);
      e1.printStackTrace();
    } catch (SystemException e2) {
      fail("Caught SystemException: " + e2);
      e2.printStackTrace();
    }

    System.out.print(
        "Final action status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(status));
    System.out.println("\nTest completed successfully.");

    myOA.shutdownObject(sync);
    myOA.shutdownObject(localObject);

    myOA.destroy();
    myORB.shutdown();
  }
예제 #5
0
 public static void shutdownOA() {
   _oa.destroy();
 }
예제 #6
0
 public static org.omg.CORBA.Object corbaReference(Servant obj) {
   return _oa.corbaReference(obj);
 }
예제 #7
0
 public static void objectIsReady(Servant s) {
   _oa.objectIsReady(s);
 }
예제 #8
0
 public static void initializeOA() throws InvalidName, SystemException {
   _oa = OA.getRootOA(ORBInterface.getORB());
   _oa.initPOA();
 }
예제 #9
0
  @Test
  public void test() {
    ORB myORB = null;
    RootOA myOA = null;

    try {
      myORB = ORB.getInstance("test");
      myOA = OA.getRootOA(myORB);

      myORB.initORB(new String[] {}, null);
      myOA.initOA();

      ORBManager.setORB(myORB);
      ORBManager.setPOA(myOA);

      TransactionFactoryImple theOTS = new TransactionFactoryImple();
      Control myControl;
      grid_i localGrid = new grid_i(100, 100);
      int h, w, v;

      myControl = theOTS.create(0);

      assertNotNull(myControl);

      h = localGrid.height();
      w = localGrid.width();

      localGrid.set(2, 4, 123, myControl);
      v = localGrid.get(2, 4, myControl);

      // no problem setting and getting the elememt:

      System.out.println("grid[2,4] is " + v);

      assertEquals(123, v);

      Terminator handle = myControl.get_terminator();

      try {
        if (handle != null) {
          handle.commit(false);
        } else System.err.println("Error - no transaction terminator!");
      } catch (Exception ex) {
        System.out.println("Test error! Caught: " + ex);
      }

      ORBManager.getPOA().shutdownObject(theOTS);
      ORBManager.getPOA().shutdownObject(localGrid);
    } catch (UserException e) {
      fail("Caught UserException: " + e);

      e.printStackTrace();
    } catch (SystemException e) {
      fail("Caught SystemException: " + e);

      e.printStackTrace();
    }

    System.out.println("\nWill now try different thread terminating transaction.\n");

    try {
      org.omg.CosTransactions.Current current = OTSManager.get_current();

      System.out.println("Starting new transaction.");

      current.begin();

      Control tc = current.get_control();

      if (tc != null) {
        System.out.println("Creating new thread.");

        TransactionalThread tranThread = new TransactionalThread(tc);

        System.out.println("Waiting for thread to terminate transaction.\n");

        tranThread.start();

        while (!tranThread.finished()) Thread.yield();

        System.out.println("\nCreator will now attempt to rollback transaction. Should fail.");

        try {
          current.rollback();

          fail("Error - managed to rollback transaction!");
        } catch (NoTransaction e1) {
          System.out.println("Correct termination - caught: " + e1);
        } catch (INVALID_TRANSACTION e2) {
          System.out.println("Correct termination - caught: " + e2);
        } catch (Exception e3) {
          fail("Wrong termination - caught unexpected exception: " + e3);
          e3.printStackTrace();
        }

        System.out.println("Test completed successfully.");
      } else System.err.println("Error - null transaction control!");
    } catch (Exception e) {
      System.out.println("Caught unexpected exception: " + e);
    }

    myOA.destroy();
    myORB.shutdown();
  }