Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Pinčuk <alexander.v.pinchuk@gmail.com>
  • Loading branch information
avpinchuk committed May 10, 2023
1 parent 036b8d9 commit 5e036bb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
Expand Up @@ -17,14 +17,6 @@

package com.sun.enterprise.resource;

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

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;

import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;

import com.sun.appserv.connectors.internal.api.PoolingException;
import com.sun.enterprise.connectors.ConnectorRuntime;
import com.sun.enterprise.resource.allocator.LocalTxConnectorAllocator;
Expand All @@ -33,30 +25,42 @@
import com.sun.logging.LogDomains;

import jakarta.resource.spi.ConnectionEventListener;
import jakarta.resource.spi.DissociatableManagedConnection;
import jakarta.resource.spi.LazyEnlistableManagedConnection;
import jakarta.transaction.Transaction;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;

import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;

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

/**
* ResourceHandle encapsulates a resource connection. Equality on the handle is based on the id field
* ResourceHandle encapsulates a resource connection.
*
* <p>Equality on the handle is based on the id field.
*
* @author Tony Ng
*/
public class ResourceHandle implements com.sun.appserv.connectors.internal.api.ResourceHandle, TransactionalResource {

private static Logger logger = LogDomains.getLogger(ResourceHandle.class, LogDomains.RSR_LOGGER);
private static final Logger logger = LogDomains.getLogger(ResourceHandle.class, LogDomains.RSR_LOGGER);

// unique ID for resource handles
static private long idSequence;

private long id;
private ClientSecurityInfo info;
private Object resource; // represents MC
private final long id;
private final ClientSecurityInfo info;
private final Object resource; // represents MC
private ResourceSpec spec;
private XAResource xares;
private XAResource xaRes;
private Object userConnection; // represents connection-handle to user
private ResourceAllocator resourceAllocator;
private final ResourceAllocator resourceAllocator;
private Object instance; // the component instance holding this resource
private int shareCount; // sharing within a component (XA only)
private boolean supportsXAResource;
private final boolean supportsXAResource;

private final AtomicBoolean busy = new AtomicBoolean(false);

Expand Down Expand Up @@ -99,11 +103,11 @@ public ResourceHandle(Object resource, ResourceSpec spec, ResourceAllocator allo
supportsXAResource = true;
}

if (resource instanceof jakarta.resource.spi.LazyEnlistableManagedConnection) {
if (resource instanceof LazyEnlistableManagedConnection) {
supportsLazyEnlistment_ = true;
}

if (resource instanceof jakarta.resource.spi.DissociatableManagedConnection) {
if (resource instanceof DissociatableManagedConnection) {
supportsLazyAssoc_ = true;
}
}
Expand All @@ -117,8 +121,9 @@ public boolean isTransactional() {
}

/**
* To check whether lazy enlistment is suspended or not.<br>
* If true, TM will not do enlist/lazy enlist.
* To check whether lazy enlistment is suspended or not.
*
* <p>If {@code true}, TM will not do enlist/lazy enlist.
*
* @return boolean
*/
Expand All @@ -137,7 +142,7 @@ public void markForReclaim(boolean reclaim) {
}

/**
* To check if the resourceHandle is marked for leak reclaim or not. <br>
* To check if the resourceHandle is marked for leak reclaim or not.
*
* @return boolean
*/
Expand Down Expand Up @@ -172,7 +177,7 @@ public ResourceSpec getResourceSpec() {

@Override
public XAResource getXAResource() {
return xares;
return xaRes;
}

public Object getUserConnection() {
Expand Down Expand Up @@ -209,15 +214,14 @@ public void fillInResourceObjects(Object userConnection, XAResource xaRes) {
// all XA interactions - Don't wrap XAResourceWrapper if it is
// already wrapped
if ((xaRes instanceof XAResourceWrapper) || (xaRes instanceof ConnectorXAResource)) {
this.xares = xaRes;
this.xaRes = xaRes;
} else {
this.xares = new XAResourceWrapper(xaRes);
this.xaRes = new XAResourceWrapper(xaRes);
}
} else {
this.xares = xaRes;
this.xaRes = xaRes;
}
}

}

// For XA-capable connections, multiple connections within a
Expand Down
Expand Up @@ -30,13 +30,12 @@
import java.util.logging.Logger;

/**
* ReadWriteLock based datastructure for pool
* ReadWriteLock based datastructure for pool.
*
* @deprecated Incorrect locking. Note: ListDataStructure uses synchronization, better, but slow.
* @author Jagadish Ramu
*/
@Deprecated
public class RWLockDataStructure implements DataStructure {

private static final Logger LOG = LogDomains.getLogger(RWLockDataStructure.class, LogDomains.RSR_LOGGER);

private int maxSize;
Expand Down Expand Up @@ -69,9 +68,7 @@ public int addResource(ResourceAllocator allocator, int count) throws PoolingExc
numResAdded++;
}
} catch (Exception e) {
PoolingException pe = new PoolingException(e.getMessage());
pe.initCause(e);
throw pe;
throw new PoolingException(e.getMessage(), e);
} finally {
writeLock.unlock();
}
Expand All @@ -97,7 +94,7 @@ public ResourceHandle getResource() {

@Override
public void removeResource(ResourceHandle resource) {
boolean removed = false;
boolean removed;
writeLock.lock();
try {
removed = resources.remove(resource);
Expand All @@ -111,6 +108,7 @@ public void removeResource(ResourceHandle resource) {

@Override
public void returnResource(ResourceHandle resource) {
// We use write lock to prevent an unnecessary resize
writeLock.lock();
try{
resource.setBusy(false);
Expand All @@ -121,7 +119,7 @@ public void returnResource(ResourceHandle resource) {

@Override
public int getFreeListSize() {
//inefficient implementation.
// inefficient implementation.
int free = 0;
readLock.lock();
try{
Expand Down
Expand Up @@ -298,7 +298,7 @@ unable_to_determine_pool_type=RAR8067: Unable to determine pool type for pool [
RAR8067.diag.cause.1=Unable to determine type of pool (Default, Associated-with-thread, etc.)
RAR8067.diag.check.1=Message can be ignored as the processing can continue using the default pool type. \
Else check pool settings and any related messages in the server.log for more information.
pool.datastructure.rwlockds.init=initializing reentrant ds
pool.datastructure.rwlockds.init=initializing rwlock ds
gf.resources.module.scope.deployment.failure=RAR8069: Failed to create resources (defined in glassfish-resources.xml) bundled in module [ {0} ], of application [ {1} ] : [ {2} ]
RAR8069.diag.cause.1=Invalid resource definition
RAR8069.diag.check.1=Check whether attributes and properties of resource-definitions conform to the constraints
Expand Down

0 comments on commit 5e036bb

Please sign in to comment.