Search in sources :

Example 1 with LocalTxConnectionEventListener

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

the class ConnectorXAResource method end.

public void end(Xid xid, int flags) throws XAException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "connection_sharing_end");
    }
    try {
        ResourceHandle handleInTransaction = getResourceHandleAndBeginTxIfNeeded();
        if (!localHandle_.equals(handleInTransaction)) {
            LocalTxConnectionEventListener l = (LocalTxConnectionEventListener) handleInTransaction.getListener();
            ResourceHandle handle = l.removeAssociation(userHandle);
            if (handle != null) {
                // not needed, just to be sure.
                ManagedConnection associatedConnection = (ManagedConnection) handle.getResource();
                associatedConnection.associateConnection(userHandle);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "connection_sharing_reset_association", userHandle);
                }
            }
        }
    } catch (Exception e) {
        handleResourceException(e);
    }
}
Also used : LocalTxConnectionEventListener(com.sun.enterprise.resource.listener.LocalTxConnectionEventListener) ManagedConnection(javax.resource.spi.ManagedConnection) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) ResourceAllocationException(javax.resource.spi.ResourceAllocationException)

Example 2 with LocalTxConnectionEventListener

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

the class ConnectorXAResource method resetAssociation.

private void resetAssociation() throws XAException {
    try {
        ResourceHandle handle = getResourceHandleForFinalize();
        LocalTxConnectionEventListener l = (LocalTxConnectionEventListener) handle.getListener();
        // Get all associated Handles and reset their ManagedConnection association.
        Map associatedHandles = l.getAssociatedHandles();
        if (associatedHandles != null) {
            Set<Map.Entry> userHandles = associatedHandles.entrySet();
            for (Map.Entry userHandleEntry : userHandles) {
                ResourceHandle associatedHandle = (ResourceHandle) userHandleEntry.getValue();
                ManagedConnection associatedConnection = (ManagedConnection) associatedHandle.getResource();
                associatedConnection.associateConnection(userHandleEntry.getKey());
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "connection_sharing_reset_association", userHandleEntry.getKey());
                }
            }
            // all associated handles are mapped back to their actual Managed Connection. Clear the associations.
            associatedHandles.clear();
        }
    } catch (Exception ex) {
        handleResourceException(ex);
    }
}
Also used : LocalTxConnectionEventListener(com.sun.enterprise.resource.listener.LocalTxConnectionEventListener) ManagedConnection(javax.resource.spi.ManagedConnection) Map(java.util.Map) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) ResourceAllocationException(javax.resource.spi.ResourceAllocationException)

Example 3 with LocalTxConnectionEventListener

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

the class ConnectorXAResource method start.

public void start(Xid xid, int flags) throws XAException {
    try {
        ResourceHandle handle = getResourceHandleAndBeginTxIfNeeded();
        if (!localHandle_.equals(handle)) {
            ManagedConnection mc = (ManagedConnection) handle.getResource();
            mc.associateConnection(userHandle);
            LocalTxConnectionEventListener l = (com.sun.enterprise.resource.listener.LocalTxConnectionEventListener) handle.getListener();
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "connection_sharing_start", userHandle);
            }
            l.associateHandle(userHandle, localHandle_);
        } else {
            associatedTransaction = getCurrentTransaction();
        }
    } catch (Exception ex) {
        handleResourceException(ex);
    }
}
Also used : LocalTxConnectionEventListener(com.sun.enterprise.resource.listener.LocalTxConnectionEventListener) ManagedConnection(javax.resource.spi.ManagedConnection) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) ResourceAllocationException(javax.resource.spi.ResourceAllocationException)

Example 4 with LocalTxConnectionEventListener

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

the class LocalTxConnectorAllocator method createResource.

public ResourceHandle createResource() throws PoolingException {
    try {
        ManagedConnection mc = mcf.createManagedConnection(subject, reqInfo);
        ResourceHandle resource = createResourceHandle(mc, spec, this, info);
        ConnectionEventListener l = new LocalTxConnectionEventListener(resource);
        mc.addConnectionEventListener(l);
        resource.setListener(l);
        XAResource xares = new ConnectorXAResource(resource, spec, this, info);
        resource.fillInResourceObjects(null, xares);
        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) XAResource(javax.transaction.xa.XAResource) LocalTxConnectionEventListener(com.sun.enterprise.resource.listener.LocalTxConnectionEventListener) ResourceException(javax.resource.ResourceException) LocalTxConnectionEventListener(com.sun.enterprise.resource.listener.LocalTxConnectionEventListener) ConnectionEventListener(com.sun.enterprise.resource.listener.ConnectionEventListener)

Aggregations

PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)4 LocalTxConnectionEventListener (com.sun.enterprise.resource.listener.LocalTxConnectionEventListener)4 ManagedConnection (javax.resource.spi.ManagedConnection)3 ResourceAllocationException (javax.resource.spi.ResourceAllocationException)3 SystemException (javax.transaction.SystemException)3 XAException (javax.transaction.xa.XAException)3 ConnectionEventListener (com.sun.enterprise.resource.listener.ConnectionEventListener)1 Map (java.util.Map)1 ResourceException (javax.resource.ResourceException)1 XAResource (javax.transaction.xa.XAResource)1