geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r925908 - in /geronimo/components/txmanager/trunk/geronimo-connector/src: main/java/org/apache/geronimo/connector/ main/java/org/apache/geronimo/connector/work/ test/java/org/apache/geronimo/connector/
Date Sun, 21 Mar 2010 21:59:55 GMT
Author: djencks
Date: Sun Mar 21 21:59:55 2010
New Revision: 925908

URL: http://svn.apache.org/viewvc?rev=925908&view=rev
Log:
GERONIMO-4360 add HintsContextHander, fix a lot of small bugs with work contexts.  changes
api slightly, needs server code change too

Added:
    geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/HintsContextHandler.java
  (with props)
Modified:
    geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/GeronimoBootstrapContext.java
    geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java
    geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/TransactionContextHandler.java
    geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkContextHandler.java
    geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkerContext.java
    geronimo/components/txmanager/trunk/geronimo-connector/src/test/java/org/apache/geronimo/connector/BootstrapContextTest.java

Modified: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/GeronimoBootstrapContext.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/GeronimoBootstrapContext.java?rev=925908&r1=925907&r2=925908&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/GeronimoBootstrapContext.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/GeronimoBootstrapContext.java
Sun Mar 21 21:59:55 2010
@@ -23,6 +23,7 @@ import javax.resource.spi.XATerminator;
 import javax.resource.spi.work.WorkManager;
 import javax.resource.spi.work.WorkContext;
 import javax.transaction.TransactionSynchronizationRegistry;
+import org.apache.geronimo.connector.work.GeronimoWorkManager;
 
 /**
  * GBean BootstrapContext implementation that refers to externally configured WorkManager
@@ -31,8 +32,9 @@ import javax.transaction.TransactionSync
  * @version $Rev$ $Date$
  */
 public class GeronimoBootstrapContext implements javax.resource.spi.BootstrapContext {
-    private final WorkManager workManager;
+    private final GeronimoWorkManager workManager;
     private final XATerminator xATerminator;
+    private final TransactionSynchronizationRegistry transactionSynchronizationRegistry;
 
     /**
      * Default constructor for use as a GBean Endpoint.
@@ -40,16 +42,19 @@ public class GeronimoBootstrapContext im
     public GeronimoBootstrapContext() {
         workManager = null;
         xATerminator = null;
+        transactionSynchronizationRegistry = null;
     }
 
     /**
      * Normal constructor for use as a GBean.
      * @param workManager
      * @param xaTerminator
+     * @param transactionSynchronizationRegistry
      */
-    public GeronimoBootstrapContext(WorkManager workManager, XATerminator xaTerminator) {
+    public GeronimoBootstrapContext(GeronimoWorkManager workManager, XATerminator xaTerminator,
TransactionSynchronizationRegistry transactionSynchronizationRegistry) {
         this.workManager = workManager;
         this.xATerminator = xaTerminator;
+        this.transactionSynchronizationRegistry = transactionSynchronizationRegistry;
     }
 
 
@@ -75,11 +80,11 @@ public class GeronimoBootstrapContext im
     }
 
     public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() {
-        return null;
+        return transactionSynchronizationRegistry;
     }
 
     public boolean isContextSupported(Class<? extends WorkContext> aClass) {
-        return false;
+        return workManager.isContextSupported(aClass);
     }
 
 }

Modified: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java?rev=925908&r1=925907&r2=925908&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java
Sun Mar 21 21:59:55 2010
@@ -24,6 +24,7 @@ import java.util.concurrent.Executor;
 import javax.resource.spi.work.ExecutionContext;
 import javax.resource.spi.work.Work;
 import javax.resource.spi.work.WorkCompletedException;
+import javax.resource.spi.work.WorkContext;
 import javax.resource.spi.work.WorkException;
 import javax.resource.spi.work.WorkListener;
 import javax.resource.spi.work.WorkManager;
@@ -207,4 +208,13 @@ public class GeronimoWorkManager impleme
         }
     }
 
+    public boolean isContextSupported(Class<? extends WorkContext> aClass) {
+        for (WorkContextHandler workContextHandler: workContextHandlers) {
+            if (workContextHandler.supports(aClass)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
 }

Added: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/HintsContextHandler.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/HintsContextHandler.java?rev=925908&view=auto
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/HintsContextHandler.java
(added)
+++ geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/HintsContextHandler.java
Sun Mar 21 21:59:55 2010
@@ -0,0 +1,46 @@
+/*
+ * 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.geronimo.connector.work;
+
+import javax.resource.spi.work.HintsContext;
+import javax.resource.spi.work.WorkCompletedException;
+import javax.resource.spi.work.WorkContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HintsContextHandler implements WorkContextHandler<HintsContext> {
+
+    public void before(HintsContext workContext) throws WorkCompletedException {
+    }
+
+    public void after(HintsContext workContext) throws WorkCompletedException {
+    }
+
+    public boolean supports(Class<? extends WorkContext> clazz) {
+        return HintsContext.class.isAssignableFrom(clazz);
+    }
+
+    public boolean required() {
+        return false;
+    }
+
+}

Propchange: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/HintsContextHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/HintsContextHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/HintsContextHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/TransactionContextHandler.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/TransactionContextHandler.java?rev=925908&r1=925907&r2=925908&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/TransactionContextHandler.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/TransactionContextHandler.java
Sun Mar 21 21:59:55 2010
@@ -22,6 +22,7 @@ package org.apache.geronimo.connector.wo
 
 import javax.resource.spi.work.TransactionContext;
 import javax.resource.spi.work.WorkCompletedException;
+import javax.resource.spi.work.WorkContext;
 import javax.transaction.xa.XAException;
 import javax.transaction.InvalidTransactionException;
 import javax.transaction.SystemException;
@@ -70,8 +71,8 @@ public class TransactionContextHandler i
         }
     }
 
-    public Class<TransactionContext> getHandledClass() {
-        return TransactionContext.class;
+    public boolean supports(Class<? extends WorkContext> clazz) {
+        return TransactionContext.class.isAssignableFrom(clazz);
     }
 
     public boolean required() {

Modified: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkContextHandler.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkContextHandler.java?rev=925908&r1=925907&r2=925908&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkContextHandler.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkContextHandler.java
Sun Mar 21 21:59:55 2010
@@ -32,7 +32,7 @@ public interface WorkContextHandler<E ex
 
     void after(E workContext) throws WorkCompletedException;
 
-    Class<E> getHandledClass(); 
+    boolean supports(Class<? extends WorkContext> clazz); 
 
     boolean required();
 

Modified: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkerContext.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkerContext.java?rev=925908&r1=925907&r2=925908&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkerContext.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/work/WorkerContext.java
Sun Mar 21 21:59:55 2010
@@ -312,9 +312,11 @@ public class WorkerContext implements Wo
                 try {
                     txWorkContext.setTransactionTimeout(executionContext.getTransactionTimeout());
                 } catch (NotSupportedException e) {
-                    throw new WorkRejectedException("Could not read tx timeout");
+                    //not set, continue to not set it.
                 }
+                txWorkContext.setXid(executionContext.getXid());
                 workContexts = Collections.<WorkContext>singletonList(txWorkContext);
+                log.info("Translated ExecutionContext to TransactionContext");
             } else if (adaptee instanceof WorkContextProvider) {
                 workContexts = ((WorkContextProvider) adaptee).getWorkContexts();
             }
@@ -323,21 +325,28 @@ public class WorkerContext implements Wo
                 boolean found = false;
                 for (Iterator<WorkContextHandler> it = workContextHandlers.iterator();
it.hasNext();) {
                     WorkContextHandler workContextHandler = it.next();
-                    //TODO is this the right way around?
-                    if (workContext.getClass().isAssignableFrom(workContextHandler.getHandledClass()))
{
+                    log.info("sorting WorkContextHandler: " + workContextHandler + " for
work context: " + workContext);
+                    if (workContextHandler.supports(workContext.getClass())) {
                         it.remove();
+                        log.info("adding sorted WorkContextHandler: " + workContextHandler);
                         sortedHandlers.add(workContextHandler);
                         found = true;
                         break;
                     }
                 }
                 if (!found) {
-                    throw new WorkCompletedException("Duplicate or unhandled WorkContext:
" + workContext, WorkContextErrorCodes.UNSUPPORTED_CONTEXT_TYPE);
+                    for (WorkContextHandler workContextHandler: sortedHandlers) {
+                        if (workContextHandler.supports(workContext.getClass())) {
+                            throw new WorkCompletedException("Duplicate WorkContext: " +
workContext, WorkContextErrorCodes.DUPLICATE_CONTEXTS);
+                        }
+                    }
+                    throw new WorkCompletedException("Unhandled WorkContext: " + workContext,
WorkContextErrorCodes.UNSUPPORTED_CONTEXT_TYPE);
                 }
             }
             for (Iterator<WorkContextHandler> it = workContextHandlers.iterator();
it.hasNext();) {
                 WorkContextHandler workContextHandler = it.next();
                 if (!workContextHandler.required()) {
+                    log.info("Removing non-required WorkContextHandler with no context: "
+ workContextHandler);
                     it.remove();
                 }
             }
@@ -345,9 +354,12 @@ public class WorkerContext implements Wo
 
             int i = 0;
             for (WorkContext workContext : workContexts) {
-                sortedHandlers.get(i++).before(workContext);
+                WorkContextHandler contextHandler = sortedHandlers.get(i++);
+                log.info("calling before on WorkContextHandler: " + contextHandler + " with
workContext: " + workContext);
+                contextHandler.before(workContext);
             }
             for (WorkContextHandler workContextHandler: workContextHandlers) {
+                log.info("calling before on WorkContextHandler: " + workContextHandler +
" with null workContext");
                 workContextHandler.before(null);
             }
             try {
@@ -355,9 +367,12 @@ public class WorkerContext implements Wo
             } finally {
                 int j = 0;
                 for (WorkContext workContext : workContexts) {
-                    sortedHandlers.get(j++).after(workContext);
+                    WorkContextHandler contextHandler = sortedHandlers.get(j++);
+                    log.info("calling after on WorkContextHandler: " + contextHandler + "
with workContext: " + workContext);
+                    contextHandler.after(workContext);
                 }
                 for (WorkContextHandler workContextHandler: workContextHandlers) {
+                    log.info("calling after on WorkContextHandler: " + workContextHandler
+ " with null workContext");
                     workContextHandler.after(null);
                 }
             }

Modified: geronimo/components/txmanager/trunk/geronimo-connector/src/test/java/org/apache/geronimo/connector/BootstrapContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-connector/src/test/java/org/apache/geronimo/connector/BootstrapContextTest.java?rev=925908&r1=925907&r2=925908&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-connector/src/test/java/org/apache/geronimo/connector/BootstrapContextTest.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-connector/src/test/java/org/apache/geronimo/connector/BootstrapContextTest.java
Sun Mar 21 21:59:55 2010
@@ -99,7 +99,7 @@ public class BootstrapContextTest extend
         GeronimoTransactionManager transactionManager = new GeronimoTransactionManager();
         TransactionContextHandler txWorkContextHandler = new TransactionContextHandler(transactionManager);
         GeronimoWorkManager manager = new GeronimoWorkManager(pool, pool, pool, Collections.<WorkContextHandler>singletonList(txWorkContextHandler));
-        GeronimoBootstrapContext context = new GeronimoBootstrapContext(manager, transactionManager);
+        GeronimoBootstrapContext context = new GeronimoBootstrapContext(manager, transactionManager,
transactionManager);
         WorkManager wm = context.getWorkManager();
 
         assertSame("Make sure it is the same object", manager, wm);
@@ -112,7 +112,7 @@ public class BootstrapContextTest extend
         GeronimoTransactionManager transactionManager = new GeronimoTransactionManager();
         TransactionContextHandler txWorkContextHandler = new TransactionContextHandler(transactionManager);
         GeronimoWorkManager manager = new GeronimoWorkManager(pool, pool, pool, Collections.<WorkContextHandler>singletonList(txWorkContextHandler));
-        GeronimoBootstrapContext context = new GeronimoBootstrapContext(manager, transactionManager);
+        GeronimoBootstrapContext context = new GeronimoBootstrapContext(manager, transactionManager,
transactionManager);
         XATerminator xat = context.getXATerminator();
 
         assertSame("Make sure it is the same object", transactionManager, xat);
@@ -122,7 +122,7 @@ public class BootstrapContextTest extend
      * Tests getTimer
      */
     public void testGetTimer() throws Exception {
-        GeronimoBootstrapContext context = new GeronimoBootstrapContext(null, null);
+        GeronimoBootstrapContext context = new GeronimoBootstrapContext(null, null, null);
         Timer t = context.createTimer();
         assertNotNull("Object is not null", t);
     }



Mime
View raw message