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");
}
}
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);
}
}
}
}
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);
}
}
}
}
}
Aggregations