You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2007/03/05 14:51:09 UTC

svn commit: r514666 - in /incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi: container/SpringJBIContainer.java messaging/DeliveryChannelImpl.java

Author: gnodet
Date: Mon Mar  5 05:51:09 2007
New Revision: 514666

URL: http://svn.apache.org/viewvc?view=rev&rev=514666
Log:
SM-865: Remove jta and j2ee-connector from the mandatory dependencies when running an embedded ServiceMix instance
Also ensure JBIContainer.getTransactionManager() is called only once

Modified:
    incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java
    incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java

Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java?view=diff&rev=514666&r1=514665&r2=514666
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java Mon Mar  5 05:51:09 2007
@@ -17,12 +17,9 @@
 package org.apache.servicemix.jbi.container;
 
 import javax.jbi.JBIException;
-import javax.resource.spi.work.WorkManager;
 
-import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
 import org.apache.servicemix.components.util.ComponentAdaptor;
 import org.apache.servicemix.jbi.framework.ComponentMBeanImpl;
-import org.jencks.factory.WorkManagerFactoryBean;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.beans.factory.BeanFactoryAware;
@@ -166,19 +163,6 @@
 
     public void setApplicationContext(ApplicationContext applicationContext) {
         this.applicationContext = applicationContext;
-    }
-
-    protected WorkManager createWorkManager() throws JBIException {
-        WorkManagerFactoryBean factory = new WorkManagerFactoryBean();
-        if (getTransactionManager() instanceof GeronimoTransactionManager) {
-            factory.setTransactionManager((GeronimoTransactionManager) getTransactionManager());
-        }
-        try {
-            return (WorkManager) factory.getObject();
-        }
-        catch (Exception e) {
-            throw new JBIException("Failed to start WorkManager: " + e, e);
-        }
     }
 
     public void destroy() throws Exception {

Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java?view=diff&rev=514666&r1=514665&r2=514666
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/messaging/DeliveryChannelImpl.java Mon Mar  5 05:51:09 2007
@@ -72,6 +72,7 @@
     private int intervalCount = 0;
     private AtomicBoolean closed = new AtomicBoolean(false);
     private Map waiters = new ConcurrentHashMap();
+    private TransactionManager transactionManager = null;
     
     /**
      * When using clustering and sendSync, the exchange received will not be the same
@@ -87,6 +88,7 @@
         this.component = component;
         this.container = component.getContainer();
         this.queue = new ArrayBlockingQueue(component.getInboundQueueCapacity());
+        this.transactionManager = (TransactionManager) this.container.getTransactionManager();
     }
 
     /**
@@ -707,40 +709,38 @@
     }
 
     protected void suspendTx(MessageExchangeImpl me) {
-        try {
-            Transaction oldTx = me.getTransactionContext();
-            if (oldTx != null) {
-                TransactionManager tm = (TransactionManager) container.getTransactionManager();
-                if (tm != null) {
+        if (transactionManager != null) {
+            try {
+                Transaction oldTx = me.getTransactionContext();
+                if (oldTx != null) {
                     if (log.isDebugEnabled()) {
                         log.debug("Suspending transaction for " + me.getExchangeId() + " in " + this);
                     }
-                    Transaction tx = tm.suspend();
+                    Transaction tx = transactionManager.suspend();
                     if (tx != oldTx) {
                         throw new IllegalStateException("the transaction context set in the messageExchange is not bound to the current thread");
                     }
                 }
+            } catch (Exception e) {
+                log.info("Exchange " + me.getExchangeId() + " aborted due to transaction exception", e);
+                me.getPacket().setAborted(true);
             }
-        } catch (Exception e) {
-            log.info("Exchange " + me.getExchangeId() + " aborted due to transaction exception", e);
-            me.getPacket().setAborted(true);
         }
     }
 
     protected void resumeTx(MessageExchangeImpl me) throws MessagingException {
-        try {
-            Transaction oldTx = me.getTransactionContext();
-            if (oldTx != null) {
-                TransactionManager tm = (TransactionManager) container.getTransactionManager();
-                if (tm != null) {
+        if (transactionManager != null) {
+            try {
+                Transaction oldTx = me.getTransactionContext();
+                if (oldTx != null) {
                     if (log.isDebugEnabled()) {
                         log.debug("Resuming transaction for " + me.getExchangeId() + " in " + this);
                     }
-                    tm.resume(oldTx);
+                    transactionManager.resume(oldTx);
                 }
+            } catch (Exception e) {
+                throw new MessagingException(e);
             }
-        } catch (Exception e) {
-            throw new MessagingException(e);
         }
     }
 
@@ -751,24 +751,21 @@
      * @throws MessagingException
      */
     protected void autoEnlistInTx(MessageExchangeImpl me) throws MessagingException {
-        try {
-            if (container.isAutoEnlistInTransaction()) {
-                TransactionManager tm = (TransactionManager) container.getTransactionManager();
-                if (tm != null) {
-                    Transaction tx = tm.getTransaction();
-                    if (tx != null) {
-                        Object oldTx = me.getTransactionContext();
-                        if (oldTx == null) {
-                            me.setTransactionContext(tx);
-                        } else if (oldTx != tx) {
-                            throw new IllegalStateException(
-                                    "the transaction context set in the messageExchange is not bound to the current thread");
-                        }
+        if (transactionManager != null && container.isAutoEnlistInTransaction()) {
+            try {
+                Transaction tx = transactionManager.getTransaction();
+                if (tx != null) {
+                    Object oldTx = me.getTransactionContext();
+                    if (oldTx == null) {
+                        me.setTransactionContext(tx);
+                    } else if (oldTx != tx) {
+                        throw new IllegalStateException(
+                                "the transaction context set in the messageExchange is not bound to the current thread");
                     }
                 }
+            } catch (Exception e) {
+                throw new MessagingException(e);
             }
-        } catch (Exception e) {
-            throw new MessagingException(e);
         }
     }