use of com.sun.enterprise.resource.ResourceState in project Payara by payara.
the class Resizer method isResourceEligibleForRemoval.
protected boolean isResourceEligibleForRemoval(ResourceHandle h, int validConnectionsCounter) {
boolean isResourceEligibleForRemoval = false;
ResourceState state = h.getResourceState();
// remove all idle-time lapsed resources.
ResourceAllocator alloc = h.getResourceAllocator();
if (preferValidateOverRecreate && alloc.hasValidatingMCF()) {
// is valid but only till the steady pool size.
if (validConnectionsCounter < pool.getSteadyPoolSize() && alloc.isConnectionValid(h)) {
h.setLastValidated(System.currentTimeMillis());
state.touchTimestamp();
} else {
// Connection invalid and hence remove resource.
if (_logger.isLoggable(Level.FINEST)) {
if (validConnectionsCounter <= pool.getSteadyPoolSize()) {
_logger.log(Level.FINEST, "PreferValidateOverRecreate: " + "Removing idle resource " + h + " from the free pool as the RA reports it to be invalid");
} else {
_logger.log(Level.FINEST, "PreferValidateOverRecreate: " + "Removing idle resource " + h + " from the free pool as the steady part size has " + "already been exceeded (" + validConnectionsCounter + " > " + pool.getSteadyPoolSize() + ")");
}
}
isResourceEligibleForRemoval = true;
}
} else {
isResourceEligibleForRemoval = true;
}
return isResourceEligibleForRemoval;
}
use of com.sun.enterprise.resource.ResourceState in project Payara by payara.
the class PoolTxHelper method resourceEnlisted.
/**
* this method is called when a resource is enlisted in
* transation tran
* @param tran Transaction to which the resource need to be enlisted
* @param resource Resource to be enlisted in the transaction
*/
public void resourceEnlisted(Transaction tran, ResourceHandle resource) {
try {
JavaEETransaction j2eetran = (JavaEETransaction) tran;
Set set = j2eetran.getResources(poolInfo);
if (set == null) {
set = new HashSet();
j2eetran.setResources(set, poolInfo);
}
set.add(resource);
} catch (ClassCastException e) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Pool [ " + poolInfo + " ]: resourceEnlisted:" + "transaction is not J2EETransaction but a " + tran.getClass().getName(), e);
}
}
ResourceState state = resource.getResourceState();
state.setEnlisted(true);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Pool [ " + poolInfo + " ]: resourceEnlisted: " + resource);
}
}
use of com.sun.enterprise.resource.ResourceState 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;
}
use of com.sun.enterprise.resource.ResourceState in project Payara by payara.
the class ConnectionPool method createResource.
public ResourceHandle createResource(ResourceAllocator alloc) throws PoolingException {
// NOTE : Pool should not call this method directly, it should be called only by pool-datastructure
ResourceHandle result = createSingleResource(alloc);
ResourceState state = new ResourceState();
state.setBusy(false);
state.setEnlisted(false);
result.setResourceState(state);
if (poolLifeCycleListener != null) {
poolLifeCycleListener.connectionCreated();
}
return result;
}
use of com.sun.enterprise.resource.ResourceState in project Payara by payara.
the class Resizer method removeIdleAndInvalidResources.
/**
* Get the free connections list from the pool, remove idle-timed-out resources
* and then invalid resources.
*
* @return int number of resources removed
*/
protected int removeIdleAndInvalidResources() {
int poolSizeBeforeRemoval = ds.getResourcesSize();
int noOfResourcesRemoved;
// Find all Connections that are free/not-in-use
ResourceState state;
int size = ds.getFreeListSize();
// let's cache the current time since precision is not required here.
long currentTime = System.currentTimeMillis();
int validConnectionsCounter = 0;
int idleConnKeptInSteadyCounter = 0;
// iterate through all thre active resources to find idle-time lapsed ones.
ResourceHandle h;
Set<ResourceHandle> activeResources = new HashSet<ResourceHandle>();
Set<String> resourcesToValidate = new HashSet<String>();
try {
while ((h = ds.getResource()) != null) {
state = h.getResourceState();
if (currentTime - state.getTimestamp() < pool.getIdleTimeout()) {
// Should be added for validation.
validConnectionsCounter++;
resourcesToValidate.add(h.toString());
activeResources.add(h);
} else {
boolean isResourceEligibleForRemoval = isResourceEligibleForRemoval(h, validConnectionsCounter);
if (!isResourceEligibleForRemoval) {
// preferValidateOverrecreate true and connection is valid within SPS
validConnectionsCounter++;
idleConnKeptInSteadyCounter++;
activeResources.add(h);
debug("PreferValidateOverRecreate: Keeping idle resource " + h + " in the steady part of the free pool " + "as the RA reports it to be valid (" + validConnectionsCounter + " <= " + pool.getSteadyPoolSize() + ")");
} else {
// Add to remove
ds.removeResource(h);
}
}
}
} finally {
for (ResourceHandle activeResource : activeResources) {
ds.returnResource(activeResource);
}
}
// remove invalid resources from the free (active) resources list.
// Since the whole pool is not locked, it may happen that some of these resources may be
// given to applications.
removeInvalidResources(resourcesToValidate);
// These statistic computations will work fine as long as resizer locks the pool throughout its operations.
if (preferValidateOverRecreate) {
debug("Idle resources validated and kept in the steady pool for pool [ " + poolInfo + " ] - " + idleConnKeptInSteadyCounter);
debug("Number of Idle resources freed for pool [ " + poolInfo + " ] - " + (size - activeResources.size() - idleConnKeptInSteadyCounter));
debug("Number of Invalid resources removed for pool [ " + poolInfo + " ] - " + (activeResources.size() - ds.getFreeListSize() + idleConnKeptInSteadyCounter));
} else {
debug("Number of Idle resources freed for pool [ " + poolInfo + " ] - " + (size - activeResources.size()));
debug("Number of Invalid resources removed for pool [ " + poolInfo + " ] - " + (activeResources.size() - ds.getFreeListSize()));
}
noOfResourcesRemoved = poolSizeBeforeRemoval - ds.getResourcesSize();
return noOfResourcesRemoved;
}
Aggregations