Package org.mule.transaction

Examples of org.mule.transaction.TransactionTemplate


     * will execute the processing of messages within a TransactionTemplate.  This template will manage the
     * transaction lifecycle for the list of messages associated with this receiver worker.
     */
    public void processMessages() throws Exception
    {
        TransactionTemplate tt = new TransactionTemplate(endpoint.getTransactionConfig(), receiver.getConnector().getMuleContext());

        // Receive messages and process them in a single transaction
        // Do not enable threading here, but serveral workers
        // 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());

                for (Object payload : messages)
                {
                    payload = preProcessMessage(payload);
                    if (payload != null)
                    {
                        MuleMessage muleMessage = receiver.createMuleMessage(payload, endpoint.getEncoding());
                        preRouteMuleMessage(muleMessage);

                        // TODO Move getSessionHandler() to the Connector interface
                        SessionHandler handler;
                        if (endpoint.getConnector() instanceof AbstractConnector)
                        {
                            handler = ((AbstractConnector) endpoint.getConnector()).getSessionHandler();
                        }
                        else
                        {
                            handler = new MuleSessionHandler();
                        }
                        MuleSession session;
                        try
                        {
                            session = handler.retrieveSessionInfoFromMessage(muleMessage);
                        }
                        catch (SerializationException e)
                        {
                            // EE-1820 Support message headers generated by previous Mule versions
                            session = new LegacySessionHandler().retrieveSessionInfoFromMessage(muleMessage);
                        }
                       
                        MuleEvent resultEvent;
                        if (session != null)
                        {
                            resultEvent = receiver.routeMessage(muleMessage, session, tx, out);
                        }
                        else
                        {
                            resultEvent = receiver.routeMessage(muleMessage, tx, out);
                        }
                        MuleMessage result = resultEvent == null null : resultEvent.getMessage();
                        if (result != null)
                        {
                            payload = postProcessMessage(result);
                            if (payload != null)
                            {
                                results.add(payload);
                            }
                        }
                    }
                }
                return results;
            }
        };

        try
        {
            List results = (List) tt.execute(cb);
            handleResults(results);
        }
        finally
        {
            messages.clear();
View Full Code Here


        // this is one component with a TX always begin
        TransactionConfig config = new MuleTransactionConfig();
        config.setFactory(new XaTransactionFactory());
        config.setAction(TransactionConfig.ACTION_ALWAYS_BEGIN);
        TransactionTemplate template = new TransactionTemplate(config, muleContext);

        // and the callee component which should begin new transaction, current must be suspended
        final TransactionConfig nestedConfig = new MuleTransactionConfig();
        nestedConfig.setFactory(new XaTransactionFactory());
        nestedConfig.setAction(TransactionConfig.ACTION_ALWAYS_BEGIN);

        // start the call chain
        template.execute(new TransactionCallback<Void>()
        {
            public Void doInTransaction() throws Exception
            {
                // the callee executes within its own TX template, but uses the same global XA transaction,
                // bound to the current thread of execution via a ThreadLocal
View Full Code Here

        // this is one service with a TX always begin
        TransactionConfig config = new MuleTransactionConfig();
        config.setFactory(new XaTransactionFactory());
        config.setAction(TransactionConfig.ACTION_ALWAYS_BEGIN);
        TransactionTemplate template = new TransactionTemplate(config, muleContext);

        // and the callee service which should join the current XA transaction, not begin a nested one
        final TransactionConfig nestedConfig = new MuleTransactionConfig();
        nestedConfig.setFactory(new XaTransactionFactory());
        nestedConfig.setAction(TransactionConfig.ACTION_BEGIN_OR_JOIN);

        // start the call chain
        template.execute(new TransactionCallback<Void>()
        {
            public Void doInTransaction() throws Exception
            {
                // the callee executes within its own TX template, but uses the same global XA transaction,
                // bound to the current thread of execution via a ThreadLocal
View Full Code Here

TOP

Related Classes of org.mule.transaction.TransactionTemplate

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.