use of com.sun.enterprise.resource.ResourceHandle in project Payara by payara.
the class Resizer method scaleDownPool.
/**
* Scale down pool by a <code>size <= pool-resize-quantity</code>
*
* @param forced scale-down only when forced
* @param scaleDownQuantity no. of resources to remove
*/
protected void scaleDownPool(int scaleDownQuantity, boolean forced) {
if (pool.getResizeQuantity() > 0 && forced) {
scaleDownQuantity = (scaleDownQuantity <= (ds.getResourcesSize() - pool.getSteadyPoolSize())) ? scaleDownQuantity : 0;
ResourceHandle h;
while (scaleDownQuantity > 0 && ((h = ds.getResource()) != null)) {
ds.removeResource(h);
scaleDownQuantity--;
}
}
}
use of com.sun.enterprise.resource.ResourceHandle in project Payara by payara.
the class Resizer method removeInvalidResources.
/**
* Removes invalid resource handles in the pool while resizing the pool.
* Uses the Connector 1.5 spec 6.5.3.4 optional RA feature to obtain
* invalid ManagedConnections
*
* @param freeConnectionsToValidate Set of free connections
*/
private void removeInvalidResources(Set<String> freeConnectionsToValidate) {
try {
debug("Sending a set of free connections to RA, " + "of size : " + freeConnectionsToValidate.size());
int invalidConnectionsCount = 0;
ResourceHandle handle;
Set<ResourceHandle> validResources = new HashSet<ResourceHandle>();
try {
while ((handle = ds.getResource()) != null) {
// validate if the connection is one in the freeConnectionsToValidate
if (freeConnectionsToValidate.contains(handle.toString())) {
Set connectionsToTest = new HashSet();
connectionsToTest.add(handle.getResource());
Set invalidConnections = handler.getInvalidConnections(connectionsToTest);
if (invalidConnections != null && invalidConnections.size() > 0) {
invalidConnectionsCount = validateAndRemoveResource(handle, invalidConnections);
} else {
// valid resource, return to pool
validResources.add(handle);
}
} else {
// valid resource, return to pool
validResources.add(handle);
}
}
} finally {
for (ResourceHandle resourceHandle : validResources) {
ds.returnResource(resourceHandle);
}
validResources.clear();
debug("No. of invalid connections received from RA : " + invalidConnectionsCount);
}
} catch (ResourceException re) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "ResourceException while trying to get invalid connections from MCF", re);
}
} catch (Exception e) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Exception while trying to get invalid connections from MCF", e);
}
}
}
use of com.sun.enterprise.resource.ResourceHandle in project Payara by payara.
the class ConnectorAllocator method createResource.
public ResourceHandle createResource() throws PoolingException {
try {
ManagedConnection mc = mcf.createManagedConnection(subject, reqInfo);
ResourceHandle resource = createResourceHandle(mc, spec, this, info);
ConnectionEventListener l = new ConnectionListenerImpl(resource);
mc.addConnectionEventListener(l);
return resource;
} catch (ResourceException ex) {
Object[] params = new Object[] { spec.getPoolInfo(), ex.toString() };
_logger.log(Level.WARNING, "poolmgr.create_resource_error", params);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Resource Exception while creating resource", ex);
}
if (ex.getLinkedException() != null) {
_logger.log(Level.WARNING, "poolmgr.create_resource_linked_error", ex.getLinkedException().toString());
}
throw new PoolingException(ex);
}
}
use of com.sun.enterprise.resource.ResourceHandle in project Payara by payara.
the class NoTxConnectorAllocator method createResource.
public ResourceHandle createResource() throws PoolingException {
try {
ManagedConnection mc = mcf.createManagedConnection(subject, reqInfo);
ResourceHandle resource = createResourceHandle(mc, spec, this, info);
ConnectionEventListener l = new ConnectionListenerImpl(resource);
mc.addConnectionEventListener(l);
return resource;
} catch (ResourceException ex) {
Object[] params = new Object[] { spec.getPoolInfo(), ex.toString() };
_logger.log(Level.WARNING, "poolmgr.create_resource_error", params);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Resource Exception while creating resource", ex);
}
if (ex.getLinkedException() != null) {
_logger.log(Level.WARNING, "poolmgr.create_resource_linked_error", ex.getLinkedException().toString());
}
throw new PoolingException(ex);
}
}
use of com.sun.enterprise.resource.ResourceHandle in project Payara by payara.
the class PoolTxHelper method transactionCompleted.
/**
* this method is called when transaction tran is completed
* @param tran transaction which has completed
* @param status transaction status
* @param poolInfo Pool name
* @return delisted resources
*/
public List<ResourceHandle> transactionCompleted(Transaction tran, int status, PoolInfo poolInfo) {
JavaEETransaction j2eetran;
List<ResourceHandle> delistedResources = new ArrayList<ResourceHandle>();
try {
j2eetran = (JavaEETransaction) tran;
} catch (ClassCastException e) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Pool: transactionCompleted: " + "transaction is not J2EETransaction but a " + tran.getClass().getName(), e);
}
return delistedResources;
}
Set set = j2eetran.getResources(poolInfo);
if (set == null)
return delistedResources;
Iterator iter = set.iterator();
while (iter.hasNext()) {
ResourceHandle resource = (ResourceHandle) iter.next();
ResourceState state = resource.getResourceState();
state.setEnlisted(false);
delistedResources.add(resource);
iter.remove();
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Pool: transactionCompleted: " + resource);
}
}
return delistedResources;
}
Aggregations