Search in sources :

Example 1 with JavaEETransactionManager

use of com.sun.enterprise.transaction.api.JavaEETransactionManager 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 2 with JavaEETransactionManager

use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.

the class SystemResourceManagerImpl method rollBackTransaction.

public void rollBackTransaction() {
    try {
        JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
        Transaction tran = tm.getTransaction();
        if (tran != null) {
            tran.setRollbackOnly();
        }
    } catch (SystemException ex) {
        _logger.log(Level.WARNING, "poolmgr.system_exception", ex);
    } catch (IllegalStateException ex) {
    // ignore
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager)

Example 3 with JavaEETransactionManager

use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.

the class SystemResourceManagerImpl method enlistResource.

/**
 * Register the <code>ResourceHandle</code> in the transaction
 *
 * @param handle	<code>ResourceHandle</code> object
 * @exception <code>PoolingException</code> If there is any error while
 *        enlisting.
 */
public void enlistResource(ResourceHandle handle) throws PoolingException {
    try {
        JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
        Transaction tran = tm.getTransaction();
        if (tran != null) {
            tm.enlistResource(tran, handle);
        }
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "poolmgr.unexpected_exception", ex);
        throw new PoolingException(ex.toString(), ex);
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) Transaction(javax.transaction.Transaction) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) SystemException(javax.transaction.SystemException)

Example 4 with JavaEETransactionManager

use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.

the class SystemResourceManagerImpl method delistResource.

/**
 * delist the <code>ResourceHandle</code> from the transaction
 *
 * @param h	<code>ResourceHandle</code> object
 * @param xaresFlag flag indicating transaction success. This can
 *        be XAResource.TMSUCCESS or XAResource.TMFAIL
 * @exception <code>PoolingException</code>
 */
public void delistResource(ResourceHandle h, int xaresFlag) {
    try {
        JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
        Transaction tran = tm.getTransaction();
        if (tran != null) {
            tm.delistResource(tran, h, xaresFlag);
        }
    } catch (SystemException ex) {
        _logger.log(Level.WARNING, "poolmgr.system_exception", ex);
    } catch (IllegalStateException ex) {
    // ignore
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager)

Example 5 with JavaEETransactionManager

use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.

the class MessageEndpointInvocationHandler method invoke.

/**
 * Invokes the method
 *
 * @param proxy  Object
 * @param method <code>Method</code> to be executed.
 * @param args   Arguments
 * @throws Throwable.
 */
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    // NOTE : be careful with "args" parameter.  It is null
    // if method signature has 0 arguments.
    String methodClassName = method.getDeclaringClass().getName();
    String methodName = method.getName();
    Object returnValue = null;
    if (logger.isLoggable(Level.FINEST)) {
        String msg = "Invoking method [" + methodName + "] from class [" + methodClassName + "]";
        logger.log(Level.FINEST, msg);
    }
    // to the MDB container
    if (MESSAGE_ENDPOINT.equals(methodClassName)) {
        if ("beforeDelivery".equals(methodName)) {
            Method onMessageMethod = (Method) args[0];
            beforeDeliveryCalled = true;
            listener_.beforeMessageDelivery(onMessageMethod, false);
        } else if ("afterDelivery".equals(methodName)) {
            // reset
            beforeDeliveryCalled = false;
            listener_.afterMessageDelivery();
        } else if ("release".equals(methodName)) {
            messageBeanPM_.destroyMessageBeanListener(listener_);
        } else {
            logger.log(Level.SEVERE, "endpointfactory.method_not_defined", new Object[] { methodName, MESSAGE_ENDPOINT });
            throw new RuntimeException(methodName);
        }
    } else if ("java.lang.Object".equals(methodClassName)) {
        returnValue = invokeJavaObjectMethod(this, method, args);
    } else {
        // RA did not call beforeDelivery, handle it here
        if (!beforeDeliveryCalled) {
            JavaEETransactionManager txManager = ConnectorRuntime.getRuntime().getTransactionManager();
            boolean txImported = (txManager.getTransaction() != null);
            listener_.beforeMessageDelivery(method, txImported);
        }
        try {
            // returnValue = listener_.deliverMessage(method, args);
            // TODO startCallFlowAgent();
            returnValue = listener_.deliverMessage(args);
        } catch (Throwable ex) {
            if (messageBeanPM_.isDeliveryTransacted(method)) {
                if (throwTransactedExceptions_) {
                    throw ex;
                } else {
                    logger.log(Level.INFO, "Resource adapter eating " + " transacted exception", ex);
                }
            } else {
                throw ex;
            }
        } finally {
            // to determine when to pair the afterDelivery call.
            if (!beforeDeliveryCalled) {
                listener_.afterMessageDelivery();
            }
            beforeDeliveryCalled = false;
        }
    }
    return returnValue;
}
Also used : JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) Method(java.lang.reflect.Method)

Aggregations

JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)15 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)5 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)4 InvocationException (org.glassfish.api.invocation.InvocationException)4 ResourceException (javax.resource.ResourceException)3 SystemException (javax.transaction.SystemException)3 Transaction (javax.transaction.Transaction)3 InvocationManager (org.glassfish.api.invocation.InvocationManager)3 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)2 ResourceSpec (com.sun.enterprise.resource.ResourceSpec)1 PoolManager (com.sun.enterprise.resource.pool.PoolManager)1 JavaEETransactionManagerSimplified (com.sun.enterprise.transaction.JavaEETransactionManagerSimplified)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Logger (java.util.logging.Logger)1 ManagedConnection (javax.resource.spi.ManagedConnection)1