Package com.sun.sgs.service

Examples of com.sun.sgs.service.Transaction


                super.run();
                action1 = new ShutdownServiceAction(service);
                action1.assertBlocked();
                action2 = new ShutdownServiceAction(service);
                action2.assertBlocked();
                Transaction txn = txnProxy.getCurrentTransaction();
                txn.abort(new TestAbortedTransactionException("abort"));
            }
View Full Code Here


     * @throws TransactionNotActiveException if there is no currently active
     *                                       transaction
     * @throws TransactionTimeoutException if the transaction has timed out
     */
    static Transaction getCurrentTransaction() {
        Transaction txn = currentTransaction.get();

        if (txn == null) {
            throw new TransactionNotActiveException("no current transaction");
        }

        if (txn.isAborted()) {
            throw new TransactionNotActiveException("Transaction is aborted",
                                                    txn.getAbortCause());
        }

        txn.checkTimeout();

        return txn;
    }
View Full Code Here

     * the state of that transaction.
     *
     * @return {@code true} if there is a current transaction
     */
    static boolean inTransaction() {
        Transaction txn = currentTransaction.get();
        return (txn != null);
    }
View Full Code Here

    static void setCurrentTransaction(Transaction transaction) {
        if (transaction == null) {
            throw new NullPointerException("null transactions not allowed");
        }

        Transaction txn = currentTransaction.get();
        if (txn != null) {
            throw new IllegalStateException("an active transaction is " +
                                            "currently running");
        }
View Full Code Here

    static void clearCurrentTransaction(Transaction transaction) {
        if (transaction == null) {
            throw new NullPointerException("transaction cannot be null");
        }

        Transaction txn = currentTransaction.get();
        if (txn == null) {
            throw new IllegalStateException("no active transaction to clear");
        }
        if (!txn.equals(transaction)) {
            throw new IllegalArgumentException("provided transaction is " +
                                               "not currently active");
        }

        currentTransaction.set(null);
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public boolean shouldContinue() {
        Transaction txn = txnProxy.getCurrentTransaction();
        return System.currentTimeMillis() - txn.getCreationTime() <
               continueThreshold;
    }
View Full Code Here

  final AtomicReference<RuntimeException> exception =
      new AtomicReference<RuntimeException>(null);
  Thread thread = new Thread() {
      public void run() {
    try {
        Transaction t = handle.getTransaction();
        if (txn != t) {
      throw new RuntimeException(
          "Expected " + txn + ", got " + t);
        }
    } catch (RuntimeException e) {
View Full Code Here

    /* -- Test Transaction.getId -- */

    @Test
    public void testGetId() {
  txn.abort(abortXcp);
  Transaction txn2 = coordinator.createTransaction(
                coordinator.getDefaultTimeout()).
      getTransaction();
  assertNotNull(txn.getId());
  assertNotNull(txn2.getId());
  assertFalse(Arrays.equals(txn.getId(), txn2.getId()));
    }
View Full Code Here

    @Test
    public void testGetCreationTime() throws Exception {
  long now = System.currentTimeMillis();
  Thread.sleep(50);
  Transaction txn1 = coordinator.createTransaction(
                coordinator.getDefaultTimeout()).
      getTransaction();
  Thread.sleep(50);
  Transaction txn2 = coordinator.createTransaction(
                coordinator.getDefaultTimeout()).
      getTransaction();
  assertTrue("Transaction creation time is too early: " +
            txn1.getCreationTime(),
            now < txn1.getCreationTime());
  assertTrue("Transaction creation times out-of-order: " +
            txn1.getCreationTime() + " vs " + txn2.getCreationTime(),
            txn1.getCreationTime() < txn2.getCreationTime());
    }
View Full Code Here

  p.setProperty(TransactionCoordinator.TXN_TIMEOUT_PROPERTY, "5000");
  p.setProperty(TransactionCoordinator.TXN_UNBOUNDED_TIMEOUT_PROPERTY,
          "100000");
  TransactionCoordinator coordinator =
      new TransactionCoordinatorImpl(p, collectorHandle);
  Transaction txn = coordinator.createTransaction(
                coordinator.getDefaultTimeout()).getTransaction();
  assertTrue("Incorrect bounded Transaction timeout: " +
       txn.getTimeout(),
       txn.getTimeout() == 5000);
  txn = coordinator.createTransaction(
                ScheduledTask.UNBOUNDED).getTransaction();
  assertTrue("Incorrect unbounded Transaction timeout: " +
       txn.getTimeout(),
       txn.getTimeout() == 100000);
    }
View Full Code Here

TOP

Related Classes of com.sun.sgs.service.Transaction

Copyright © 2018 www.massapicom. 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.