Search in sources :

Example 1 with PoolingException

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

the class ResourceManagerImpl method getTransaction.

/**
 * Returns the transaction component is participating.
 *
 * @return Handle to the <code>Transaction</code> object.
 * @exception <code>PoolingException<code>
 */
public Transaction getTransaction() throws PoolingException {
    InvocationManager invmgr = ConnectorRuntime.getRuntime().getInvocationManager();
    ComponentInvocation inv = invmgr.getCurrentInvocation();
    if (inv == null) {
        try {
            return ConnectorRuntime.getRuntime().getTransaction();
        } catch (Exception ex) {
            return null;
        }
    }
    return (Transaction) inv.getTransaction();
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) InvocationException(org.glassfish.api.invocation.InvocationException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException)

Example 2 with PoolingException

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

the class ResourceManagerImpl method unregisterResource.

/**
 * Unregister the <code>ResourceHandle</code> from the transaction
 *
 * @param resource	<code>ResourceHandle</code> object
 * @param xaresFlag flag indicating transaction success. This can
 *        be XAResource.TMSUCCESS or XAResource.TMFAIL
 * @exception <code>PoolingException</code>
 */
public void unregisterResource(ResourceHandle resource, int xaresFlag) {
    JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
    Transaction tran = null;
    try {
        // delist with TMSUCCESS if necessary
        if (resource.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.unregisterComponentResource(resource);
            }
            if (tran != null && resource.isEnlisted()) {
                tm.delistResource(tran, resource, xaresFlag);
            }
        }
    } catch (SystemException ex) {
        _logger.log(Level.WARNING, "poolmgr.system_exception", ex);
    } catch (IllegalStateException ex) {
    // transaction aborted. Do nothing
    } catch (InvocationException ex) {
    // unregisterResource is called outside of component context
    // likely to be container-forced destroy. Do nothing
    }
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationException(org.glassfish.api.invocation.InvocationException) 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 3 with PoolingException

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

the class ConnectionPool method getResource.

/**
 * returns resource from the pool.
 *
 * @return a free pooled resource object matching the ResourceSpec
 * @throws PoolingException - if any error occurrs
 *                          - or the pool has reached its max size and the
 *                          max-connection-wait-time-in-millis has expired.
 */
public ResourceHandle getResource(ResourceSpec spec, ResourceAllocator alloc, Transaction txn) throws PoolingException, RetryableUnavailableException {
    // Note: this method should not be synchronized or the
    // startTime would be incorrect for threads waiting to enter
    /*
        * Here are all the comments for the method put together for
        * easy reference.
        *  1.
           // - Try to get a free resource. Note: internalGetResource()
           // will create a new resource if none is free and the max has
           // not been reached.
           // - If can't get one, get on the wait queue.
           // - Repeat this until maxWaitTime expires.
           // - If maxWaitTime == 0, repeat indefinitely.

           2.
           //the doFailAllConnectionsProcessing method would already
           //have been invoked by now.
           //We simply go ahead and create a new resource here
           //from the allocator that we have and adjust the resources
           //list accordingly so as to not exceed the maxPoolSize ever
           //(i.e if steadyPoolSize == maxPoolSize )
           ///Also since we are creating the resource out of the allocator
           //that we came into this method with, we need not worry about
           //matching
        */
    ResourceHandle result = null;
    long startTime = System.currentTimeMillis();
    long elapsedWaitTime;
    long remainingWaitTime = 0;
    while (true) {
        if (gateway.allowed()) {
            // See comment #1 above
            JavaEETransaction jtx = ((JavaEETransaction) txn);
            Set resourcesSet = null;
            if (jtx != null) {
                resourcesSet = jtx.getResources(poolInfo);
            }
            // already obtained in the current transaction.
            if (!blocked || (resourcesSet != null && resourcesSet.size() > 0)) {
                try {
                    result = internalGetResource(spec, alloc, txn);
                } finally {
                    gateway.acquiredResource();
                }
            }
        }
        if (result != null) {
            // got one, return it
            if (poolLifeCycleListener != null) {
                poolLifeCycleListener.connectionAcquired(result.getId());
                elapsedWaitTime = System.currentTimeMillis() - startTime;
                poolLifeCycleListener.connectionRequestServed(elapsedWaitTime);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Resource Pool: elapsed time " + "(ms) to get connection for [" + spec + "] : " + elapsedWaitTime);
                }
            }
            // return it
            break;
        } else {
            // did not get a resource.
            if (maxWaitTime > 0) {
                elapsedWaitTime = System.currentTimeMillis() - startTime;
                if (elapsedWaitTime < maxWaitTime) {
                    // time has not expired, determine remaining wait time.
                    remainingWaitTime = maxWaitTime - elapsedWaitTime;
                } else {
                    if (!blocked) {
                        // wait time has expired
                        if (poolLifeCycleListener != null) {
                            poolLifeCycleListener.connectionTimedOut();
                        }
                        String msg = localStrings.getStringWithDefault("poolmgr.no.available.resource", "No available resource. Wait-time expired.");
                        throw new PoolingException(msg);
                    }
                }
            }
            if (!blocked) {
                // add to wait-queue
                Object waitMonitor = new Object();
                if (poolLifeCycleListener != null) {
                    poolLifeCycleListener.connectionRequestQueued();
                }
                synchronized (waitMonitor) {
                    waitQueue.addToQueue(waitMonitor);
                    try {
                        logFine("Resource Pool: getting on wait queue");
                        waitMonitor.wait(remainingWaitTime);
                    } catch (InterruptedException ex) {
                        // Could be system shutdown.
                        break;
                    }
                    // so the overhead for removing inexistant objects is low.
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "removing wait monitor from queue: " + waitMonitor);
                    }
                    if (waitQueue.removeFromQueue(waitMonitor)) {
                        if (poolLifeCycleListener != null) {
                            poolLifeCycleListener.connectionRequestDequeued();
                        }
                    }
                }
            } else {
                // add to reconfig-wait-queue
                Object reconfigWaitMonitor = new Object();
                synchronized (reconfigWaitMonitor) {
                    reconfigWaitQueue.addToQueue(reconfigWaitMonitor);
                    try {
                        if (reconfigWaitTime > 0) {
                            if (_logger.isLoggable(Level.FINEST)) {
                                _logger.finest("[DRC] getting into reconfig wait queue for time [" + reconfigWaitTime + "]");
                            }
                            reconfigWaitMonitor.wait(reconfigWaitTime);
                        }
                    } catch (InterruptedException ex) {
                        // Could be system shutdown.
                        break;
                    }
                    // so the overhead for removing inexistent objects is low.
                    if (_logger.isLoggable(Level.FINEST)) {
                        _logger.log(Level.FINEST, "[DRC] removing wait monitor from reconfig-wait-queue: " + reconfigWaitMonitor);
                    }
                    reconfigWaitQueue.removeFromQueue(reconfigWaitMonitor);
                    if (_logger.isLoggable(Level.FINEST)) {
                        _logger.log(Level.FINEST, "[DRC] throwing Retryable-Unavailable-Exception");
                    }
                    RetryableUnavailableException rue = new RetryableUnavailableException("Pool Reconfigured, " + "Connection Factory can retry the lookup");
                    rue.setErrorCode(BadConnectionEventListener.POOL_RECONFIGURED_ERROR_CODE);
                    throw rue;
                }
            }
        }
    }
    alloc.fillInResourceObjects(result);
    return result;
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) RetryableUnavailableException(javax.resource.spi.RetryableUnavailableException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle)

Example 4 with PoolingException

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

the class ConnectionPool method cleanupResource.

protected boolean cleanupResource(ResourceHandle handle) {
    boolean cleanupSuccessful = true;
    // cleanup resource
    try {
        ResourceAllocator alloc = handle.getResourceAllocator();
        alloc.cleanup(handle);
    } catch (PoolingException ex) {
        Object[] params = new Object[] { poolInfo, ex };
        _logger.log(Level.WARNING, "cleanup.resource.failed", params);
        cleanupSuccessful = false;
        resourceErrorOccurred(handle);
    }
    return cleanupSuccessful;
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceAllocator(com.sun.enterprise.resource.allocator.ResourceAllocator)

Example 5 with PoolingException

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

the class ResourceGateway method initializeCustomResourceGatewayInPrivilegedMode.

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

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

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