Search in sources :

Example 21 with ResourceHandle

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

the class BasicResourceAllocator method createResource.

public ResourceHandle createResource(XAResource xaResource) throws PoolingException {
    ResourceHandle resourceHandle = null;
    ResourceSpec spec = new ResourceSpec(JMS_RESOURCE_FACTORY, ResourceSpec.JMS);
    if (xaResource != null) {
        logger.logp(Level.FINEST, "BasicResourceAllocator", "createResource", "NOT NULL", xaResource);
        try {
            resourceHandle = new ResourceHandle(// no object present
            null, spec, this, null);
            if (logger.isLoggable(Level.FINEST)) {
                xaResource = new XAResourceWrapper(xaResource);
            }
            resourceHandle.fillInResourceObjects(null, xaResource);
        } catch (Exception e) {
            throw (PoolingException) (new PoolingException()).initCause(e);
        }
    } else {
        logger.logp(Level.FINEST, "BasicResourceAllocator", "createResource", "NULL");
    }
    return resourceHandle;
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ResourceSpec(com.sun.enterprise.resource.ResourceSpec) XAResourceWrapper(com.sun.enterprise.resource.XAResourceWrapper) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException)

Example 22 with ResourceHandle

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

the class ConnectorMessageBeanClient method createEndpoint.

/**
 * {@inheritDoc}
 */
public MessageEndpoint createEndpoint(XAResource xaResource, long timeout) throws UnavailableException {
    synchronized (this) {
        while (myState == BLOCKED) {
            try {
                wait(timeout);
            } catch (Exception e) {
            // This exception should not affect the functionality.
            } finally {
                // Once the first thread comes out of wait, block is
                // is removed. This makes sure that the time for which the
                // the block remains is limited. Max 2x6000.
                myState = UNBLOCKED;
            }
        }
    }
    if (!started_) {
        logger.log(Level.WARNING, "endpointfactory.unavailable");
        throw new UnavailableException("EndpointFactory is currently not available");
    }
    MessageEndpoint endpoint = null;
    try {
        ResourceHandle resourceHandle = allocator_.createResource(xaResource);
        MessageBeanListener listener = messageBeanPM_.createMessageBeanListener(resourceHandle);
        MessageEndpointInvocationHandler handler = new MessageEndpointInvocationHandler(listener, messageBeanPM_);
        endpoint = (MessageEndpoint) messageBeanPM_.createMessageBeanProxy(handler);
    } catch (Exception ex) {
        throw (UnavailableException) (new UnavailableException()).initCause(ex);
    }
    return endpoint;
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) MessageBeanListener(org.glassfish.ejb.api.MessageBeanListener) UnavailableException(javax.resource.spi.UnavailableException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) UnavailableException(javax.resource.spi.UnavailableException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 23 with ResourceHandle

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

the class AssocWithThreadResourcePool method getUnenlistedResource.

// this is the RI getResource() with some modifications
/**
 * return resource in free list. If none is found, returns null
 */
protected ResourceHandle getUnenlistedResource(ResourceSpec spec, ResourceAllocator alloc, Transaction tran) throws PoolingException {
    ResourceHandle result;
    result = super.getUnenlistedResource(spec, alloc, tran);
    // and hence we should not use this resource.
    if (result != null) {
        synchronized (result.lock) {
            if (ds.getAllResources().contains(result) && ((AssocWithThreadResourceHandle) result).isDirty()) {
                // Remove the resource and set to null
                ds.removeResource(result);
                result = null;
            }
        }
    }
    // DISASSOCIATE
    if (result == null) {
        synchronized (this) {
            for (ResourceHandle resource : ds.getAllResources()) {
                synchronized (resource.lock) {
                    if (resource.getResourceState().isUnenlisted() && resource.getResourceState().isFree() && !(((AssocWithThreadResourceHandle) resource).isDirty())) {
                        if (!matchConnection(resource, alloc)) {
                            continue;
                        }
                        if (resource.hasConnectionErrorOccurred()) {
                            continue;
                        }
                        result = resource;
                        setResourceStateToBusy(result);
                        ((AssocWithThreadResourceHandle) result).setAssociated(false);
                        break;
                    }
                }
            }
        }
    }
    if (localResource.get() == null) {
        setInThreadLocal((AssocWithThreadResourceHandle) result);
    }
    return result;
}
Also used : ResourceHandle(com.sun.enterprise.resource.ResourceHandle) AssocWithThreadResourceHandle(com.sun.enterprise.resource.AssocWithThreadResourceHandle) AssocWithThreadResourceHandle(com.sun.enterprise.resource.AssocWithThreadResourceHandle)

Example 24 with ResourceHandle

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

the class ListDataStructure method addResource.

/**
 * creates a new resource and adds to the datastructure.
 *
 * @param allocator ResourceAllocator
 * @param count     Number (units) of resources to create
 * @return int number of resources added
 */
public int addResource(ResourceAllocator allocator, int count) throws PoolingException {
    int numResAdded = 0;
    for (int i = 0; i < count && resources.size() < maxSize; i++) {
        boolean lockAcquired = dynSemaphore.tryAcquire();
        if (lockAcquired) {
            try {
                ResourceHandle handle = handler.createResource(allocator);
                synchronized (resources) {
                    synchronized (free) {
                        free.add(handle);
                        resources.add(handle);
                        numResAdded++;
                    }
                }
            } catch (Exception e) {
                dynSemaphore.release();
                PoolingException pe = new PoolingException(e.getMessage());
                pe.initCause(e);
                throw pe;
            }
        }
    }
    return numResAdded;
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException)

Example 25 with ResourceHandle

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

the class ListDataStructure method removeAll.

/**
 * remove & destroy all resources from the datastructure.
 */
public void removeAll() {
    synchronized (resources) {
        synchronized (free) {
            while (resources.size() > 0) {
                ResourceHandle handle = resources.remove(0);
                free.remove(handle);
                dynSemaphore.release();
                handler.deleteResource(handle);
            }
        }
    }
    free.clear();
    resources.clear();
}
Also used : ResourceHandle(com.sun.enterprise.resource.ResourceHandle)

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