Search in sources :

Example 26 with PoolingException

use of com.sun.appserv.connectors.internal.api.PoolingException in project Payara by payara.

the class PoolWaitQueueFactory method initializeCustomWaitQueueInPrivilegedMode.

private static PoolWaitQueue initializeCustomWaitQueueInPrivilegedMode(final String className) throws PoolingException {
    Object result = AccessController.doPrivileged(new PrivilegedAction() {

        public Object run() {
            Object result = null;
            try {
                result = initializeCustomWaitQueue(className);
            } catch (Exception e) {
                _logger.log(Level.WARNING, "pool.waitqueue.init.failure", className);
                _logger.log(Level.WARNING, "pool.waitqueue.init.failure.exception", e);
            }
            return result;
        }
    });
    if (result != null) {
        return (PoolWaitQueue) result;
    } else {
        throw new PoolingException("Unable to initalize custom PoolWaitQueue : " + className);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) PrivilegedAction(java.security.PrivilegedAction) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException)

Example 27 with PoolingException

use of com.sun.appserv.connectors.internal.api.PoolingException in project Payara by payara.

the class ResourceManagerImpl method registerResource.

/**
 * Register the <code>ResourceHandle</code> in the transaction
 *
 * @param handle	<code>ResourceHandle</code> object
 * @exception <code>PoolingException</code>
 */
public void registerResource(ResourceHandle handle) throws PoolingException {
    try {
        Transaction tran = null;
        JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
        // enlist if necessary
        if (handle.isTransactional()) {
            InvocationManager invmgr = ConnectorRuntime.getRuntime().getInvocationManager();
            ComponentInvocation inv = invmgr.getCurrentInvocation();
            if (inv == null) {
                // in that, you return the transaction from the TxManager
                try {
                    tran = tm.getTransaction();
                } catch (Exception e) {
                    tran = null;
                    _logger.log(Level.INFO, e.getMessage());
                }
            } else {
                tran = (Transaction) inv.getTransaction();
                tm.registerComponentResource(handle);
            }
            if (tran != null) {
                try {
                    tm.enlistResource(tran, handle);
                } catch (Exception ex) {
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.fine("Exception whle trying to enlist resource " + ex.getMessage());
                    }
                    // to enlist the resource
                    if (inv != null) {
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.fine("Attempting to unregister component resource");
                        }
                        tm.unregisterComponentResource(handle);
                    }
                    throw ex;
                }
            }
        }
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "poolmgr.component_register_exception", ex);
        throw new PoolingException(ex.toString(), ex);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) InvocationException(org.glassfish.api.invocation.InvocationException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException)

Example 28 with PoolingException

use of com.sun.appserv.connectors.internal.api.PoolingException in project Payara by payara.

the class ConnectionPool method createSingleResource.

/**
 * Method to be used to create resource, instead of calling ResourceAllocator.createConfigBean().
 * This method handles the connection creation retrial in case of failure
 *
 * @param resourceAllocator ResourceAllocator
 * @return ResourceHandle newly created resource
 * @throws PoolingException when unable create a resource
 */
protected ResourceHandle createSingleResource(ResourceAllocator resourceAllocator) throws PoolingException {
    ResourceHandle resourceHandle;
    int count = 0;
    long startTime = 0;
    while (true) {
        try {
            count++;
            startTime = System.currentTimeMillis();
            resourceHandle = resourceAllocator.createResource();
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Time taken to create a single " + "resource : " + resourceHandle.getResourceSpec().getResourceId() + " and adding to the pool (ms) : " + (System.currentTimeMillis() - startTime));
            }
            if (validation || validateAtmostEveryIdleSecs)
                resourceHandle.setLastValidated(System.currentTimeMillis());
            break;
        } catch (Exception ex) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Connection creation failed for " + count + " time. It will be retried, " + "if connection creation retrial is enabled.", ex);
            }
            if (!connectionCreationRetry_ || count > connectionCreationRetryAttempts_)
                throw new PoolingException(ex);
            try {
                Thread.sleep(conCreationRetryInterval_);
            } catch (InterruptedException ie) {
            // ignore this exception
            }
        }
    }
    return resourceHandle;
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) RetryableUnavailableException(javax.resource.spi.RetryableUnavailableException)

Example 29 with PoolingException

use of com.sun.appserv.connectors.internal.api.PoolingException in project Payara by payara.

the class ConnectionPool method getPoolConfigurationFromJndi.

protected ConnectorConnectionPool getPoolConfigurationFromJndi(Hashtable env) throws PoolingException {
    ConnectorConnectionPool poolResource;
    try {
        String jndiNameOfPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
        poolResource = (ConnectorConnectionPool) ConnectorRuntime.getRuntime().getResourceNamingService().lookup(poolInfo, jndiNameOfPool, env);
    } catch (NamingException ex) {
        throw new PoolingException(ex);
    }
    return poolResource;
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ConnectorConnectionPool(com.sun.enterprise.connectors.ConnectorConnectionPool) NamingException(javax.naming.NamingException)

Example 30 with PoolingException

use of com.sun.appserv.connectors.internal.api.PoolingException in project Payara by payara.

the class PoolManagerImpl method getResource.

// invoked by DataSource objects to obtain a connection
public Object getResource(ResourceSpec spec, ResourceAllocator alloc, ClientSecurityInfo info) throws PoolingException, RetryableUnavailableException {
    Transaction tran = null;
    boolean transactional = alloc.isTransactional();
    if (transactional) {
        tran = getResourceManager(spec).getTransaction();
    }
    ResourceHandle handle = getResourceFromPool(spec, alloc, info, tran);
    if (!handle.supportsLazyAssociation()) {
        spec.setLazyAssociatable(false);
    }
    if (spec.isLazyAssociatable() && spec.getConnectionToAssociate() != null) {
        // we need to associate a new connection with it
        try {
            Object connection = spec.getConnectionToAssociate();
            ManagedConnection dmc = (ManagedConnection) handle.getResource();
            dmc.associateConnection(connection);
        } catch (ResourceException e) {
            putbackDirectToPool(handle, spec.getPoolInfo());
            PoolingException pe = new PoolingException(e.getMessage());
            pe.initCause(e);
            throw pe;
        }
    }
    // we cannot either
    if (!handle.supportsLazyEnlistment()) {
        spec.setLazyEnlistable(false);
    }
    handle.setResourceSpec(spec);
    try {
        if (handle.getResourceState().isUnenlisted()) {
            // The spec being used here is the spec with the updated
            // lazy enlistment info
            // Here's the real place where we care about the correct
            // resource manager (which in turn depends upon the ResourceSpec)
            // and that's because if lazy enlistment needs to be done
            // we need to get the LazyEnlistableResourceManager
            getResourceManager(spec).enlistResource(handle);
        }
    } catch (Exception e) {
        // In the rare cases where enlistResource throws exception, we
        // should throw the resource away
        putbackBadResourceToPool(handle);
        _logger.log(Level.WARNING, "poolmgr.err_enlisting_res_in_getconn", spec.getPoolInfo());
        logFine("rm.enlistResource threw Exception. Evicting resource from pool");
        // and rethrow the exception
        throw new PoolingException(e);
    }
    return handle.getUserConnection();
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) Transaction(javax.transaction.Transaction) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) InvocationException(org.glassfish.api.invocation.InvocationException) RetryableUnavailableException(javax.resource.spi.RetryableUnavailableException)

Aggregations

PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)32 ResourceException (javax.resource.ResourceException)17 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)9 ManagedConnection (javax.resource.spi.ManagedConnection)7 InvocationException (org.glassfish.api.invocation.InvocationException)5 PrivilegedAction (java.security.PrivilegedAction)4 RetryableUnavailableException (javax.resource.spi.RetryableUnavailableException)4 JavaEETransaction (com.sun.enterprise.transaction.api.JavaEETransaction)3 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)3 NamingException (javax.naming.NamingException)3 SystemException (javax.transaction.SystemException)3 XAResource (javax.transaction.xa.XAResource)3 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)3 InvocationManager (org.glassfish.api.invocation.InvocationManager)3 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)2 ResourceSpec (com.sun.enterprise.resource.ResourceSpec)2 ConnectionEventListener (com.sun.enterprise.resource.listener.ConnectionEventListener)2 PoolManager (com.sun.enterprise.resource.pool.PoolManager)2 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)2 Transaction (javax.transaction.Transaction)2