Java Code Examples for javax.transaction.xa.XAResource#TMSUSPEND

The following examples show how to use javax.transaction.xa.XAResource#TMSUSPEND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalTx.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public synchronized boolean delistResource(XAResource xaResource, int flag) throws IllegalStateException, SystemException
{
    if (flag == XAResource.TMSUSPEND)
    {
        throw new SystemException("suspend not supported");
    }
    flag = this.status.preDelistCheck(this, flag);

    TxGroup manager = this.removeByCommitter(xaResource);
    if (manager == null)
    {
        throw new IllegalStateException("Cannot delist a resource that's not enlisted " + xaResource);
    }

    try
    {
        xaResource.end(manager.getBranchXid(), flag);
        return true;
    }
    catch (XAException e)
    {
        logger.warn("Unable to delist XAResource " + xaResource + ", error code: " + e.errorCode, e);
        this.status = MARKED_ROLLBACK;
        return false;
    }
}
 
Example 2
Source File: MultiThreadedTx.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public synchronized boolean delistResource(XAResource xaResource, int flag) throws IllegalStateException, SystemException
{
    if (flag == XAResource.TMSUSPEND)
    {
        throw new SystemException("suspend not supported");
    }
    flag = this.status.get().preDelistCheck(this, flag);

    TxGroup manager = this.removeByCommitter(xaResource);
    if (manager == null)
    {
        throw new IllegalStateException("Cannot delist a resource that's not enlisted " + xaResource);
    }

    try
    {
        xaResource.end(manager.getBranchXid(), flag);
        return true;
    }
    catch (XAException e)
    {
        logger.warn("Unable to delist XAResource " + xaResource + ", error code: " + e.errorCode, e);
        this.status.set(MARKED_ROLLBACK);
        return false;
    }
}
 
Example 3
Source File: MultiThreadedTx.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public synchronized Future<Boolean> delistResource(FutureXaResource futureXaResource, int flag) throws IllegalStateException, SystemException
{
    if (flag == XAResource.TMSUSPEND)
    {
        throw new SystemException("suspend not supported");
    }
    flag = this.status.get().preDelistCheck(this, flag);

    TxGroup manager = this.removeByCommitter(futureXaResource.getDelegated());
    if (manager == null)
    {
        throw new IllegalStateException("Cannot delist a resource that's not enlisted " + futureXaResource.getDelegated());
    }

    try
    {
        return futureXaResource.end(manager.getBranchXid(), flag);
    }
    catch (XAException e)
    {
        logger.warn("Unable to delist XAResource " + futureXaResource.getDelegated() + ", error code: " + e.errorCode, e);
        this.status.set(MARKED_ROLLBACK);
        return FALSE_FUTURE;
    }
}
 
Example 4
Source File: ActiveMQSessionContext.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void xaEnd(Xid xid, int flags) throws XAException, ActiveMQException {
   Packet packet;
   if (flags == XAResource.TMSUSPEND) {
      packet = new PacketImpl(PacketImpl.SESS_XA_SUSPEND);
   } else if (flags == XAResource.TMSUCCESS) {
      packet = new SessionXAEndMessage(xid, false);
   } else if (flags == XAResource.TMFAIL) {
      packet = new SessionXAEndMessage(xid, true);
   } else {
      throw new XAException(XAException.XAER_INVAL);
   }

   SessionXAResponseMessage response = (SessionXAResponseMessage) sessionChannel.sendBlocking(packet, PacketImpl.SESS_XA_RESP);

   if (response.isError()) {
      throw new XAException(response.getResponseCode());
   }
}
 
Example 5
Source File: ClientSessionImpl.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private String convertTXFlag(final int flags) {
   if (flags == XAResource.TMSUSPEND) {
      return "SESS_XA_SUSPEND";
   } else if (flags == XAResource.TMSUCCESS) {
      return "TMSUCCESS";
   } else if (flags == XAResource.TMFAIL) {
      return "TMFAIL";
   } else if (flags == XAResource.TMJOIN) {
      return "TMJOIN";
   } else if (flags == XAResource.TMRESUME) {
      return "TMRESUME";
   } else if (flags == XAResource.TMNOFLAGS) {
      // Don't need to flush since the previous end will have done this
      return "TMNOFLAGS";
   } else {
      return "XAER_INVAL(" + flags + ")";
   }
}
 
Example 6
Source File: FBManagedConnection.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Dissociates a resource from a global transaction.
 *
 * @throws XAException
 *         Occurs when the state was not correct (end called twice), or the transaction ID is wrong.
 */
private void end(Xid id, int flags) throws XAException {
    if (flags != XAResource.TMSUCCESS && flags != XAResource.TMFAIL && flags != XAResource.TMSUSPEND)
        throw new FBXAException("flag not allowed in this context: " + flags + ", valid flags are TMSUCCESS, TMFAIL, TMSUSPEND", XAException.XAER_PROTO);
    internalEnd(id, flags);
    mcf.notifyEnd(this, id);
    inDistributedTransaction = false;

    try {
        // This will reset the managed environment of the associated connections and set the transaction coordinator to local
        // TODO This is a bit of a hack; need to find a better way
        setManagedEnvironment(isManagedEnvironment());
    } catch (SQLException ex) {
        throw new FBXAException("Reset of managed state failed", XAException.XAER_RMERR, ex);
    }
}
 
Example 7
Source File: LocalXAResource.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
public synchronized void end(Xid xid, int flags) throws XAException {
	if (xid == null) {
		throw new XAException(XAException.XAER_INVAL);
	} else if (this.currentXid == null) {
		throw new XAException(XAException.XAER_PROTO);
	} else if (!this.currentXid.equals(xid)) {
		throw new XAException(XAException.XAER_PROTO);
	} else if (flags == XAResource.TMSUSPEND) {
		this.suspendXid = xid;
		this.suspendAutoCommit = this.originalAutoCommit;
		this.currentXid = null;
		this.originalAutoCommit = true;
	} else if (flags == XAResource.TMSUCCESS) {
		// delay the logging operation to the commit phase.
		// this.createTransactionLogIfNecessary(xid);
	} else if (flags == XAResource.TMFAIL) {
		logger.debug("Error occurred while ending local-xa-resource.");
	} else {
		throw new XAException(XAException.XAER_PROTO);
	}
}
 
Example 8
Source File: TransactionCoordinator.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** supports suspend only, for tcc transaction manager. */
public void end(Xid xid, int flags) throws XAException {
	if (XAResource.TMSUSPEND != flags) {
		throw new XAException(XAException.XAER_INVAL);
	}
	TransactionManager transactionManager = this.beanFactory.getTransactionManager();
	XidFactory xidFactory = this.beanFactory.getXidFactory();
	Transaction transaction = transactionManager.getTransactionQuietly();
	if (transaction == null) {
		throw new XAException(XAException.XAER_NOTA);
	}
	TransactionContext transactionContext = transaction.getTransactionContext();
	TransactionXid transactionXid = transactionContext.getXid();

	TransactionXid branchXid = (TransactionXid) xid;
	TransactionXid globalXid = xidFactory.createGlobalXid(branchXid.getGlobalTransactionId());

	if (CommonUtils.equals(globalXid, transactionXid) == false) {
		throw new XAException(XAException.XAER_INVAL);
	}
	transactionManager.desociateThread();
}
 
Example 9
Source File: TxLogManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void end(Xid xid, int flags) throws XAException
{
   log.tracef("end(%s, %d)", xid, flags);

   if (flags == XAResource.TMSUCCESS)
   {
      addTxState(TX_XA_END_TMSUCCESS);
   }
   else if (flags == XAResource.TMFAIL)
   {
      addTxState(TX_XA_END_TMFAIL);
   }
   else if (flags == XAResource.TMSUSPEND)
   {
      addTxState(TX_XA_END_TMSUSPEND);
   }
   else
   {
      addTxState(TX_XA_END_UNKNOWN);
   }
}
 
Example 10
Source File: CloudSpannerXAConnection.java    From spanner-jdbc with MIT License 5 votes vote down vote up
/**
 * Preconditions: 1. Flags is one of TMSUCCESS, TMFAIL, TMSUSPEND 2. xid != null 3. Connection is
 * associated with transaction xid
 *
 * Implementation deficiency preconditions: 1. Flags is not TMSUSPEND
 *
 * Postconditions: 1. connection is disassociated from the transaction.
 * 
 * @see XAResource#end(Xid, int)
 */
@Override
public void end(Xid xid, int flags) throws XAException {
  if (logger.logDebug()) {
    debug("ending transaction xid = " + xid);
  }

  // Check preconditions

  if (flags != XAResource.TMSUSPEND && flags != XAResource.TMFAIL
      && flags != XAResource.TMSUCCESS) {
    throw new CloudSpannerXAException(CloudSpannerXAException.INVALID_FLAGS,
        Code.INVALID_ARGUMENT, XAException.XAER_INVAL);
  }

  if (xid == null) {
    throw new CloudSpannerXAException(CloudSpannerXAException.XID_NOT_NULL, Code.INVALID_ARGUMENT,
        XAException.XAER_INVAL);
  }

  if (state != STATE_ACTIVE || !currentXid.equals(xid)) {
    throw new CloudSpannerXAException(CloudSpannerXAException.END_WITHOUT_START,
        Code.FAILED_PRECONDITION, XAException.XAER_PROTO);
  }

  // Check implementation deficiency preconditions
  if (flags == XAResource.TMSUSPEND) {
    throw new CloudSpannerXAException(CloudSpannerXAException.SUSPEND_NOT_IMPLEMENTED,
        Code.UNIMPLEMENTED, XAException.XAER_RMERR);
  }

  // We ignore TMFAIL. It's just a hint to the RM. We could roll back
  // immediately
  // if TMFAIL was given.

  // All clear. We don't have any real work to do.
  state = STATE_ENDED;
}
 
Example 11
Source File: AbstractLuceneIndexerAndSearcherFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void end(Xid xid, int flag) throws XAException
{
    Map<StoreRef, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid);
    if (indexers == null)
    {
        if (suspendedIndexersInGlobalTx.containsKey(xid))
        {
            throw new XAException("Trying to commit indexes for a suspended transaction.");
        }
        else
        {
            // nothing to do
            return;
        }
    }
    if (flag == XAResource.TMSUSPEND)
    {
        activeIndexersInGlobalTx.remove(xid);
        suspendedIndexersInGlobalTx.put(xid, indexers);
    }
    else if (flag == TMFAIL)
    {
        activeIndexersInGlobalTx.remove(xid);
        suspendedIndexersInGlobalTx.remove(xid);
    }
    else if (flag == TMSUCCESS)
    {
        activeIndexersInGlobalTx.remove(xid);
    }
}
 
Example 12
Source File: FBManagedConnection.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * The {@code internalEnd} method ends the xid as requested if appropriate and throws a XAException including the
 * appropriate XA error code and a message if not. The caller can decode the exception as necessary.
 *
 * @param xid
 *         a {@code Xid} value
 * @param flags
 *         an {@code int} value
 * @throws XAException
 *         if an error occurs
 */
void internalEnd(Xid xid, int flags) throws XAException {
    if (log.isDebugEnabled()) log.debug("End called: " + xid);
    FbTransaction endingTr = xidMap.get(xid);

    if (endingTr == null) {
        throw new FBXAException("Unrecognized transaction", XAException.XAER_NOTA);
    }

    if (flags == XAResource.TMFAIL) {
        try {
            endingTr.rollback();
            getGDSHelper().setCurrentTransaction(null);
        } catch (SQLException ex) {
            throw new FBXAException("can't rollback transaction", XAException.XAER_RMFAIL, ex);
        }
    } else if (flags == XAResource.TMSUCCESS) {
        if (gdsHelper != null && endingTr == gdsHelper.getCurrentTransaction()) {
            gdsHelper.setCurrentTransaction(null);
        } else {
            throw new FBXAException("You are trying to end a transaction that is not the current transaction",
                    XAException.XAER_INVAL);
        }
    } else if (flags == XAResource.TMSUSPEND) {
        if (gdsHelper != null && endingTr == gdsHelper.getCurrentTransaction()) {
            gdsHelper.setCurrentTransaction(null);
        } else {
            throw new FBXAException("You are trying to suspend a transaction that is not the current transaction",
                    XAException.XAER_INVAL);
        }
    }
}
 
Example 13
Source File: TransactionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean delistResource(XAResourceArchive archive, int flag) throws SystemException {
	try {
		Xid branchXid = archive.getXid();

		logger.info("{}> delist: xares= {}, branch= {}, flags= {}",
				ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), archive,
				ByteUtils.byteArrayToString(branchXid.getBranchQualifier()), flag);

		switch (flag) {
		case XAResource.TMSUSPEND:
			archive.end(branchXid, flag);
			archive.setDelisted(true);
			archive.setSuspended(true);
			return true;
		case XAResource.TMFAIL:
			this.setRollbackOnlyQuietly();
		case XAResource.TMSUCCESS:
			archive.end(branchXid, flag);
			archive.setDelisted(true);
			return true;
		default:
			return false;
		}
	} catch (XAException xae) {
		logger.error("XATerminatorImpl.delistResource(XAResourceArchive, int)", xae);

		// Possible XAException values are XAER_RMERR, XAER_RMFAIL,
		// XAER_NOTA, XAER_INVAL, XAER_PROTO, or XA_RB*.
		switch (xae.errorCode) {
		case XAException.XAER_NOTA:
			// The specified XID is not known by the resource manager.
		case XAException.XAER_INVAL:
			// Invalid arguments were specified.
		case XAException.XAER_PROTO:
			// The routine was invoked in an improper context.
			return false;
		case XAException.XAER_RMFAIL:
			// An error occurred that makes the resource manager unavailable.
		case XAException.XAER_RMERR:
			// An error occurred in dissociating the transaction branch from the thread of control.
			return false; // throw new SystemException();
		default /* XA_RB* */ :
			return false; // throw new RollbackRequiredException();
		}
	} catch (RuntimeException ex) {
		logger.error("XATerminatorImpl.delistResource(XAResourceArchive, int)", ex);
		throw new SystemException();
	}
}