Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -395,7 +395,9 @@ private static boolean toBoolean(Object prop, boolean defaultVal) {

public static int getTransactionSupportFromRaXml(String rarName) throws ConnectorRuntimeException {
ConnectorDescriptor descriptor = ConnectorRuntime.getRuntime().getConnectorDescriptor(rarName);
String txSupport = descriptor.getOutboundResourceAdapter().getTransSupport();
String txSupport = descriptor == null || descriptor.getOutboundResourceAdapter() == null
? null
: descriptor.getOutboundResourceAdapter().getTransSupport();
return parseTransactionSupportString(txSupport);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* @author Sivakumar Thyagarajan
*/
public abstract class AbstractConnectorAllocator implements ResourceAllocator {
protected final static Logger LOG = LogDomains.getLogger(AbstractConnectorAllocator.class,LogDomains.RSR_LOGGER);
protected static final Logger LOG = LogDomains.getLogger(AbstractConnectorAllocator.class,LogDomains.RSR_LOGGER);

protected PoolManager poolMgr;
protected ResourceSpec spec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;

import static java.util.logging.Level.FINEST;

/**
* LocalTransaction Connector Allocator, used for transaction level:
* {@link com.sun.appserv.connectors.internal.api.ConnectorConstants#LOCAL_TRANSACTION_INT}.
Expand All @@ -51,7 +53,7 @@ public class LocalTxConnectorAllocator extends AbstractConnectorAllocator {
private static final String COMMIT = "COMMIT";
private static final String ROLLBACK = "ROLLBACK";

private static String transactionCompletionMode = System
private static final String TX_COMPLETION_MODE = System
.getProperty("com.sun.enterprise.in-progress-local-transaction.completion-mode");

private final boolean shareable;
Expand All @@ -69,6 +71,10 @@ public LocalTxConnectorAllocator(PoolManager poolMgr,
this.shareable = shareable;
}

@Override
public boolean shareableWithinComponent() {
return shareable;
}

@Override
public ResourceHandle createResource() throws PoolingException {
Expand All @@ -90,68 +96,56 @@ public ResourceHandle createResource() throws PoolingException {
}

@Override
public void fillInResourceObjects(ResourceHandle resource)
throws PoolingException {
public void fillInResourceObjects(ResourceHandle handle) throws PoolingException {
try {
ManagedConnection mc = resource.getResource();
ManagedConnection mc = handle.getResource();
Object con = mc.getConnection(subject, reqInfo);
ConnectorXAResource xares = (ConnectorXAResource) resource.getXAResource();
ConnectorXAResource xares = (ConnectorXAResource) handle.getXAResource();
xares.setUserHandle(con);
resource.fillInResourceObjects(con, xares);
handle.fillInResourceObjects(con, xares);
} catch (ResourceException ex) {
throw new PoolingException(ex);
}
}

@Override
public void destroyResource(ResourceHandle resource)
throws PoolingException {
public void destroyResource(ResourceHandle handle) throws PoolingException {
try {
ManagedConnection mc = resource.getResource();
XAResource xares = resource.getXAResource();
forceTransactionCompletion(xares);
mc.destroy();
LOG.finest("destroyResource for LocalTxConnectorAllocator done");

ManagedConnection connection = handle.getResource();
XAResource xaResource = handle.getXAResource();
forceTransactionCompletion(xaResource);
connection.destroy();
LOG.log(FINEST, "Connection was destroyed: {0}", connection);
} catch (Exception ex) {
throw new PoolingException(ex);
}
}

@Override
public boolean shareableWithinComponent() {
return shareable;
}

private void forceTransactionCompletion(XAResource xares) throws SystemException {
if(transactionCompletionMode != null){
if(xares instanceof ConnectorXAResource){
ConnectorXAResource connectorXARes = (ConnectorXAResource)xares;
JavaEETransaction j2eetran = connectorXARes.getAssociatedTransaction();
if(j2eetran != null && j2eetran.isLocalTx()){
if(j2eetran.getStatus() == (Status.STATUS_ACTIVE)){
try{
if(transactionCompletionMode.equalsIgnoreCase(COMMIT)){
if(LOG.isLoggable(Level.FINEST)){
LOG.log(Level.FINEST,"Transaction Completion Mode for LocalTx resource is " +
"set as COMMIT, committing transaction");
}
j2eetran.commit();
}else if(transactionCompletionMode.equalsIgnoreCase(ROLLBACK)){
if(LOG.isLoggable(Level.FINEST)){
LOG.log(Level.FINEST,"Transaction Completion Mode for LocalTx resource is " +
"set as ROLLBACK, rolling back transaction");
}
j2eetran.rollback();
}else{
LOG.log(Level.WARNING,"Unknown transaction completion mode, no action made");
}
}catch(Exception e){
LOG.log(Level.WARNING, "Failure while forcibily completing an incomplete, " +
"local transaction ", e);
}
}
private void forceTransactionCompletion(XAResource xaResource) throws SystemException {
if (TX_COMPLETION_MODE == null) {
return;
}
if (xaResource instanceof ConnectorXAResource) {
ConnectorXAResource connectorXARes = (ConnectorXAResource) xaResource;
JavaEETransaction j2eetran = connectorXARes.getAssociatedTransaction();
if (j2eetran == null || !j2eetran.isLocalTx() || j2eetran.getStatus() != Status.STATUS_ACTIVE) {
return;
}
try {
if (COMMIT.equalsIgnoreCase(TX_COMPLETION_MODE)) {
LOG.log(FINEST, "Transaction Completion Mode for LocalTx resource is set as COMMIT,"
+ " committing transaction");
j2eetran.commit();
} else if (ROLLBACK.equalsIgnoreCase(TX_COMPLETION_MODE)) {
LOG.log(FINEST, "Transaction Completion Mode for LocalTx resource is set as ROLLBACK,"
+ " rolling back transaction");
j2eetran.rollback();
} else {
LOG.log(Level.WARNING, "Unknown transaction completion mode, no action made");
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Failure while forcibily completing an incomplete, local transaction ", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,34 +199,34 @@ protected synchronized void freeUnenlistedResource(ResourceHandle resourceHandle
/**
* destroys the resource
*
* @param resourceHandle resource to be destroyed
* @param handle resource to be destroyed
*/
@Override
public void deleteResource(ResourceHandle resourceHandle) {
public void deleteResource(ResourceHandle handle) {
try {
super.deleteResource(resourceHandle);
super.deleteResource(handle);
} finally {
if (resourceHandle instanceof AssocWithThreadResourceHandle) {
((AssocWithThreadResourceHandle) resourceHandle).setUnusable();
if (handle instanceof AssocWithThreadResourceHandle) {
((AssocWithThreadResourceHandle) handle).setUnusable();
}
}
}

/**
* to associate a resource with the thread
*
* @param h ResourceHandle
* @param handle ResourceHandle
*/
private void setInThreadLocal(AssocWithThreadResourceHandle h) {
if (h == null) {
private void setInThreadLocal(AssocWithThreadResourceHandle handle) {
if (handle == null) {
return;
}
h.lock();
handle.lock();
try {
h.setAssociated(true);
localResource.set(h);
handle.setAssociated(true);
localResource.set(handle);
} finally {
h.unlock();
handle.unlock();
}
}

Expand All @@ -250,7 +250,7 @@ private ResourceHandle resolvePossibleRemoval(ResourceHandle handle) {
}
}

private synchronized ResourceHandle searchFreeUnenlisted(ResourceAllocator alloc) {
private synchronized ResourceHandle searchFreeUnenlisted(ResourceAllocator allocator) {
for (ResourceHandle handle : dataStructure.getAllResources()) {
handle.lock();
try {
Expand All @@ -262,7 +262,7 @@ private synchronized ResourceHandle searchFreeUnenlisted(ResourceAllocator alloc

if (handle.getResourceState().isEnlisted() || handle.getResourceState().isBusy()
|| handle.hasConnectionErrorOccurred() || ((AssocWithThreadResourceHandle) handle).isUnusable()
|| !matchConnection(handle, alloc)) {
|| !matchConnection(handle, allocator)) {
continue;
}
setResourceStateToBusy(handle);
Expand Down
Loading