Package org.mule.api.transaction

Examples of org.mule.api.transaction.Transaction


            {

                public Void doInTransaction() throws Exception
                {
                    // Get Transaction & Bind MuleSession
                    Transaction tx = TransactionCoordination.getInstance().getTransaction();
                    if (tx != null)
                    {
                        tx.bindResource(connector.getConnection(), session);
                    }
                    if (tx instanceof JmsClientAcknowledgeTransaction)
                    {
                        tx.bindResource(message, message);
                    }

                    if (logger.isDebugEnabled())
                    {
                        logger.debug("Message received it is of type: " +
View Full Code Here


        }
        catch (CommunicationException ce)
        {
            try
            {
                final Transaction tx = TransactionCoordination.getInstance().getTransaction();
                if (tx != null)
                {
                    tx.setRollbackOnly();
                }
            }
            catch (TransactionException e)
            {
                throw new MuleRuntimeException(
View Full Code Here

        return flowConstruct.getName() + "~" + endpoint.getEndpointURI().getAddress();
    }

    public Session getSessionFromTransaction()
    {
        Transaction tx = TransactionCoordination.getInstance().getTransaction();
        if (tx != null)
        {
            if (tx.hasResource(connection))
            {
                if (logger.isDebugEnabled())
                {
                    logger.debug("Retrieving jms session from current transaction " + tx);
                }

                Session session = (Session) tx.getResource(connection);

                if (logger.isDebugEnabled())
                {
                    logger.debug("Using " + session + " bound to transaction " + tx);
                }
View Full Code Here

        if (session != null)
        {
            return session;
        }

        Transaction tx = TransactionCoordination.getInstance().getTransaction();

        session = jmsSupport.createSession(connection, topic, transacted, acknowledgementMode, noLocal);

        if (logger.isDebugEnabled())
        {
            logger.debug(MessageFormat.format(
                    "Retrieved new jms session from connection: " +
                            "topic={0}, transacted={1}, ack mode={2}, nolocal={3}: {4}",
                    topic, transacted, acknowledgementMode, noLocal, session));
        }

        if (tx != null)
        {
            logger.debug("Binding session " + session + " to current transaction " + tx);
            try
            {
                tx.bindResource(connection, session);
            }
            catch (TransactionException e)
            {
                closeQuietly(session);
                throw new RuntimeException("Could not bind session to current transaction", e);
View Full Code Here

     *
     * @param session the session that ill be closed if there is an active transaction.
     */
    public void closeSessionIfNoTransactionActive(Session session)
    {
        final Transaction transaction = TransactionCoordination.getInstance().getTransaction();
        if (transaction == null)
        {
            if (logger.isDebugEnabled())
            {
                logger.error("Closing non-TX session: " + session);
View Full Code Here

        {
            final boolean topic = connector.getTopicResolver().isTopic(endpoint);

            JmsSupport support = connector.getJmsSupport();
            final TransactionConfig transactionConfig = endpoint.getTransactionConfig();
            final Transaction tx = TransactionCoordination.getInstance().getTransaction();
            boolean transacted = transactionConfig != null && transactionConfig.isTransacted();

            session = connector.getSession(transacted, topic);

            if (transacted && !tx.isXA())
            {
                // register a session close listener
                final Session finalSession = session;
                getConnector().getMuleContext().registerListener(new TransactionNotificationListener<TransactionNotification>()
                {
                    public void onNotification(TransactionNotification txNotification)
                    {
                        final int txAction = txNotification.getAction();
                        final String txId = txNotification.getTransactionStringId();
                        if ((txAction == TransactionNotification.TRANSACTION_COMMITTED || txAction == TransactionNotification.TRANSACTION_ROLLEDBACK) &&
                            txId.equals(tx.getId())) {
                            connector.closeQuietly(finalSession);
                        }
                    }
                }, tx.getId());

                cleanupListenerRegistered = true;
            }

            Destination dest = support.createDestination(session, endpoint);
View Full Code Here

        // may have been started
        TransactionCallback<?> cb = new TransactionCallback()
        {
            public Object doInTransaction() throws Exception
            {
                Transaction tx = TransactionCoordination.getInstance().getTransaction();
                if (tx != null)
                {
                    bindTransaction(tx);
                }
                List<Object> results = new ArrayList<Object>(messages.size());
View Full Code Here

        verify(session, times(1)).close();
    }

    public void testDoNotClosesSessionIfThereIsAnActiveTransaction() throws Exception
    {
        Transaction transaction = mock(Transaction.class);
        TransactionCoordination.getInstance().bindTransaction(transaction);

        try
        {
            JmsConnector connector = new JmsConnector(muleContext);
View Full Code Here

     */
    protected boolean isTransactionRollback()
    {
        try
        {
            Transaction tx = TransactionCoordination.getInstance().getTransaction();
            if (tx != null && tx.isRollbackOnly())
            {
                return true;
            }
        }
        catch (TransactionException e)
View Full Code Here

        Object replyMessage = super.onCall(context);

        if (expectTransaction)
        {
            // Verify transaction has begun.
            Transaction currentTx = context.getCurrentTransaction();
            if (currentTx == null || !currentTx.isBegun())
            {   
                context.setStopFurtherProcessing(true);
                throw new TransactionException(MessageFactory.createStaticMessage("Trying to roll back transaction but no transaction is underway."));
            }           

            if (rollback)
            {
                // Mark the transaction for rollback.
                logger.info("@@@@ Rolling back transaction @@@@");
                currentTx.setRollbackOnly();
            }       
        }
       
        return replyMessage;
    }
View Full Code Here

TOP

Related Classes of org.mule.api.transaction.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.