[jboss-cvs] JBossAS SVN: r71714 - in projects/ejb3/branches/cluster-dev/cache/src: main/java/org/jboss/ejb3/cache/spi and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 3 17:47:45 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-04-03 17:47:44 -0400 (Thu, 03 Apr 2008)
New Revision: 71714
Added:
projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/JndiTransactionSynchronizationRegistrySource.java
projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/TransactionSynchronizationRegistrySource.java
projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransactionSynchroniztionRegistry.java
Modified:
projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/impl/TransactionalCache.java
projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/SynchronizationCoordinator.java
projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/SynchronizationCoordinatorImpl.java
projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/MockEjb3System.java
projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransaction.java
projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransactionManager.java
Log:
[EJBTHREE-1026] Use TransactionSynchronizationRegistry to ensure in javax.ejb.SessionSynchronization beforeCompletion() executes before cache release
Modified: projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/impl/TransactionalCache.java
===================================================================
--- projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/impl/TransactionalCache.java 2008-04-03 20:39:46 UTC (rev 71713)
+++ projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/impl/TransactionalCache.java 2008-04-03 21:47:44 UTC (rev 71714)
@@ -27,7 +27,6 @@
import java.util.concurrent.locks.ReentrantLock;
import javax.ejb.NoSuchEJBException;
-import javax.transaction.RollbackException;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
@@ -358,18 +357,7 @@
if (tx != null)
{
CacheReleaseSynchronization<C, T> sync = new CacheReleaseSynchronization<C, T>(this, cacheItem, tx);
- try
- {
- synchronizationCoordinator.addSynchronizationFirst(tx, sync);
- }
- catch (RollbackException e)
- {
- throw new RuntimeException("Failed registering synchronization for " + cacheItem, e);
- }
- catch (SystemException e)
- {
- throw new RuntimeException("Failed registering synchronization for " + cacheItem, e);
- }
+ synchronizationCoordinator.addSynchronizationFirst(sync);
synchronizations.put(cacheItem.getId(), sync);
}
}
Modified: projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/SynchronizationCoordinator.java
===================================================================
--- projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/SynchronizationCoordinator.java 2008-04-03 20:39:46 UTC (rev 71713)
+++ projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/SynchronizationCoordinator.java 2008-04-03 21:47:44 UTC (rev 71714)
@@ -22,22 +22,32 @@
package org.jboss.ejb3.cache.spi;
-import javax.transaction.RollbackException;
import javax.transaction.Synchronization;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
/**
- * Coordinates order of transaction {@link Synchronization} execution, allowing
- * different elements of the caching system to ensure their synchronization
+ * Coordinates order of transaction {@link Synchronization} execution. In
+ * particular it:
+ * <ol>
+ * <li>
+ * Ensures that any registered synchronization's <code>beforeCompletion()</code>
+ * is invoked after any {@link javax.ejb.SessionSynchronization#beforeCompletion()}
+ * and that any registered synchronization's <code>afterCompletion()</code>
+ * is invoked before any {@link javax.ejb.SessionSynchronization#afterCompletion()}.
+ * </li>
+ * <li>
+ * Allows different elements of the caching system to ensure their synchronization
* executes either relatively early or relatively late in the transaction
* commit process.
+ * </li>
+ * </ol>
* <p>
* Note that a <code>SynchronizationCoordinator</code> has no effect on the
* order of execution of synchronizations it doesn't know about (e.g. those
* registered by code external to the caching subsystem.)
* </p>
*
+ * @see javax.transaction.TransactionSynchronizationRegistry#registerInterposedSynchronization(Synchronization)
+ *
* @author Brian Stansberry
*/
public interface SynchronizationCoordinator
@@ -51,11 +61,9 @@
* @param tx the transaction
* @param sync the synchronization
*
- * @throws RollbackException
- * @throws SystemException
+ * @throws IllegalStateException if no transaction is active
*/
- void addSynchronizationFirst(Transaction tx, Synchronization sync)
- throws RollbackException, SystemException;
+ void addSynchronizationFirst(Synchronization sync);
/**
* Register the given Synchronization with the given Transaction,
@@ -66,9 +74,7 @@
* @param tx the transaction
* @param sync the synchronization
*
- * @throws RollbackException
- * @throws SystemException
+ * @throws IllegalStateException if no transaction is active
*/
- void addSynchronizationLast(Transaction tx, Synchronization sync)
- throws RollbackException, SystemException;
+ void addSynchronizationLast(Synchronization sync);
}
Added: projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/JndiTransactionSynchronizationRegistrySource.java
===================================================================
--- projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/JndiTransactionSynchronizationRegistrySource.java (rev 0)
+++ projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/JndiTransactionSynchronizationRegistrySource.java 2008-04-03 21:47:44 UTC (rev 71714)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.cache.spi.impl;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.TransactionSynchronizationRegistry;
+
+/**
+ * {@link TransactionSynchronizationRegistrySource} that gets its registry
+ * by doing a JNDI lookup of the standard name
+ * <code>java:comp/TransactionSynchronizationRegistry</code>.
+ *
+ * @author Brian Stansberry
+ */
+public class JndiTransactionSynchronizationRegistrySource implements TransactionSynchronizationRegistrySource
+{
+ public static final String STANDARD_JNDI_NAME = "java:comp/TransactionSynchronizationRegistry";
+
+ public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry()
+ {
+ try
+ {
+ return (TransactionSynchronizationRegistry) new InitialContext().lookup(STANDARD_JNDI_NAME);
+ }
+ catch (NamingException e)
+ {
+ throw new RuntimeException("Cannot find TransactionSynchronizationRegistry", e);
+ }
+ }
+
+}
Modified: projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/SynchronizationCoordinatorImpl.java
===================================================================
--- projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/SynchronizationCoordinatorImpl.java 2008-04-03 20:39:46 UTC (rev 71713)
+++ projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/SynchronizationCoordinatorImpl.java 2008-04-03 21:47:44 UTC (rev 71714)
@@ -26,75 +26,95 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import javax.transaction.RollbackException;
import javax.transaction.Synchronization;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
+import javax.transaction.TransactionSynchronizationRegistry;
import org.jboss.ejb3.cache.spi.SynchronizationCoordinator;
import org.jboss.logging.Logger;
/**
+ * Default implementation of {@link SynchronizationCoordinator}.
+ *
* @author Brian Stansberry
- *
*/
public class SynchronizationCoordinatorImpl implements SynchronizationCoordinator
{
private static final Logger log = Logger.getLogger(SynchronizationCoordinatorImpl.class);
- private ConcurrentMap<Transaction, OrderedSynchronizationHandler> handlers =
- new ConcurrentHashMap<Transaction, OrderedSynchronizationHandler>();
+ private ConcurrentMap<Object, OrderedSynchronizationHandler> handlers =
+ new ConcurrentHashMap<Object, OrderedSynchronizationHandler>();
- public void addSynchronizationFirst(Transaction tx, Synchronization sync)
- throws RollbackException, SystemException
+ private TransactionSynchronizationRegistrySource registrySource;
+
+ public void addSynchronizationFirst(Synchronization sync)
{
- getHandler(tx).registerAtHead(sync);
+ getHandler().registerAtHead(sync);
}
- public void addSynchronizationLast(Transaction tx, Synchronization sync)
- throws RollbackException, SystemException
+ public void addSynchronizationLast(Synchronization sync)
{
- getHandler(tx).registerAtTail(sync);
+ getHandler().registerAtTail(sync);
}
- private OrderedSynchronizationHandler getHandler(Transaction tx) throws RollbackException, SystemException
+ public void start()
{
- OrderedSynchronizationHandler handler = handlers.get(tx);
+ if (registrySource == null)
+ {
+ registrySource = new JndiTransactionSynchronizationRegistrySource();
+ }
+ }
+
+ public TransactionSynchronizationRegistrySource getTransactionSynchronizationRegistrySource()
+ {
+ return registrySource;
+ }
+
+ public void setTransactionSynchronizationRegistrySource(TransactionSynchronizationRegistrySource registrySource)
+ {
+ this.registrySource = registrySource;
+ }
+
+ private OrderedSynchronizationHandler getHandler()
+ {
+ TransactionSynchronizationRegistry syncRegistry = registrySource.getTransactionSynchronizationRegistry();
+ Object txId = syncRegistry.getTransactionKey();
+
+ OrderedSynchronizationHandler handler = handlers.get(txId);
if (handler == null)
{
- handler = new OrderedSynchronizationHandler(tx, this);
- OrderedSynchronizationHandler old = handlers.putIfAbsent(tx, handler);
+ handler = new OrderedSynchronizationHandler(txId, this);
+ OrderedSynchronizationHandler old = handlers.putIfAbsent(txId, handler);
if (old != null)
{
handler = old;
}
else
{
- tx.registerSynchronization(handler);
+ syncRegistry.registerInterposedSynchronization(handler);
}
}
return handler;
}
- private void removeHandler(Transaction tx)
+ private void removeHandler(Object txId)
{
- handlers.remove(tx);
+ handlers.remove(txId);
}
private static class OrderedSynchronizationHandler implements Synchronization
{
- private Transaction tx = null;
+ private Object txId = null;
private SynchronizationCoordinatorImpl coordinator;
private final LinkedList<Synchronization> synchronizations = new LinkedList<Synchronization>();
- private OrderedSynchronizationHandler(Transaction tx, SynchronizationCoordinatorImpl coordinator)
+ private OrderedSynchronizationHandler(Object txId, SynchronizationCoordinatorImpl coordinator)
{
- assert tx != null : "tx is null";
+ assert txId != null : "txId is null";
assert coordinator != null : "coordinator is null";
- this.tx = tx;
+ this.txId = txId;
this.coordinator = coordinator;
}
@@ -145,8 +165,8 @@
}
// finally unregister us from the hashmap
- coordinator.removeHandler(tx);
- tx = null;
+ coordinator.removeHandler(txId);
+ txId = null;
// throw the exception so the TM can deal with it.
if (exceptionInAfterCompletion != null) throw exceptionInAfterCompletion;
@@ -155,18 +175,9 @@
public String toString()
{
StringBuffer sb = new StringBuffer();
- sb.append("tx=" + getTxAsString() + ", handlers=" + synchronizations);
+ sb.append("txId=" + txId + ", handlers=" + synchronizations);
return sb.toString();
}
- private String getTxAsString()
- {
- // Don't call toString() on tx or it can lead to stack overflow
- if (tx == null)
- return null;
-
- return tx.getClass().getName() + "@" + System.identityHashCode(tx);
- }
-
}
}
Added: projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/TransactionSynchronizationRegistrySource.java
===================================================================
--- projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/TransactionSynchronizationRegistrySource.java (rev 0)
+++ projects/ejb3/branches/cluster-dev/cache/src/main/java/org/jboss/ejb3/cache/spi/impl/TransactionSynchronizationRegistrySource.java 2008-04-03 21:47:44 UTC (rev 71714)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.cache.spi.impl;
+
+import javax.transaction.TransactionSynchronizationRegistry;
+
+/**
+ * Provides access to a {@link TransactionSynchronizationRegistry}.
+ *
+ * @author Brian Stansberry
+ */
+public interface TransactionSynchronizationRegistrySource
+{
+ TransactionSynchronizationRegistry getTransactionSynchronizationRegistry();
+}
Modified: projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/MockEjb3System.java
===================================================================
--- projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/MockEjb3System.java 2008-04-03 20:39:46 UTC (rev 71713)
+++ projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/MockEjb3System.java 2008-04-03 21:47:44 UTC (rev 71714)
@@ -36,6 +36,7 @@
import org.jboss.ejb3.cache.spi.BackingCacheEntryStoreSource;
import org.jboss.ejb3.cache.spi.PassivationExpirationCoordinator;
import org.jboss.ejb3.cache.spi.impl.AbstractStatefulCacheFactory;
+import org.jboss.ejb3.cache.spi.impl.SynchronizationCoordinatorImpl;
import org.jboss.ejb3.test.cache.mock.tm.MockTransactionManager;
/**
@@ -162,6 +163,12 @@
factory.setPassivationExpirationCoordinator(coordinator);
// Process passivation/expiration as quickly as possible so tests run fast
factory.setDefaultPassivationExpirationInterval(1);
+ if (tm instanceof MockTransactionManager)
+ {
+ SynchronizationCoordinatorImpl sci = new SynchronizationCoordinatorImpl();
+ sci.setTransactionSynchronizationRegistrySource((MockTransactionManager) tm);
+ factory.setSynchronizationCoordinator(sci);
+ }
factory.start();
}
return factory;
Modified: projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransaction.java
===================================================================
--- projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransaction.java 2008-04-03 20:39:46 UTC (rev 71713)
+++ projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransaction.java 2008-04-03 21:47:44 UTC (rev 71714)
@@ -24,6 +24,7 @@
package org.jboss.ejb3.test.cache.mock.tm;
import java.util.LinkedList;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
@@ -32,6 +33,7 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
+import javax.transaction.TransactionSynchronizationRegistry;
import javax.transaction.xa.XAResource;
import org.jboss.logging.Logger;
@@ -45,17 +47,27 @@
{
private static final Logger log = Logger.getLogger(MockTransaction.class);
+ private static final AtomicInteger count = new AtomicInteger();
+
private int status;
+ private final String id;
- private LinkedList<Synchronization> synchronizations;
-
+ private LinkedList<Synchronization> synchronizations = new LinkedList<Synchronization>();
+ private MockTransactionSynchroniztionRegistry syncRegistry;
+
private final MockTransactionManager jtaTransactionManager;
public MockTransaction(MockTransactionManager jtaTransactionManager)
{
this.jtaTransactionManager = jtaTransactionManager;
this.status = Status.STATUS_ACTIVE;
+ this.id = "MockTransaction-" + count.incrementAndGet();
}
+
+ public String getId()
+ {
+ return id;
+ }
public int getStatus()
{
@@ -81,10 +93,26 @@
s.beforeCompletion();
}
+ if (syncRegistry != null)
+ {
+ for (Synchronization sync : syncRegistry.getSynchronizations())
+ {
+ sync.beforeCompletion();
+ }
+ }
+
status = Status.STATUS_COMMITTING;
status = Status.STATUS_COMMITTED;
+ if (syncRegistry != null)
+ {
+ for (Synchronization sync : syncRegistry.getSynchronizations())
+ {
+ sync.afterCompletion(status);
+ }
+ }
+
for (int i = 0; i < synchronizations.size(); i++)
{
Synchronization s = (Synchronization) synchronizations.get(i);
@@ -100,6 +128,14 @@
{
status = Status.STATUS_ROLLEDBACK;
+ if (syncRegistry != null)
+ {
+ for (Synchronization sync : syncRegistry.getSynchronizations())
+ {
+ sync.afterCompletion(status);
+ }
+ }
+
if (synchronizations != null)
{
for (int i = 0; i < synchronizations.size(); i++)
@@ -122,10 +158,6 @@
IllegalStateException, SystemException
{
// todo : find the spec-allowable statuses during which synch can be registered...
- if (synchronizations == null)
- {
- synchronizations = new LinkedList<Synchronization>();
- }
synchronizations.add(synchronization);
}
@@ -139,4 +171,13 @@
{
return false;
}
+
+ public synchronized TransactionSynchronizationRegistry getTransactionSynchronizationRegistry()
+ {
+ if (syncRegistry == null)
+ {
+ syncRegistry = new MockTransactionSynchroniztionRegistry(this);
+ }
+ return syncRegistry;
+ }
}
Modified: projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransactionManager.java
===================================================================
--- projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransactionManager.java 2008-04-03 20:39:46 UTC (rev 71713)
+++ projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransactionManager.java 2008-04-03 21:47:44 UTC (rev 71714)
@@ -34,7 +34,9 @@
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
+import javax.transaction.TransactionSynchronizationRegistry;
+import org.jboss.ejb3.cache.spi.impl.TransactionSynchronizationRegistrySource;
import org.jboss.logging.Logger;
/**
@@ -43,7 +45,7 @@
*
* @author Brian Stansberry
*/
-public class MockTransactionManager implements TransactionManager
+public class MockTransactionManager implements TransactionManager, TransactionSynchronizationRegistrySource
{
public static final String DEFAULT = "default";
@@ -163,6 +165,16 @@
public void setTransactionTimeout(int i) throws SystemException
{
}
+
+ public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry()
+ {
+ if (currentTransaction.get() == null)
+ {
+ throw new IllegalStateException("no current transaction");
+ }
+ return currentTransaction.get().getTransactionSynchronizationRegistry();
+
+ }
void endCurrent(MockTransaction transaction)
{
Added: projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransactionSynchroniztionRegistry.java
===================================================================
--- projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransactionSynchroniztionRegistry.java (rev 0)
+++ projects/ejb3/branches/cluster-dev/cache/src/test/java/org/jboss/ejb3/test/cache/mock/tm/MockTransactionSynchroniztionRegistry.java 2008-04-03 21:47:44 UTC (rev 71714)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.cache.mock.tm;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionSynchronizationRegistry;
+
+/**
+ * @author Brian Stansberry
+ *
+ */
+public class MockTransactionSynchroniztionRegistry implements TransactionSynchronizationRegistry
+{
+ private final MockTransaction tx;
+ private LinkedList<Synchronization> synchronizations = new LinkedList<Synchronization>();
+
+ public MockTransactionSynchroniztionRegistry(MockTransaction tx)
+ {
+ assert tx != null : "tx is null";
+ this.tx = tx;
+ }
+
+ public Object getResource(Object key) throws IllegalStateException
+ {
+ throw new UnsupportedOperationException("unsupported");
+ }
+
+ public boolean getRollbackOnly() throws IllegalStateException
+ {
+ return false;
+ }
+
+ public Object getTransactionKey()
+ {
+ return tx.getId();
+ }
+
+ public int getTransactionStatus()
+ {
+ return tx.getStatus();
+ }
+
+ public void putResource(Object key, Object value) throws IllegalStateException
+ {
+ throw new UnsupportedOperationException("unsupported");
+ }
+
+ public void registerInterposedSynchronization(Synchronization sync) throws IllegalStateException
+ {
+ synchronizations.add(sync);
+ }
+
+ public void setRollbackOnly() throws IllegalStateException
+ {
+ try
+ {
+ tx.setRollbackOnly();
+ }
+ catch (SystemException e)
+ {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public List<Synchronization> getSynchronizations()
+ {
+ return synchronizations;
+ }
+
+}
More information about the jboss-cvs-commits
mailing list