Package com.sun.sgs.service

Examples of com.sun.sgs.service.TransactionParticipant


  state = State.PREPARING;
  ProfileParticipantDetailImpl detail = null;
  for (Iterator<TransactionParticipant> iter = participants.iterator();
       iter.hasNext(); )
  {
      TransactionParticipant participant = iter.next();
      if (detailMap != null) {
    detail = detailMap.get(participant.getTypeName());
    startTime = System.currentTimeMillis();
      }
      try {
    if (iter.hasNext() || disablePrepareAndCommitOpt) {
        boolean readOnly = participant.prepare(this);
        if (detail != null) {
      detail.setPrepared(System.currentTimeMillis() -
             startTime, readOnly);
        }
        if (readOnly) {
      iter.remove();
      if (detail != null) {
          collectorHandle.addParticipant(detail);
      }
        }
        if (logger.isLoggable(Level.FINEST)) {
      logger.log(Level.FINEST,
           "prepare {0} participant:{1} returns {2}",
           this, getParticipantInfo(participant),
           readOnly);
        }
    } else {
        participant.prepareAndCommit(this);
        if (detail != null) {
      detail.
          setCommittedDirectly(System.currentTimeMillis() -
             startTime);
      collectorHandle.addParticipant(detail);
        }
        iter.remove();
        if (logger.isLoggable(Level.FINEST)) {
      logger.log(
          Level.FINEST,
          "prepareAndCommit {0} participant:{1} returns",
          this, getParticipantInfo(participant));
        }
    }
      } catch (Exception e) {
    if (logger.isLoggable(Level.FINEST)) {
        logger.logThrow(
      Level.FINEST, e, "{0} {1} participant:{1} throws",
      iter.hasNext() ? "prepare" : "prepareAndCommit",
      this, getParticipantInfo(participant));
    }
    if (state != State.ABORTED) {
        abort(e);
    }
    throw e;
      }
      if (state == State.ABORTED) {
    throw new TransactionAbortedException(
        "Transaction has been aborted: " + abortCause, abortCause);
      }
  }
  state = State.COMMITTING;
  for (TransactionParticipant participant : participants) {
      if (logger.isLoggable(Level.FINEST)) {
    logger.log(Level.FINEST, "commit {0} participant:{1}",
         this, getParticipantInfo(participant));
      }
      if (detailMap != null) {
    detail = detailMap.get(participant.getTypeName());
    startTime = System.currentTimeMillis();
      }
      try {
    participant.commit(this);
    if (detail != null) {
        detail.setCommitted(System.currentTimeMillis() -
          startTime);
        collectorHandle.addParticipant(detail);
    }
View Full Code Here


    /* -- Test abort -- */

    @Test
    public void testAbortNullTxn() throws Exception {
  store.createObject(txn);
  TransactionParticipant participant =
      txn.participants.iterator().next();
  try {
      participant.abort(null);
      fail("Expected NullPointerException");
  } catch (NullPointerException e) {
      System.err.println(e);
  }
    }
View Full Code Here

    /* -- Test prepare -- */

    @Test
    public void testPrepareNullTxn() throws Exception {
  store.createObject(txn);
  TransactionParticipant participant =
      txn.participants.iterator().next();
  try {
      participant.prepare(null);
      fail("Expected NullPointerException");
  } catch (NullPointerException e) {
      System.err.println(e);
  }
    }
View Full Code Here

    /* -- Test prepareAndCommit -- */

    @Test
    public void testPrepareAndCommitNullTxn() throws Exception {
  store.createObject(txn);
  TransactionParticipant participant =
      txn.participants.iterator().next();
  try {
      participant.prepareAndCommit(null);
      fail("Expected NullPointerException");
  } catch (NullPointerException e) {
      System.err.println(e);
  }
    }
View Full Code Here

    /* -- Test commit -- */

    @Test
    public void testCommitNullTxn() throws Exception {
  store.createObject(txn);
  TransactionParticipant participant =
      txn.participants.iterator().next();
  try {
      participant.commit(null);
      fail("Expected NullPointerException");
  } catch (NullPointerException e) {
      System.err.println(e);
  }
    }
View Full Code Here

    @Test
    public void testCommitNoTimeout() throws Exception {
  txn.commit();
  txn = new DummyTransaction(UsePrepareAndCommit.NO, 1000) {
      public void join(final TransactionParticipant participant) {
    super.join(new TransactionParticipant() {
        public boolean prepare(Transaction txn) throws Exception {
      return participant.prepare(txn);
        }
        public void commit(Transaction txn) {
      try {
View Full Code Here

  handle.getTransaction();
    }

    @Test
    public void testGetTransactionPreparing() {
  TransactionParticipant participant =
      new DummyTransactionParticipant() {
    public boolean prepare(Transaction txn) throws Exception {
        handle.getTransaction();
        return super.prepare(txn);
    }
View Full Code Here

  txn.join(participant);
    }

    @Test
    public void testGetTransactionAborting() {
  TransactionParticipant participant =
      new DummyTransactionParticipant() {
    public void abort(Transaction txn) {
        handle.getTransaction();
        super.abort(txn);
    }
View Full Code Here

  handle.getTransaction();
    }

    @Test
    public void testGetTransactionCommitting() throws Exception {
  TransactionParticipant participant =
      new DummyTransactionParticipant() {
    public void commit(Transaction txn) {
        handle.getTransaction();
        super.commit(txn);
    }
View Full Code Here

    @Test
    public void testJoinOtherThread() throws Exception {
  final AtomicReference<RuntimeException> exception =
      new AtomicReference<RuntimeException>(null);
  final TransactionParticipant participant =
      new DummyTransactionParticipant();
  Thread thread = new Thread() {
      public void run() {
    try {
        txn.join(participant);
View Full Code Here

TOP

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

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.