You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by dj...@apache.org on 2008/03/16 07:48:56 UTC

svn commit: r637548 - in /openejb/trunk/openejb3: ./ assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/ container/openejb-core/ container/openejb-core/src/main/java/org/apache/openejb/core/mdb/ containe...

Author: djencks
Date: Sat Mar 15 23:48:50 2008
New Revision: 637548

URL: http://svn.apache.org/viewvc?rev=637548&view=rev
Log:
OPENEJB-777 OPENEJB-702.  Introduce NamedXAResource wrapping for DBCP datasources, and supply a TxRecovery parameter to turn this on and off for DBCP pools and for mdbs.  Also introduce a factory bean to create the transaction manager together with XidFactory and HOWLLog so standalone openejb has transaction recovery possibilities.  These are all turned off in embedded as the tests do not shut down the log sufficiently for it to be restarted in the same vm.  The DBCP pool code is hacky but appears to work.

Added:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java   (with props)
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/ManagedDataSourceWithRecovery.java
      - copied, changed from r637306, openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java
Modified:
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml
    openejb/trunk/openejb3/container/openejb-core/pom.xml
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/EndpointFactory.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java
    openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml
    openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
    openejb/trunk/openejb3/pom.xml

Modified: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml?rev=637548&r1=637547&r2=637548&view=diff
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml (original)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml Sat Mar 15 23:48:50 2008
@@ -178,7 +178,7 @@
           id="Default MDB Container"
           service="Container"
           types="MESSAGE"
-          constructor="id, transactionManager, securityService, ResourceAdapter, MessageListenerInterface, ActivationSpecClass, InstanceLimit"
+          constructor="id, transactionManager, securityService, ResourceAdapter, MessageListenerInterface, ActivationSpecClass, InstanceLimit, TxRecovery"
           class-name="org.apache.openejb.core.mdb.MdbContainer">
 
     # The resource adapter delivers messages to the container
@@ -198,6 +198,11 @@
 
     InstanceLimit 10
 
+    # Specifies whether to use NamedXAResource wrappers to allow the geronimo tm
+    # to log and recover in doubt transactions.
+    TxRecovery true
+
+
   </ServiceProvider>
 
   <!--
@@ -240,11 +245,28 @@
   # Default Transaction Manager implementation
   # ================================================
   -->
-  <ServiceProvider
-          id="Default Transaction Manager"
-          service="TransactionManager"
-          types="TransactionManager"
-          class-name="org.apache.geronimo.transaction.manager.GeronimoTransactionManager"/>
+    <ServiceProvider
+            id="Default Transaction Manager"
+            service="TransactionManager"
+            types="TransactionManager"
+            factory-name="create"
+            constructor="defaultTransactionTimeoutSeconds, tmId, bufferClassName, bufferSizeKb, checksumEnabled, adler32Checksum, flushSleepTimeMilliseconds, logFileDir, logFileExt, logFileName, maxBlocksPerFile, maxBuffers, maxLogFiles, minBuffers, threadsWaitingForceThreshold"
+            class-name="org.apache.openejb.resource.GeronimoTransactionManagerFactory">
+           defaultTransactionTimeoutSeconds 600
+           bufferSizeKb 32
+           checksumEnabled true
+           adler32Checksum true
+           flushSleepTimeMilliseconds 50
+           logFileDir txlog
+           logFileExt log
+           logFileName howl
+           maxBlocksPerFile -1
+           maxBuffers 0
+        # set to 0 or less to disable transaction logging and recovery
+           maxLogFiles 2
+           minBuffers 4
+           threadsWaitingForceThreshold -1
+    </ServiceProvider>
 
   <!--
   # ================================================
@@ -256,7 +278,7 @@
           service="Resource"
           types="javax.sql.DataSource, DataSource"
           factory-name="create"
-          constructor="JtaManaged"
+          constructor="JtaManaged,TxRecovery"
           class-name="org.apache.openejb.resource.jdbc.DataSourceFactory">
 
     # Determines wether or not this data source should be JTA managed
@@ -271,6 +293,10 @@
 
     JtaManaged = true
 
+    # Specifies whether to use NamedXAResource wrappers to allow the geronimo tm
+    # to log and recover in doubt transactions.
+    TxRecovery true
+
     # Driver class name
 
     JdbcDriver org.hsqldb.jdbcDriver
@@ -450,10 +476,11 @@
           service="Resource"
           types="javax.sql.DataSource, DataSource"
           factory-name="create"
-          constructor="JtaManaged"
+          constructor="JtaManaged,TxRecovery"
           class-name="org.apache.openejb.resource.jdbc.DataSourceFactory">
 
     JtaManaged = false
+    TxRecovery = false
 
     # Driver class name
 
@@ -648,7 +675,8 @@
     BrokerXmlConfig broker:(tcp://localhost:61616)?useJmx=false
 
     # Broker address
-    ServerUrl vm://localhost?async=true
+    # ServerUrl vm://localhost?async=true
+    ServerUrl tcp://localhost:61616
 
     # DataSource for persistence messages
     DataSource Default Unmanaged JDBC Database

Modified: openejb/trunk/openejb3/container/openejb-core/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/pom.xml?rev=637548&r1=637547&r2=637548&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/pom.xml (original)
+++ openejb/trunk/openejb3/container/openejb-core/pom.xml Sat Mar 15 23:48:50 2008
@@ -275,6 +275,10 @@
       <groupId>org.apache.geronimo.components</groupId>
       <artifactId>geronimo-transaction</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.objectweb.howl</groupId>
+      <artifactId>howl</artifactId>
+    </dependency>
     <!-- JavaMail -->
     <dependency>
       <groupId>org.apache.geronimo.javamail</groupId>

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/EndpointFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/EndpointFactory.java?rev=637548&r1=637547&r2=637548&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/EndpointFactory.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/EndpointFactory.java Sat Mar 15 23:48:50 2008
@@ -37,14 +37,16 @@
     private final MdbInstanceFactory instanceFactory;
     private final ClassLoader classLoader;
     private final Class[] interfaces;
+    private final boolean txRecovery;
 
-    public EndpointFactory(ActivationSpec activationSpec, MdbContainer container, CoreDeploymentInfo deploymentInfo, MdbInstanceFactory instanceFactory) {
+    public EndpointFactory(ActivationSpec activationSpec, MdbContainer container, CoreDeploymentInfo deploymentInfo, MdbInstanceFactory instanceFactory, boolean txRecovery) {
         this.activationSpec = activationSpec;
         this.container = container;
         this.deploymentInfo = deploymentInfo;
         this.instanceFactory = instanceFactory;
         classLoader = container.getMessageListenerInterface().getClassLoader();
         interfaces = new Class[]{container.getMessageListenerInterface(), MessageEndpoint.class};
+        this.txRecovery = txRecovery;
     }
 
     public ActivationSpec getActivationSpec() {
@@ -56,8 +58,10 @@
     }
 
     public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException {
-        NamedXAResource wrapper = new WrapperNamedXAResource(xaResource, container.getContainerID().toString());
-        EndpointHandler endpointHandler = new EndpointHandler(container, deploymentInfo, instanceFactory, wrapper);
+        if (txRecovery) {
+            xaResource = new WrapperNamedXAResource(xaResource, container.getContainerID().toString());
+        }
+        EndpointHandler endpointHandler = new EndpointHandler(container, deploymentInfo, instanceFactory, xaResource);
         MessageEndpoint messageEndpoint = (MessageEndpoint) Proxy.newProxyInstance(classLoader, interfaces, endpointHandler);
         return messageEndpoint;
     }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java?rev=637548&r1=637547&r2=637548&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java Sat Mar 15 23:48:50 2008
@@ -67,10 +67,11 @@
     private final Class messageListenerInterface;
     private final Class activationSpecClass;
     private final int instanceLimit;
+    private final boolean txRecovery;
 
     private final ConcurrentMap<Object, CoreDeploymentInfo> deployments = new ConcurrentHashMap<Object, CoreDeploymentInfo>();
 
-    public MdbContainer(Object containerID, TransactionManager transactionManager, SecurityService securityService, ResourceAdapter resourceAdapter, Class messageListenerInterface, Class activationSpecClass, int instanceLimit) {
+    public MdbContainer(Object containerID, TransactionManager transactionManager, SecurityService securityService, ResourceAdapter resourceAdapter, Class messageListenerInterface, Class activationSpecClass, int instanceLimit, boolean txRecovery) {
         this.containerID = containerID;
         this.transactionManager = transactionManager;
         this.securityService = securityService;
@@ -78,6 +79,7 @@
         this.messageListenerInterface = messageListenerInterface;
         this.activationSpecClass = activationSpecClass;
         this.instanceLimit = instanceLimit;
+        this.txRecovery = txRecovery;
     }
 
     public DeploymentInfo [] deployments() {
@@ -122,7 +124,7 @@
 
         // create the message endpoint
         MdbInstanceFactory instanceFactory = new MdbInstanceFactory(deploymentInfo, transactionManager, securityService, instanceLimit);
-        EndpointFactory endpointFactory = new EndpointFactory(activationSpec, this, deploymentInfo, instanceFactory);
+        EndpointFactory endpointFactory = new EndpointFactory(activationSpec, this, deploymentInfo, instanceFactory, txRecovery);
 
         // update the data structures
         // this must be done before activating the endpoint since the ra may immedately begin delivering messages

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java?rev=637548&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java Sat Mar 15 23:48:50 2008
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.openejb.resource;
+
+import java.io.IOException;
+
+import javax.transaction.xa.XAException;
+
+import org.apache.geronimo.transaction.log.HOWLLog;
+import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
+import org.apache.geronimo.transaction.manager.TransactionLog;
+import org.apache.geronimo.transaction.manager.XidFactory;
+import org.apache.geronimo.transaction.manager.XidFactoryImpl;
+import org.apache.openejb.loader.SystemInstance;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class GeronimoTransactionManagerFactory {
+
+    private static final byte[] DEFAULT_TM_ID = new byte[]{71, 84, 77, 73, 68};
+    private static final int DEFAULT_BUFFER_SIZE = 32;
+
+    public static GeronimoTransactionManager create(int defaultTransactionTimeoutSeconds,
+                                                    byte[] tmId,
+                                                    String bufferClassName,
+                                                    int bufferSizeKb,
+                                                    boolean checksumEnabled,
+                                                    boolean adler32Checksum,
+                                                    int flushSleepTimeMilliseconds,
+                                                    String logFileDir,
+                                                    String logFileExt,
+                                                    String logFileName,
+                                                    int maxBlocksPerFile,
+                                                    int maxBuffers,
+                                                    int maxLogFiles,
+                                                    int minBuffers,
+                                                    int threadsWaitingForceThreshold) throws Exception {
+        XidFactory xidFactory = null;
+        TransactionLog txLog = null;
+        if (maxLogFiles > 0) {
+            xidFactory = new XidFactoryImpl(tmId == null ? DEFAULT_TM_ID: tmId);
+            txLog = new HOWLLog(bufferClassName == null ? "org.objectweb.howl.log.BlockLogBuffer" : bufferClassName,
+                    bufferSizeKb == 0 ? DEFAULT_BUFFER_SIZE : bufferSizeKb,
+                    checksumEnabled,
+                    adler32Checksum,
+                    flushSleepTimeMilliseconds,
+                    logFileDir,
+                    logFileExt,
+                    logFileName,
+                    maxBlocksPerFile,
+                    maxBuffers,
+                    maxLogFiles,
+                    minBuffers,
+                    threadsWaitingForceThreshold,
+                    xidFactory,
+                    SystemInstance.get().getBase().getDirectory("."));
+            ((HOWLLog)txLog).doStart();
+        }
+        return new GeronimoTransactionManager(defaultTransactionTimeoutSeconds, xidFactory, txLog);
+    }
+}

Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoTransactionManagerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java?rev=637548&r1=637547&r2=637548&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java Sat Mar 15 23:48:50 2008
@@ -17,13 +17,14 @@
  */
 package org.apache.openejb.resource.jdbc;
 
-import org.apache.openejb.loader.SystemInstance;
-
-import javax.sql.DataSource;
 import java.io.File;
 import java.sql.SQLException;
 import java.util.Properties;
 
+import javax.sql.DataSource;
+
+import org.apache.openejb.loader.SystemInstance;
+
 public class BasicManagedDataSource extends org.apache.commons.dbcp.managed.BasicManagedDataSource {
     public synchronized String getUserName() {
         return super.getUsername();
@@ -54,7 +55,7 @@
         int level = IsolationLevels.getIsolationLevel(s);
         super.setDefaultTransactionIsolation(level);
     }
-    
+
     protected synchronized DataSource createDataSource() throws SQLException {
         if (dataSource != null) {
             return dataSource;
@@ -68,7 +69,8 @@
             helper.configure(this);
         }
 
-        // creat the data source
+        wrapTransactionManager();
+        // create the data source
         if (helper == null || !helper.enableUserDirHack()) {
             return super.createDataSource();
         } else {
@@ -86,4 +88,8 @@
             }
         }
     }
+
+    protected void wrapTransactionManager() {
+    }
+
 }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java?rev=637548&r1=637547&r2=637548&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java Sat Mar 15 23:48:50 2008
@@ -22,9 +22,13 @@
  * @version $Rev$ $Date$
  */
 public class DataSourceFactory {
-    public static DataSource create(boolean managed){
+    public static DataSource create(boolean managed, boolean txRecovery){
         if (managed){
-            return new BasicManagedDataSource();
+            if (txRecovery) {
+                return new ManagedDataSourceWithRecovery();
+            } else {
+                return new BasicManagedDataSource();
+            }
         } else {
             return new BasicDataSource();
         }

Copied: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/ManagedDataSourceWithRecovery.java (from r637306, openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/ManagedDataSourceWithRecovery.java?p2=openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/ManagedDataSourceWithRecovery.java&p1=openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java&r1=637306&r2=637548&rev=637548&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/BasicManagedDataSource.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/ManagedDataSourceWithRecovery.java Sat Mar 15 23:48:50 2008
@@ -17,73 +17,138 @@
  */
 package org.apache.openejb.resource.jdbc;
 
-import org.apache.openejb.loader.SystemInstance;
-
-import javax.sql.DataSource;
 import java.io.File;
 import java.sql.SQLException;
 import java.util.Properties;
 
-public class BasicManagedDataSource extends org.apache.commons.dbcp.managed.BasicManagedDataSource {
-    public synchronized String getUserName() {
-        return super.getUsername();
-    }
+import javax.sql.DataSource;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAResource;
 
-    public synchronized void setUserName(String string) {
-        super.setUsername(string);
-    }
+import org.apache.geronimo.transaction.manager.WrapperNamedXAResource;
+import org.apache.openejb.loader.SystemInstance;
 
-    public synchronized String getJdbcDriver() {
-        return super.getDriverClassName();
-    }
+public class ManagedDataSourceWithRecovery extends BasicManagedDataSource {
+    private TransactionManager suppliedTransactionManager;
 
-    public synchronized void setJdbcDriver(String string) {
-        super.setDriverClassName(string);
+    @Override
+    public void setTransactionManager(TransactionManager transactionManager) {
+        this.suppliedTransactionManager = transactionManager;
     }
 
-    public synchronized String getJdbcUrl() {
-        return super.getUrl();
+    protected void wrapTransactionManager() {
+        if (suppliedTransactionManager != null) {
+            super.setTransactionManager(new TransactionManagerWrapper(suppliedTransactionManager, getUrl()));
+        }
     }
 
-    public synchronized void setJdbcUrl(String string) {
-        super.setUrl(string);
-    }
+    private static class TransactionManagerWrapper implements TransactionManager {
+
+        private final TransactionManager transactionManager;
+        private final String name;
+
+        private TransactionManagerWrapper(TransactionManager transactionManager, String name) {
+            this.transactionManager = transactionManager;
+            this.name = name;
+        }
+
+        public void begin() throws NotSupportedException, SystemException {
+            transactionManager.begin();
+        }
+
+        public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
+            transactionManager.commit();
+        }
+
+        public int getStatus() throws SystemException {
+            return transactionManager.getStatus();
+        }
+
+        public Transaction getTransaction() throws SystemException {
+            Transaction tx = transactionManager.getTransaction();
+            return tx == null? null: new TransactionWrapper(transactionManager.getTransaction(), name);
+        }
+
+        public void resume(Transaction transaction) throws IllegalStateException, InvalidTransactionException, SystemException {
+            transactionManager.resume(((TransactionWrapper)transaction).transaction);
+        }
+
+        public void rollback() throws IllegalStateException, SecurityException, SystemException {
+            transactionManager.rollback();
+        }
+
+        public void setRollbackOnly() throws IllegalStateException, SystemException {
+            transactionManager.setRollbackOnly();
+        }
 
-    public synchronized void setDefaultTransactionIsolation(String s) {
-        if (s == null || s.equals("")) return;
-        int level = IsolationLevels.getIsolationLevel(s);
-        super.setDefaultTransactionIsolation(level);
+        public void setTransactionTimeout(int i) throws SystemException {
+            transactionManager.setTransactionTimeout(i);
+        }
+
+        public Transaction suspend() throws SystemException {
+            return new TransactionWrapper(transactionManager.suspend(), name);
+        }
     }
-    
-    protected synchronized DataSource createDataSource() throws SQLException {
-        if (dataSource != null) {
-            return dataSource;
-        }
-
-        // get the plugin
-        DataSourcePlugin helper = BasicDataSourceUtil.getDataSourcePlugin(getUrl());
-
-        // configure this
-        if (helper != null) {
-            helper.configure(this);
-        }
-
-        // creat the data source
-        if (helper == null || !helper.enableUserDirHack()) {
-            return super.createDataSource();
-        } else {
-            // wrap super call with code that sets user.dir to openejb.base and then resets it
-            Properties systemProperties = System.getProperties();
-            synchronized (systemProperties) {
-                String userDir = systemProperties.getProperty("user.dir");
-                try {
-                    File base = SystemInstance.get().getBase().getDirectory();
-                    systemProperties.setProperty("user.dir", base.getAbsolutePath());
-                    return super.createDataSource();
-                } finally {
-                    systemProperties.setProperty("user.dir", userDir);
-                }
-            }
+
+    private static class TransactionWrapper implements Transaction {
+
+        private final Transaction transaction;
+        private final String name;
+
+        private TransactionWrapper(Transaction transaction, String name) {
+            this.transaction = transaction;
+            this.name = name;
+        }
+
+        public void commit() throws HeuristicMixedException, HeuristicRollbackException, RollbackException, SecurityException, SystemException {
+            transaction.commit();
+        }
+
+        public boolean delistResource(XAResource xaResource, int i) throws IllegalStateException, SystemException {
+            XAResource wrapper = new WrapperNamedXAResource(xaResource, name);
+            return transaction.delistResource(wrapper, i);
+        }
+
+        public boolean enlistResource(XAResource xaResource) throws IllegalStateException, RollbackException, SystemException {
+            XAResource wrapper = new WrapperNamedXAResource(xaResource, name);
+            return transaction.enlistResource(wrapper);
+        }
+
+        public int getStatus() throws SystemException {
+            return transaction.getStatus();
+        }
+
+        public void registerSynchronization(Synchronization synchronization) throws IllegalStateException, RollbackException, SystemException {
+            transaction.registerSynchronization(synchronization);
+        }
+
+        public void rollback() throws IllegalStateException, SystemException {
+            transaction.rollback();
+        }
+
+        public void setRollbackOnly() throws IllegalStateException, SystemException {
+            transaction.setRollbackOnly();
+        }
+
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+
+            TransactionWrapper that = (TransactionWrapper) o;
+
+            return transaction.equals(that.transaction);
+        }
+
+        public int hashCode() {
+            return transaction.hashCode();
         }
     }
-}
+}
\ No newline at end of file

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml?rev=637548&r1=637547&r2=637548&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml Sat Mar 15 23:48:50 2008
@@ -176,7 +176,7 @@
           id="Default MDB Container"
           service="Container"
           types="MESSAGE"
-          constructor="id, transactionManager, securityService, ResourceAdapter, MessageListenerInterface, ActivationSpecClass, InstanceLimit"
+          constructor="id, transactionManager, securityService, ResourceAdapter, MessageListenerInterface, ActivationSpecClass, InstanceLimit, TxRecovery"
           class-name="org.apache.openejb.core.mdb.MdbContainer">
 
     # The resource adapter delivers messages to the container
@@ -196,6 +196,10 @@
 
     InstanceLimit 10
 
+    # Specifies whether to use NamedXAResource wrappers to allow the geronimo tm
+    # to log and recover in doubt transactions.
+    TxRecovery false
+
   </ServiceProvider>
 
   <!--
@@ -235,7 +239,24 @@
           id="Default Transaction Manager"
           service="TransactionManager"
           types="TransactionManager"
-          class-name="org.apache.geronimo.transaction.manager.GeronimoTransactionManager"/>
+          factory-name="create"
+          constructor="defaultTransactionTimeoutSeconds, tmId, bufferClassName, bufferSizeKb, checksumEnabled, adler32Checksum, flushSleepTimeMilliseconds, logFileDir, logFileExt, logFileName, maxBlocksPerFile, maxBuffers, maxLogFiles, minBuffers, threadsWaitingForceThreshold"
+          class-name="org.apache.openejb.resource.GeronimoTransactionManagerFactory">
+         defaultTransactionTimeoutSeconds 600
+         bufferSizeKb 32
+         checksumEnabled true
+         adler32Checksum true
+         flushSleepTimeMilliseconds 50
+         logFileDir txlog
+         logFileExt log
+         logFileName howl
+         maxBlocksPerFile -1
+         maxBuffers 0
+      # set to 0 or less to disable transaction logging and recovery
+         maxLogFiles 0
+         minBuffers 4
+         threadsWaitingForceThreshold -1
+  </ServiceProvider>
 
   <!--
   # ================================================
@@ -247,7 +268,7 @@
           service="Resource"
           types="javax.sql.DataSource, DataSource"
           factory-name="create"
-          constructor="JtaManaged"
+          constructor="JtaManaged, TxRecovery"
           class-name="org.apache.openejb.resource.jdbc.DataSourceFactory">
 
     # Determines wether or not this data source should be JTA managed
@@ -262,6 +283,10 @@
 
     JtaManaged = true
 
+    # Specifies whether to use NamedXAResource wrappers to allow the geronimo tm
+    # to log and recover in doubt transactions.
+    TxRecovery false
+
     # Driver class name
 
     JdbcDriver org.hsqldb.jdbcDriver
@@ -441,10 +466,11 @@
           service="Resource"
           types="javax.sql.DataSource, DataSource"
           factory-name="create"
-          constructor="JtaManaged"
+          constructor="JtaManaged, TxRecovery"
           class-name="org.apache.openejb.resource.jdbc.DataSourceFactory">
 
     JtaManaged = false
+    TxRecovery = false
 
     # Driver class name
 
@@ -638,9 +664,9 @@
     # Broker configuration
     BrokerXmlConfig broker:(tcp://localhost:61616)?useJmx=false
 
-    # Broker address
-      # ServerUrl vm://localhost?async=true
-      ServerUrl tcp://localhost:61616
+    # Broker address (vm transport may not work with TxRecovery on)
+    ServerUrl vm://localhost?async=true
+    # ServerUrl tcp://localhost:61616
 
 
     # DataSource for persistence messages

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml?rev=637548&r1=637547&r2=637548&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml Sat Mar 15 23:48:50 2008
@@ -181,7 +181,7 @@
           id="Default MDB Container"
           service="Container"
           types="MESSAGE"
-          constructor="id, transactionManager, securityService, ResourceAdapter, MessageListenerInterface, ActivationSpecClass, InstanceLimit"
+          constructor="id, transactionManager, securityService, ResourceAdapter, MessageListenerInterface, ActivationSpecClass, InstanceLimit, TxRecovery"
           class-name="org.apache.openejb.core.mdb.MdbContainer">
 
     # The resource adapter delivers messages to the container
@@ -201,6 +201,10 @@
 
     InstanceLimit 10
 
+    # Specifies whether to use NamedXAResource wrappers to allow the geronimo tm
+    # to log and recover in doubt transactions.
+    TxRecovery true
+
   </ServiceProvider>
 
   <!--
@@ -236,11 +240,28 @@
   # Default Transaction Manager implementation
   # ================================================
   -->
-  <ServiceProvider
-          id="Default Transaction Manager"
-          service="TransactionManager"
-          types="TransactionManager"
-          class-name="org.apache.geronimo.transaction.manager.GeronimoTransactionManager"/>
+    <ServiceProvider
+            id="Default Transaction Manager"
+            service="TransactionManager"
+            types="TransactionManager"
+            factory-name="create"
+            constructor="defaultTransactionTimeoutSeconds, tmId, bufferClassName, bufferSizeKb, checksumEnabled, adler32Checksum, flushSleepTimeMilliseconds, logFileDir, logFileExt, logFileName, maxBlocksPerFile, maxBuffers, maxLogFiles, minBuffers, threadsWaitingForceThreshold"
+            class-name="org.apache.openejb.resource.GeronimoTransactionManagerFactory">
+           defaultTransactionTimeoutSeconds 600
+           bufferSizeKb 32
+           checksumEnabled true
+           adler32Checksum true
+           flushSleepTimeMilliseconds 50
+           logFileDir txlog
+           logFileExt log
+           logFileName howl
+           maxBlocksPerFile -1
+           maxBuffers 0
+        # set to 0 or less to disable transaction logging and recovery
+           maxLogFiles 2
+           minBuffers 4
+           threadsWaitingForceThreshold -1
+    </ServiceProvider>
 
   <!--
   # ================================================
@@ -252,7 +273,7 @@
           service="Resource"
           types="javax.sql.DataSource, DataSource"
           factory-name="create"
-          constructor="JtaManaged"
+          constructor="JtaManaged,TxRecovery"
           class-name="org.apache.openejb.resource.jdbc.DataSourceFactory">
 
     # Determines wether or not this data source should be JTA managed
@@ -267,6 +288,10 @@
 
     JtaManaged = true
 
+    # Specifies whether to use NamedXAResource wrappers to allow the geronimo tm
+    # to log and recover in doubt transactions.
+    TxRecovery true
+
     # Driver class name
 
     JdbcDriver org.hsqldb.jdbcDriver
@@ -446,10 +471,12 @@
           service="Resource"
           types="javax.sql.DataSource, DataSource"
           factory-name="create"
-          constructor="JtaManaged"
+          constructor="JtaManaged,TxRecovery"
           class-name="org.apache.openejb.resource.jdbc.DataSourceFactory">
 
     JtaManaged = false
+    TxRecovery true
+
 
     # Driver class name
 

Modified: openejb/trunk/openejb3/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/pom.xml?rev=637548&r1=637547&r2=637548&view=diff
==============================================================================
--- openejb/trunk/openejb3/pom.xml (original)
+++ openejb/trunk/openejb3/pom.xml Sat Mar 15 23:48:50 2008
@@ -643,6 +643,11 @@
         </exclusions>
       </dependency>
       <dependency>
+        <groupId>org.objectweb.howl</groupId>
+        <artifactId>howl</artifactId>
+        <version>1.0.1-1</version>
+      </dependency>
+      <dependency>
         <groupId>org.apache.geronimo.javamail</groupId>
         <artifactId>geronimo-javamail_1.4_mail</artifactId>
         <version>1.2</version>



Re: svn commit: r637548 - in /openejb/trunk/openejb3: ./ assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/ container/openejb-core/ container/openejb-core/src/main/java/org/apache/openejb/core/mdb/ containe...

Posted by Dain Sundstrom <da...@iq80.com>.
On Mar 15, 2008, at 11:48 PM, djencks@apache.org wrote:

> +    <ServiceProvider
> +            id="Default Transaction Manager"
> +            service="TransactionManager"
> +            types="TransactionManager"
> +            factory-name="create"
> +            constructor="defaultTransactionTimeoutSeconds, tmId,  
> bufferClassName, bufferSizeKb, checksumEnabled, adler32Checksum,  
> flushSleepTimeMilliseconds, logFileDir, logFileExt, logFileName,  
> maxBlocksPerFile, maxBuffers, maxLogFiles, minBuffers,  
> threadsWaitingForceThreshold"
> +            class- 
> name="org.apache.openejb.resource.GeronimoTransactionManagerFactory">

If you have a custom factory class, it is better to not use  
constructor injection, so you don't have to do stuff like maintain  
that huge constructor arg list above.  It also make is easy for people  
to reuse the factory in test cases.

-dain