Search in sources :

Example 16 with ResourceHandle

use of com.sun.enterprise.resource.ResourceHandle in project Payara by payara.

the class Resizer method scaleDownPool.

/**
 * Scale down pool by a <code>size &lt;= 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--;
        }
    }
}
Also used : ResourceHandle(com.sun.enterprise.resource.ResourceHandle)

Example 17 with ResourceHandle

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);
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ResourceException(javax.resource.ResourceException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) HashSet(java.util.HashSet)

Example 18 with ResourceHandle

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);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ResourceException(javax.resource.ResourceException)

Example 19 with ResourceHandle

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);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) ConnectionEventListener(com.sun.enterprise.resource.listener.ConnectionEventListener)

Example 20 with ResourceHandle

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;
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ResourceState(com.sun.enterprise.resource.ResourceState)

Aggregations

ResourceHandle (com.sun.enterprise.resource.ResourceHandle)36 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)11 ResourceException (javax.resource.ResourceException)9 ResourceState (com.sun.enterprise.resource.ResourceState)6 JavaEETransaction (com.sun.enterprise.transaction.api.JavaEETransaction)5 HashSet (java.util.HashSet)5 AssocWithThreadResourceHandle (com.sun.enterprise.resource.AssocWithThreadResourceHandle)4 ManagedConnection (javax.resource.spi.ManagedConnection)3 RetryableUnavailableException (javax.resource.spi.RetryableUnavailableException)3 ResourceSpec (com.sun.enterprise.resource.ResourceSpec)2 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)2 Set (java.util.Set)2 InvocationException (org.glassfish.api.invocation.InvocationException)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 XAResourceWrapper (com.sun.enterprise.resource.XAResourceWrapper)1 ConnectionEventListener (com.sun.enterprise.resource.listener.ConnectionEventListener)1 PoolManager (com.sun.enterprise.resource.pool.PoolManager)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Iterator (java.util.Iterator)1 List (java.util.List)1