From c69cfd049c17c5f8d7cfb305a5315db10fb902b4 Mon Sep 17 00:00:00 2001 From: David Jencks Date: Sat, 22 Aug 2009 22:14:17 +0000 Subject: [PATCH] update to spec git-svn-id: https://svn.apache.org/repos/asf/geronimo/components/txmanager/trunk@806899 13f79535-47bb-0310-9956-ffa450edef68 --- .../connector/GeronimoBootstrapContext.java | 10 +++ .../connector/work/GeronimoWorkManager.java | 18 ++-- ...er.java => TransactionContextHandler.java} | 36 ++++---- ...xtHandler.java => WorkContextHandler.java} | 8 +- .../connector/work/WorkerContext.java | 82 +++++++++---------- .../connector/BootstrapContextTest.java | 12 +-- .../connector/work/PooledWorkManagerTest.java | 4 +- 7 files changed, 90 insertions(+), 80 deletions(-) rename geronimo-connector/src/main/java/org/apache/geronimo/connector/work/{TransactionInflowContextHandler.java => TransactionContextHandler.java} (57%) rename geronimo-connector/src/main/java/org/apache/geronimo/connector/work/{InflowContextHandler.java => WorkContextHandler.java} (80%) diff --git a/geronimo-connector/src/main/java/org/apache/geronimo/connector/GeronimoBootstrapContext.java b/geronimo-connector/src/main/java/org/apache/geronimo/connector/GeronimoBootstrapContext.java index 09d7f5a..8847a01 100644 --- a/geronimo-connector/src/main/java/org/apache/geronimo/connector/GeronimoBootstrapContext.java +++ b/geronimo-connector/src/main/java/org/apache/geronimo/connector/GeronimoBootstrapContext.java @@ -21,6 +21,8 @@ import javax.resource.spi.UnavailableException; import javax.resource.spi.XATerminator; import javax.resource.spi.work.WorkManager; +import javax.resource.spi.work.WorkContext; +import javax.transaction.TransactionSynchronizationRegistry; /** * GBean BootstrapContext implementation that refers to externally configured WorkManager @@ -72,4 +74,12 @@ public Timer createTimer() throws UnavailableException { return new Timer(); } + public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() { + return null; + } + + public boolean isContextSupported(Class aClass) { + return false; + } + } diff --git a/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java b/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java index c9ef362..ca53282 100644 --- a/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java +++ b/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java @@ -65,7 +65,7 @@ public class GeronimoWorkManager implements WorkManager { */ private Executor scheduledWorkExecutorPool; - private final Collection inflowContextHandlers; + private final Collection workContextHandlers; private final WorkExecutor scheduleWorkExecutor = new ScheduleWorkExecutor(); @@ -79,11 +79,11 @@ public GeronimoWorkManager() { this(null, null, null, null); } - public GeronimoWorkManager(Executor sync, Executor start, Executor sched, Collection inflowContextHandlers) { + public GeronimoWorkManager(Executor sync, Executor start, Executor sched, Collection workContextHandlers) { syncWorkExecutorPool = sync; startWorkExecutorPool = start; scheduledWorkExecutorPool = sched; - this.inflowContextHandlers = inflowContextHandlers == null ? Collections.emptyList() : inflowContextHandlers; + this.workContextHandlers = workContextHandlers == null ? Collections.emptyList() : workContextHandlers; } public void doStart() throws Exception { @@ -116,7 +116,7 @@ public Executor getScheduledWorkExecutorPool() { * @see javax.resource.spi.work.WorkManager#doWork(javax.resource.spi.work.Work) */ public void doWork(Work work) throws WorkException { - executeWork(new WorkerContext(work, inflowContextHandlers), syncWorkExecutor, syncWorkExecutorPool); + executeWork(new WorkerContext(work, workContextHandlers), syncWorkExecutor, syncWorkExecutorPool); } /* (non-Javadoc) @@ -129,7 +129,7 @@ public void doWork( WorkListener workListener) throws WorkException { WorkerContext workWrapper = - new WorkerContext(work, startTimeout, execContext, workListener, inflowContextHandlers); + new WorkerContext(work, startTimeout, execContext, workListener, workContextHandlers); workWrapper.setThreadPriority(Thread.currentThread().getPriority()); executeWork(workWrapper, syncWorkExecutor, syncWorkExecutorPool); } @@ -138,7 +138,7 @@ public void doWork( * @see javax.resource.spi.work.WorkManager#startWork(javax.resource.spi.work.Work) */ public long startWork(Work work) throws WorkException { - WorkerContext workWrapper = new WorkerContext(work, inflowContextHandlers); + WorkerContext workWrapper = new WorkerContext(work, workContextHandlers); workWrapper.setThreadPriority(Thread.currentThread().getPriority()); executeWork(workWrapper, startWorkExecutor, startWorkExecutorPool); return System.currentTimeMillis() - workWrapper.getAcceptedTime(); @@ -154,7 +154,7 @@ public long startWork( WorkListener workListener) throws WorkException { WorkerContext workWrapper = - new WorkerContext(work, startTimeout, execContext, workListener, inflowContextHandlers); + new WorkerContext(work, startTimeout, execContext, workListener, workContextHandlers); workWrapper.setThreadPriority(Thread.currentThread().getPriority()); executeWork(workWrapper, startWorkExecutor, startWorkExecutorPool); return System.currentTimeMillis() - workWrapper.getAcceptedTime(); @@ -164,7 +164,7 @@ public long startWork( * @see javax.resource.spi.work.WorkManager#scheduleWork(javax.resource.spi.work.Work) */ public void scheduleWork(Work work) throws WorkException { - WorkerContext workWrapper = new WorkerContext(work, inflowContextHandlers); + WorkerContext workWrapper = new WorkerContext(work, workContextHandlers); workWrapper.setThreadPriority(Thread.currentThread().getPriority()); executeWork(workWrapper, scheduleWorkExecutor, scheduledWorkExecutorPool); } @@ -179,7 +179,7 @@ public void scheduleWork( WorkListener workListener) throws WorkException { WorkerContext workWrapper = - new WorkerContext(work, startTimeout, execContext, workListener, inflowContextHandlers); + new WorkerContext(work, startTimeout, execContext, workListener, workContextHandlers); workWrapper.setThreadPriority(Thread.currentThread().getPriority()); executeWork(workWrapper, scheduleWorkExecutor, scheduledWorkExecutorPool); } diff --git a/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/TransactionInflowContextHandler.java b/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/TransactionContextHandler.java similarity index 57% rename from geronimo-connector/src/main/java/org/apache/geronimo/connector/work/TransactionInflowContextHandler.java rename to geronimo-connector/src/main/java/org/apache/geronimo/connector/work/TransactionContextHandler.java index 5bcd0d1..62ed49d 100644 --- a/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/TransactionInflowContextHandler.java +++ b/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/TransactionContextHandler.java @@ -20,7 +20,7 @@ package org.apache.geronimo.connector.work; -import javax.resource.spi.work.TransactionInflowContext; +import javax.resource.spi.work.TransactionContext; import javax.resource.spi.work.WorkCompletedException; import javax.transaction.xa.XAException; import javax.transaction.InvalidTransactionException; @@ -32,46 +32,46 @@ /** * @version $Rev$ $Date$ */ -public class TransactionInflowContextHandler implements InflowContextHandler{ +public class TransactionContextHandler implements WorkContextHandler{ private final XAWork xaWork; - public TransactionInflowContextHandler(XAWork xaWork) { + public TransactionContextHandler(XAWork xaWork) { this.xaWork = xaWork; } - public void before(TransactionInflowContext inflowContext) throws WorkCompletedException { - if (inflowContext.getXid() != null) { + public void before(TransactionContext workContext) throws WorkCompletedException { + if (workContext.getXid() != null) { try { - long transactionTimeout = inflowContext.getTransactionTimeout(); + long transactionTimeout = workContext.getTransactionTimeout(); //translate -1 value to 0 to indicate default transaction timeout. - xaWork.begin(inflowContext.getXid(), transactionTimeout < 0 ? 0 : transactionTimeout); + xaWork.begin(workContext.getXid(), transactionTimeout < 0 ? 0 : transactionTimeout); } catch (XAException e) { - throw (WorkCompletedException)new WorkCompletedException("Transaction import failed for xid " + inflowContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e); + throw (WorkCompletedException)new WorkCompletedException("Transaction import failed for xid " + workContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e); } catch (InvalidTransactionException e) { - throw (WorkCompletedException)new WorkCompletedException("Transaction import failed for xid " + inflowContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e); + throw (WorkCompletedException)new WorkCompletedException("Transaction import failed for xid " + workContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e); } catch (SystemException e) { - throw (WorkCompletedException)new WorkCompletedException("Transaction import failed for xid " + inflowContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e); + throw (WorkCompletedException)new WorkCompletedException("Transaction import failed for xid " + workContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e); } catch (ImportedTransactionActiveException e) { - throw (WorkCompletedException)new WorkCompletedException("Transaction already active for xid " + inflowContext.getXid(), WorkCompletedException.TX_CONCURRENT_WORK_DISALLOWED).initCause(e); + throw (WorkCompletedException)new WorkCompletedException("Transaction already active for xid " + workContext.getXid(), WorkCompletedException.TX_CONCURRENT_WORK_DISALLOWED).initCause(e); } } } - public void after(TransactionInflowContext inflowContext) throws WorkCompletedException { - if (inflowContext.getXid() != null) { + public void after(TransactionContext workContext) throws WorkCompletedException { + if (workContext.getXid() != null) { try { - xaWork.end(inflowContext.getXid()); + xaWork.end(workContext.getXid()); } catch (XAException e) { - throw (WorkCompletedException)new WorkCompletedException("Transaction end failed for xid " + inflowContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e); + throw (WorkCompletedException)new WorkCompletedException("Transaction end failed for xid " + workContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e); } catch (SystemException e) { - throw (WorkCompletedException)new WorkCompletedException("Transaction end failed for xid " + inflowContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e); + throw (WorkCompletedException)new WorkCompletedException("Transaction end failed for xid " + workContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e); } } } - public Class getHandledClass() { - return TransactionInflowContext.class; + public Class getHandledClass() { + return TransactionContext.class; } public boolean required() { diff --git a/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/InflowContextHandler.java b/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkContextHandler.java similarity index 80% rename from geronimo-connector/src/main/java/org/apache/geronimo/connector/work/InflowContextHandler.java rename to geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkContextHandler.java index 5e0ad3c..431de6c 100644 --- a/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/InflowContextHandler.java +++ b/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkContextHandler.java @@ -20,17 +20,17 @@ package org.apache.geronimo.connector.work; -import javax.resource.spi.work.InflowContext; +import javax.resource.spi.work.WorkContext; import javax.resource.spi.work.WorkCompletedException; /** * @version $Rev$ $Date$ */ -public interface InflowContextHandler { +public interface WorkContextHandler { - void before(E inflowContext) throws WorkCompletedException; + void before(E workContext) throws WorkCompletedException; - void after(E inflowContext) throws WorkCompletedException; + void after(E workContext) throws WorkCompletedException; Class getHandledClass(); diff --git a/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkerContext.java b/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkerContext.java index 4f5c2d7..d80fa01 100644 --- a/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkerContext.java +++ b/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkerContext.java @@ -26,9 +26,9 @@ import javax.resource.NotSupportedException; import javax.resource.spi.work.ExecutionContext; -import javax.resource.spi.work.InflowContext; -import javax.resource.spi.work.InflowContextProvider; -import javax.resource.spi.work.TransactionInflowContext; +import javax.resource.spi.work.WorkContext; +import javax.resource.spi.work.WorkContextProvider; +import javax.resource.spi.work.TransactionContext; import javax.resource.spi.work.Work; import javax.resource.spi.work.WorkAdapter; import javax.resource.spi.work.WorkCompletedException; @@ -50,7 +50,7 @@ public class WorkerContext implements Work { private static final Logger log = LoggerFactory.getLogger(WorkerContext.class); - private static final List NO_INFLOW_CONTEXT = Collections.emptyList(); + private static final List NO_INFLOW_CONTEXT = Collections.emptyList(); /** * Null WorkListener used as the default WorkListener. @@ -123,18 +123,18 @@ public void workRejected(WorkEvent event) { */ private final ExecutionContext executionContext; - private final List inflowContextHandlers; + private final List workContextHandlers; /** * Create a WorkWrapper. - * TODO include a InflowContextLifecycleListener + * TODO include a WorkContextLifecycleListener * @param work Work to be wrapped. - * @param inflowContextHandlers InflowContextHandlers supported by this work manager + * @param workContextHandlers WorkContextHandlers supported by this work manager */ - public WorkerContext(Work work, Collection inflowContextHandlers) { + public WorkerContext(Work work, Collection workContextHandlers) { adaptee = work; - this.inflowContextHandlers = new ArrayList(inflowContextHandlers); + this.workContextHandlers = new ArrayList(workContextHandlers); executionContext = null; workListener = NULL_WORK_LISTENER; } @@ -142,20 +142,20 @@ public WorkerContext(Work work, Collection inflowContextHa /** * Create a WorkWrapper with the specified execution context. * - * TODO include a InflowContextLifecycleListener + * TODO include a WorkContextLifecycleListener * @param aWork Work to be wrapped. * @param aStartTimeout a time duration (in milliseconds) within which the * execution of the Work instance must start. * @param execContext an object containing the execution context with which * the submitted Work instance must be executed. * @param workListener an object which would be notified when the various - * @param inflowContextHandlers InflowContextHandlers supported by this work manager - * @throws javax.resource.spi.work.WorkRejectedException if executionContext supplied yet Work implements InflowContextProvider + * @param workContextHandlers WorkContextHandlers supported by this work manager + * @throws javax.resource.spi.work.WorkRejectedException if executionContext supplied yet Work implements WorkContextProvider */ public WorkerContext(Work aWork, long aStartTimeout, ExecutionContext execContext, - WorkListener workListener, Collection inflowContextHandlers) throws WorkRejectedException { + WorkListener workListener, Collection workContextHandlers) throws WorkRejectedException { adaptee = aWork; startTimeOut = aStartTimeout; if (null == workListener) { @@ -163,15 +163,15 @@ public WorkerContext(Work aWork, } else { this.workListener = workListener; } - if (aWork instanceof InflowContextProvider) { + if (aWork instanceof WorkContextProvider) { if (execContext != null) { - throw new WorkRejectedException("Execution context provided but Work implements InflowContextProvider"); + throw new WorkRejectedException("Execution context provided but Work implements WorkContextProvider"); } executionContext = null; } else { executionContext = execContext; } - this.inflowContextHandlers = new ArrayList(inflowContextHandlers); + this.workContextHandlers = new ArrayList(workContextHandlers); } /* (non-Javadoc) @@ -305,59 +305,59 @@ public void run() { //Implementation note: we assume this is being called without an interesting TransactionContext, //and ignore/replace whatever is associated with the current thread. try { - List inflowContexts = NO_INFLOW_CONTEXT; + List workContexts = NO_INFLOW_CONTEXT; if (executionContext != null) { - TransactionInflowContext txInflowContext = new TransactionInflowContext(); + TransactionContext txWorkContext = new TransactionContext(); try { - txInflowContext.setTransactionTimeout(executionContext.getTransactionTimeout()); + txWorkContext.setTransactionTimeout(executionContext.getTransactionTimeout()); } catch (NotSupportedException e) { throw new WorkRejectedException("Could not read tx timeout"); } - inflowContexts = Collections.singletonList(txInflowContext); - } else if (adaptee instanceof InflowContextProvider) { - inflowContexts = ((InflowContextProvider) adaptee).getInflowContexts(); + workContexts = Collections.singletonList(txWorkContext); + } else if (adaptee instanceof WorkContextProvider) { + workContexts = ((WorkContextProvider) adaptee).getWorkContexts(); } - List sortedHandlers = new ArrayList(inflowContexts.size()); - for (InflowContext inflowContext : inflowContexts) { + List sortedHandlers = new ArrayList(workContexts.size()); + for (WorkContext workContext : workContexts) { boolean found = false; - for (Iterator it = inflowContextHandlers.iterator(); it.hasNext();) { - InflowContextHandler inflowContextHandler = it.next(); + for (Iterator it = workContextHandlers.iterator(); it.hasNext();) { + WorkContextHandler workContextHandler = it.next(); //TODO is this the right way around? - if (inflowContext.getClass().isAssignableFrom(inflowContextHandler.getHandledClass())) { + if (workContext.getClass().isAssignableFrom(workContextHandler.getHandledClass())) { it.remove(); - sortedHandlers.add(inflowContextHandler); + sortedHandlers.add(workContextHandler); found = true; break; } } if (!found) { - throw new WorkCompletedException("Duplicate or unhandled InflowContext: " + inflowContext); + throw new WorkCompletedException("Duplicate or unhandled WorkContext: " + workContext); } } - for (Iterator it = inflowContextHandlers.iterator(); it.hasNext();) { - InflowContextHandler inflowContextHandler = it.next(); - if (!inflowContextHandler.required()) { + for (Iterator it = workContextHandlers.iterator(); it.hasNext();) { + WorkContextHandler workContextHandler = it.next(); + if (!workContextHandler.required()) { it.remove(); } } - // TODO use a InflowContextLifecycleListener + // TODO use a WorkContextLifecycleListener int i = 0; - for (InflowContext inflowContext : inflowContexts) { - sortedHandlers.get(i++).before(inflowContext); + for (WorkContext workContext : workContexts) { + sortedHandlers.get(i++).before(workContext); } - for (InflowContextHandler inflowContextHandler: inflowContextHandlers) { - inflowContextHandler.before(null); + for (WorkContextHandler workContextHandler: workContextHandlers) { + workContextHandler.before(null); } try { adaptee.run(); } finally { int j = 0; - for (InflowContext inflowContext : inflowContexts) { - sortedHandlers.get(j++).after(inflowContext); + for (WorkContext workContext : workContexts) { + sortedHandlers.get(j++).after(workContext); } - for (InflowContextHandler inflowContextHandler: inflowContextHandlers) { - inflowContextHandler.after(null); + for (WorkContextHandler workContextHandler: workContextHandlers) { + workContextHandler.after(null); } } diff --git a/geronimo-connector/src/test/java/org/apache/geronimo/connector/BootstrapContextTest.java b/geronimo-connector/src/test/java/org/apache/geronimo/connector/BootstrapContextTest.java index fc1446d..084f26e 100644 --- a/geronimo-connector/src/test/java/org/apache/geronimo/connector/BootstrapContextTest.java +++ b/geronimo-connector/src/test/java/org/apache/geronimo/connector/BootstrapContextTest.java @@ -31,8 +31,8 @@ import junit.framework.TestCase; import org.apache.geronimo.connector.work.GeronimoWorkManager; -import org.apache.geronimo.connector.work.TransactionInflowContextHandler; -import org.apache.geronimo.connector.work.InflowContextHandler; +import org.apache.geronimo.connector.work.TransactionContextHandler; +import org.apache.geronimo.connector.work.WorkContextHandler; import org.apache.geronimo.transaction.manager.GeronimoTransactionManager; import org.apache.geronimo.transaction.manager.XAWork; @@ -97,8 +97,8 @@ private synchronized int getNextWorkerID() { */ public void testGetSetWorkManager() throws Exception { GeronimoTransactionManager transactionManager = new GeronimoTransactionManager(); - TransactionInflowContextHandler txInflowContextHandler = new TransactionInflowContextHandler(transactionManager); - GeronimoWorkManager manager = new GeronimoWorkManager(pool, pool, pool, Collections.singletonList(txInflowContextHandler)); + TransactionContextHandler txWorkContextHandler = new TransactionContextHandler(transactionManager); + GeronimoWorkManager manager = new GeronimoWorkManager(pool, pool, pool, Collections.singletonList(txWorkContextHandler)); GeronimoBootstrapContext context = new GeronimoBootstrapContext(manager, transactionManager); WorkManager wm = context.getWorkManager(); @@ -110,8 +110,8 @@ public void testGetSetWorkManager() throws Exception { */ public void testGetSetXATerminator() throws Exception { GeronimoTransactionManager transactionManager = new GeronimoTransactionManager(); - TransactionInflowContextHandler txInflowContextHandler = new TransactionInflowContextHandler(transactionManager); - GeronimoWorkManager manager = new GeronimoWorkManager(pool, pool, pool, Collections.singletonList(txInflowContextHandler)); + TransactionContextHandler txWorkContextHandler = new TransactionContextHandler(transactionManager); + GeronimoWorkManager manager = new GeronimoWorkManager(pool, pool, pool, Collections.singletonList(txWorkContextHandler)); GeronimoBootstrapContext context = new GeronimoBootstrapContext(manager, transactionManager); XATerminator xat = context.getXATerminator(); diff --git a/geronimo-connector/src/test/java/org/apache/geronimo/connector/work/PooledWorkManagerTest.java b/geronimo-connector/src/test/java/org/apache/geronimo/connector/work/PooledWorkManagerTest.java index 258f737..e7e63cd 100644 --- a/geronimo-connector/src/test/java/org/apache/geronimo/connector/work/PooledWorkManagerTest.java +++ b/geronimo-connector/src/test/java/org/apache/geronimo/connector/work/PooledWorkManagerTest.java @@ -52,7 +52,7 @@ protected void setUp() throws Exception { super.setUp(); XAWork xaWork = new GeronimoTransactionManager(); - TransactionInflowContextHandler txInflowContextHandler = new TransactionInflowContextHandler(xaWork); + TransactionContextHandler txWorkContextHandler = new TransactionContextHandler(xaWork); int poolSize = 1; int keepAliveTime = 30000; ThreadPoolExecutor pool = new ThreadPoolExecutor( @@ -65,7 +65,7 @@ protected void setUp() throws Exception { pool.setThreadFactory(new ThreadPoolThreadFactory("Connector Test", getClass().getClassLoader())); - workManager = new GeronimoWorkManager(pool, pool, pool, Collections.singletonList(txInflowContextHandler)); + workManager = new GeronimoWorkManager(pool, pool, pool, Collections.singletonList(txWorkContextHandler)); workManager.doStart(); }