[jboss-cvs] JBossAS SVN: r95683 - in projects/jboss-osgi/trunk: reactor/jta/src/main/java/org/jboss/osgi/jta/internal and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 28 10:57:50 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-10-28 10:57:49 -0400 (Wed, 28 Oct 2009)
New Revision: 95683
Added:
projects/jboss-osgi/trunk/reactor/jta/src/main/java/org/jboss/osgi/jta/internal/UserTransactionServiceFactory.java
Modified:
projects/jboss-osgi/trunk/reactor/jta/pom.xml
projects/jboss-osgi/trunk/reactor/jta/src/main/java/org/jboss/osgi/jta/internal/TransactionServiceActivator.java
projects/jboss-osgi/trunk/reactor/jta/src/test/java/org/jboss/test/osgi/jta/UserTransactionTestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jta/ut/UserTransactionActivator.java
Log:
More work on JTA integration
Modified: projects/jboss-osgi/trunk/reactor/jta/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/jta/pom.xml 2009-10-28 14:17:58 UTC (rev 95682)
+++ projects/jboss-osgi/trunk/reactor/jta/pom.xml 2009-10-28 14:57:49 UTC (rev 95683)
@@ -51,11 +51,19 @@
<groupId>jboss.jbossts</groupId>
<artifactId>jbossjts</artifactId>
<version>${version.jboss.jbossts}</version>
+ <!--
+ <scope>system</scope>
+ <systemPath>/home/tdiesler/svn/jboss-osgi/trunk/reactor/jta/jbossjts.jar</systemPath>
+ -->
</dependency>
<dependency>
<groupId>jboss.jbossts</groupId>
<artifactId>jbossts-common</artifactId>
<version>${version.jboss.jbossts}</version>
+ <!--
+ <scope>system</scope>
+ <systemPath>/home/tdiesler/svn/jboss-osgi/trunk/reactor/jta/jbossts-common.jar</systemPath>
+ -->
</dependency>
<!-- OSGi Dependencies -->
@@ -101,9 +109,11 @@
javax.management,
javax.naming,
javax.naming.spi,
+ javax.transaction,
javax.xml.parsers,
org.apache.commons.logging,
org.jboss.osgi.spi.capability,
+ org.jboss.osgi.spi.util,
org.osgi.framework,
org.w3c.dom,
Modified: projects/jboss-osgi/trunk/reactor/jta/src/main/java/org/jboss/osgi/jta/internal/TransactionServiceActivator.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/jta/src/main/java/org/jboss/osgi/jta/internal/TransactionServiceActivator.java 2009-10-28 14:17:58 UTC (rev 95682)
+++ projects/jboss-osgi/trunk/reactor/jta/src/main/java/org/jboss/osgi/jta/internal/TransactionServiceActivator.java 2009-10-28 14:57:49 UTC (rev 95683)
@@ -28,8 +28,11 @@
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
+import com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction;
+
/**
* A transaction services activator
*
@@ -48,13 +51,16 @@
{
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ class BaseTransactionHack extends BaseTransaction {};
+ new BaseTransactionHack();
+
// Register the TransactionManager service
TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
transactionManagerReg = context.registerService(TransactionManager.class.getName(), tm, null);
// Register the UserTransaction service
- UserTransaction ut = com.arjuna.ats.jta.UserTransaction.userTransaction();
- userTransactionReg = context.registerService(UserTransaction.class.getName(), ut, null);
+ ServiceFactory txFactory = new UserTransactionServiceFactory();
+ userTransactionReg = context.registerService(UserTransaction.class.getName(), txFactory, null);
}
finally
{
Added: projects/jboss-osgi/trunk/reactor/jta/src/main/java/org/jboss/osgi/jta/internal/UserTransactionServiceFactory.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/jta/src/main/java/org/jboss/osgi/jta/internal/UserTransactionServiceFactory.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/jta/src/main/java/org/jboss/osgi/jta/internal/UserTransactionServiceFactory.java 2009-10-28 14:57:49 UTC (rev 95683)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.jta.internal;
+
+//$Id$
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import javax.transaction.UserTransaction;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * A service factory for the user transaction
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 28-Oct-2009
+ */
+public class UserTransactionServiceFactory implements ServiceFactory
+{
+ public Object getService(Bundle bundle, ServiceRegistration registration)
+ {
+ ClassLoader classLoader = getClass().getClassLoader();
+ UserTransactionProxy handler = new UserTransactionProxy(classLoader);
+ return Proxy.newProxyInstance(classLoader, new Class[] { UserTransaction.class }, handler);
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
+ {
+ // nothing to do
+ }
+
+ /**
+ * Wraps every invocation on the UserTransaction to make the context class loader available
+ */
+ class UserTransactionProxy implements InvocationHandler
+ {
+ private UserTransaction tx;
+ private ClassLoader classLoader;
+
+ public UserTransactionProxy(ClassLoader classLoader)
+ {
+ this.tx = com.arjuna.ats.jta.UserTransaction.userTransaction();
+ this.classLoader = classLoader;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ return method.invoke(tx, args);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(ctxLoader);
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/jta/src/main/java/org/jboss/osgi/jta/internal/UserTransactionServiceFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/trunk/reactor/jta/src/test/java/org/jboss/test/osgi/jta/UserTransactionTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/jta/src/test/java/org/jboss/test/osgi/jta/UserTransactionTestCase.java 2009-10-28 14:17:58 UTC (rev 95682)
+++ projects/jboss-osgi/trunk/reactor/jta/src/test/java/org/jboss/test/osgi/jta/UserTransactionTestCase.java 2009-10-28 14:57:49 UTC (rev 95683)
@@ -29,6 +29,8 @@
import org.junit.Test;
+import com.arjuna.common.util.propertyservice.plugins.PropertyManagerIOPlugin;
+
/**
* Test basic JBossTM operations
*
@@ -42,5 +44,14 @@
{
UserTransaction ut = com.arjuna.ats.jta.UserTransaction.userTransaction();
assertNotNull("UserTransaction not null", ut);
+
+ /*
+ System.out.println("");
+ new RuntimeException().printStackTrace(System.out);
+ System.out.println("Thread: " + Thread.currentThread() + " - " + Thread.currentThread().getContextClassLoader());
+ System.out.println("PropertyManager: " + this);
+ System.out.println("PropertyManager: " + getClass().getClassLoader());
+ System.out.println("PropertyManagerIOPlugin: " + PropertyManagerIOPlugin.class.getClassLoader());
+ */
}
}
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jta/ut/UserTransactionActivator.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jta/ut/UserTransactionActivator.java 2009-10-28 14:17:58 UTC (rev 95682)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/jta/ut/UserTransactionActivator.java 2009-10-28 14:57:49 UTC (rev 95683)
@@ -49,17 +49,17 @@
UserTransaction tx = (UserTransaction)context.getService(sref);
assertNotNull("UserTransaction not null", tx);
-// tx.begin();
-// try
-// {
-// doStuff();
-// tx.commit();
-// }
-// catch (Exception e)
-// {
-// tx.setRollbackOnly();
-// }
-// assertEquals(Status.STATUS_COMMITTED, tx.getStatus());
+ tx.begin();
+ try
+ {
+ doStuff();
+ tx.commit();
+ }
+ catch (Exception e)
+ {
+ tx.setRollbackOnly();
+ }
+ assertEquals(Status.STATUS_COMMITTED, tx.getStatus());
}
public void stop(BundleContext context) throws Exception
More information about the jboss-cvs-commits
mailing list