Search in sources :

Example 1 with MuleXaObject

use of org.mule.runtime.api.tx.MuleXaObject in project mule by mulesoft.

the class XaTransaction method bindResource.

/**
 * @param key Must be the provider of the resource object. i.e. for JDBC it's the XADataSource, for JMS is the
 *        XAConnectionFactory. It can be a wrapper in which case should be a
 *        {@link XaResourceFactoryHolder} to be able to determine correctly if there's already a
 *        resource for that {@link javax.transaction.xa.XAResource} provider.
 * @param resource the resource object. It must be an {@link javax.transaction.xa.XAResource} or a
 *        {@link MuleXaObject}
 * @throws TransactionException
 */
public synchronized void bindResource(Object key, Object resource) throws TransactionException {
    ResourceKey normalizedKey = getResourceEntry(key, resource);
    if (resources.containsKey(key)) {
        throw new IllegalTransactionStateException(CoreMessages.transactionResourceAlreadyListedForKey(key));
    }
    resources.put(normalizedKey, resource);
    if (key == null) {
        logger.error("Key for bound resource " + resource + " is null");
    }
    if (resource instanceof MuleXaObject) {
        MuleXaObject xaObject = (MuleXaObject) resource;
        xaObject.enlist();
    } else if (resource instanceof XAResource) {
        enlistResource((XAResource) resource);
    } else {
        logger.error("Bound resource " + resource + " is neither a MuleXaObject nor XAResource");
    }
}
Also used : MuleXaObject(org.mule.runtime.api.tx.MuleXaObject) XAResource(javax.transaction.xa.XAResource) IllegalTransactionStateException(org.mule.runtime.core.privileged.transaction.xa.IllegalTransactionStateException)

Example 2 with MuleXaObject

use of org.mule.runtime.api.tx.MuleXaObject in project mule by mulesoft.

the class XaTransaction method delistResources.

protected void delistResources() {
    for (Object o : resources.entrySet()) {
        Map.Entry entry = (Map.Entry) o;
        final Object xaObject = entry.getValue();
        if (xaObject instanceof MuleXaObject) {
            // there is need for reuse object
            try {
                ((MuleXaObject) xaObject).delist();
            } catch (Exception e) {
                logger.error("Failed to delist resource " + xaObject, e);
            }
        }
    }
}
Also used : MuleXaObject(org.mule.runtime.api.tx.MuleXaObject) MuleXaObject(org.mule.runtime.api.tx.MuleXaObject) HashMap(java.util.HashMap) Map(java.util.Map) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) InvalidTransactionException(javax.transaction.InvalidTransactionException) TransactionException(org.mule.runtime.api.tx.TransactionException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) TransactionStatusException(org.mule.runtime.core.api.transaction.TransactionStatusException) TransactionRollbackException(org.mule.runtime.core.api.transaction.TransactionRollbackException) XAException(javax.transaction.xa.XAException) IllegalTransactionStateException(org.mule.runtime.core.privileged.transaction.xa.IllegalTransactionStateException)

Example 3 with MuleXaObject

use of org.mule.runtime.api.tx.MuleXaObject in project mule by mulesoft.

the class XaTransaction method closeResources.

protected void closeResources() {
    Iterator i = resources.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        final Object value = entry.getValue();
        if (value instanceof MuleXaObject) {
            MuleXaObject xaObject = (MuleXaObject) value;
            if (!xaObject.isReuseObject()) {
                try {
                    xaObject.close();
                    i.remove();
                } catch (Exception e) {
                    logger.error("Failed to close resource " + xaObject, e);
                }
            }
        }
    }
}
Also used : MuleXaObject(org.mule.runtime.api.tx.MuleXaObject) Iterator(java.util.Iterator) MuleXaObject(org.mule.runtime.api.tx.MuleXaObject) HashMap(java.util.HashMap) Map(java.util.Map) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) InvalidTransactionException(javax.transaction.InvalidTransactionException) TransactionException(org.mule.runtime.api.tx.TransactionException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) TransactionStatusException(org.mule.runtime.core.api.transaction.TransactionStatusException) TransactionRollbackException(org.mule.runtime.core.api.transaction.TransactionRollbackException) XAException(javax.transaction.xa.XAException) IllegalTransactionStateException(org.mule.runtime.core.privileged.transaction.xa.IllegalTransactionStateException)

Aggregations

MuleXaObject (org.mule.runtime.api.tx.MuleXaObject)3 IllegalTransactionStateException (org.mule.runtime.core.privileged.transaction.xa.IllegalTransactionStateException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)2 InvalidTransactionException (javax.transaction.InvalidTransactionException)2 RollbackException (javax.transaction.RollbackException)2 SystemException (javax.transaction.SystemException)2 XAException (javax.transaction.xa.XAException)2 TransactionException (org.mule.runtime.api.tx.TransactionException)2 TransactionRollbackException (org.mule.runtime.core.api.transaction.TransactionRollbackException)2 TransactionStatusException (org.mule.runtime.core.api.transaction.TransactionStatusException)2 Iterator (java.util.Iterator)1 XAResource (javax.transaction.xa.XAResource)1