@Override
  public Response processForgetTransaction(TransactionInfo info) throws Exception {
    TransactionId txId = info.getTransactionId();
    txMap.remove(txId);

    protocolManager.forgetTransaction(info.getTransactionId());
    return null;
  }
 @Override
 public Response processRollbackTransaction(TransactionInfo info) throws Exception {
   protocolManager.rollbackTransaction(info);
   TransactionId txId = info.getTransactionId();
   txMap.remove(txId);
   return null;
 }
  @Override
  public Response processCommitTransactionTwoPhase(TransactionInfo info) throws Exception {
    protocolManager.commitTransactionTwoPhase(info);
    TransactionId txId = info.getTransactionId();
    txMap.remove(txId);

    return null;
  }
  @Override
  public Response processBeginTransaction(TransactionInfo info) throws Exception {
    TransactionId txId = info.getTransactionId();

    if (!txMap.containsKey(txId)) {
      txMap.put(txId, info);
    }
    return null;
  }
  @Override
  public Response processEndTransaction(TransactionInfo info) throws Exception {
    protocolManager.endTransaction(info);
    TransactionId txId = info.getTransactionId();

    if (!txMap.containsKey(txId)) {
      txMap.put(txId, info);
    }
    return null;
  }
示例#6
0
  /**
   * Commits all work done in this transaction and releases any locks currently held.
   *
   * @throws JMSException if the JMS provider fails to commit the transaction due to some internal
   *     error.
   * @throws javax.jms.IllegalStateException if the method is not called by a transacted session.
   */
  public void commit() throws JMSException {
    if (isInXATransaction()) {
      throw new TransactionInProgressException(
          "Cannot commit() if an XA transaction is already in progress ");
    }

    try {
      beforeEnd();
    } catch (JMSException e) {
      rollback();
      throw e;
    }

    if (transactionId != null && rollbackOnly) {
      final String message =
          "Commit of "
              + transactionId
              + "  failed due to rollback only request; typically due to failover with pending acks";
      try {
        rollback();
      } finally {
        LOG.warn(message);
        throw new TransactionRolledBackException(message);
      }
    }

    // Only send commit if the transaction was started.
    if (transactionId != null) {
      LOG.debug(
          "Commit: {} syncCount: {}",
          transactionId,
          (synchronizations != null ? synchronizations.size() : 0));

      TransactionInfo info =
          new TransactionInfo(getConnectionId(), transactionId, TransactionInfo.COMMIT_ONE_PHASE);
      this.transactionId = null;
      // Notify the listener that the tx was committed back
      try {
        this.connection.syncSendPacket(info);
        if (localTransactionEventListener != null) {
          localTransactionEventListener.commitEvent();
        }
        afterCommit();
      } catch (JMSException cause) {
        LOG.info("commit failed for transaction {}", info.getTransactionId(), cause);
        if (localTransactionEventListener != null) {
          localTransactionEventListener.rollbackEvent();
        }
        afterRollback();
        throw cause;
      }
    }
  }