[jboss-cvs] JBossAS SVN: r86214 - in projects/jboss-jca/trunk/core/src: main/java/org/jboss/jca/core/workmanager and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 23 11:51:21 EDT 2009


Author: jesper.pedersen
Date: 2009-03-23 11:51:21 -0400 (Mon, 23 Mar 2009)
New Revision: 86214

Added:
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/SynchronizedWork.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/UnsynchronizedWork.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/package.html
Modified:
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/WorkManager.java
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/workmanager/WorkManagerImpl.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkInterfaceTestCase.java
Log:
[JBJCA-33] WorkManager - Specification

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/WorkManager.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/WorkManager.java	2009-03-23 15:34:44 UTC (rev 86213)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/WorkManager.java	2009-03-23 15:51:21 UTC (rev 86214)
@@ -58,6 +58,18 @@
    public void setXATerminator(JBossXATerminator xaTerminator);
 
    /**
+    * Is spec compliant
+    * @return True if spec compliant; otherwise false
+    */
+   public boolean isSpecCompliant();
+
+   /**
+    * Set spec compliant flag
+    * @param v The value
+    */
+   public void setSpecCompliant(boolean v);
+
+   /**
     * Start work
     * @param wrapper the work wrapper
     * @throws WorkException for any error 

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/workmanager/WorkManagerImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/workmanager/WorkManagerImpl.java	2009-03-23 15:34:44 UTC (rev 86213)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/workmanager/WorkManagerImpl.java	2009-03-23 15:51:21 UTC (rev 86214)
@@ -26,6 +26,8 @@
 import org.jboss.jca.core.api.WorkManager;
 import org.jboss.jca.core.api.WorkWrapper;
 
+import java.lang.reflect.Modifier;
+
 import javax.resource.spi.work.ExecutionContext;
 import javax.resource.spi.work.Work;
 import javax.resource.spi.work.WorkException;
@@ -47,6 +49,9 @@
    /** Whether trace is enabled */
    private boolean trace = log.isTraceEnabled();
 
+   /** Running in spec compliant mode */
+   private boolean specCompliant;
+
    /** The thread pool */
    private ThreadPool threadPool;
 
@@ -58,6 +63,7 @@
     */
    public WorkManagerImpl()
    {
+      specCompliant = true;
    }
 
    /**
@@ -97,6 +103,24 @@
    }
 
    /**
+    * Is spec compliant
+    * @return True if spec compliant; otherwise false
+    */
+   public boolean isSpecCompliant()
+   {
+      return specCompliant;
+   }
+
+   /**
+    * Set spec compliant flag
+    * @param v The value
+    */
+   public void setSpecCompliant(boolean v)
+   {
+      specCompliant = v;
+   }
+
+   /**
     * {@inheritDoc}
     */
    public void doWork(Work work) throws WorkException
@@ -113,12 +137,21 @@
                       WorkListener workListener) 
       throws WorkException
    {
+      if (work == null)
+         throw new WorkException("Null work");
+
+      if (specCompliant)
+         verifyWork(work);
+
       if (execContext == null)
          execContext = new ExecutionContext();
+
       WorkWrapper wrapper = 
          new WorkWrapper(this, work, Task.WAIT_FOR_COMPLETE, startTimeout, execContext, workListener);
+
       importWork(wrapper);
       executeWork(wrapper);
+
       if (wrapper.getWorkException() != null)
          throw wrapper.getWorkException();
    }
@@ -140,13 +173,23 @@
                          WorkListener workListener) 
       throws WorkException
    {
+      if (work == null)
+         throw new WorkException("Null work");
+
+      if (specCompliant)
+         verifyWork(work);
+
       if (execContext == null)
          execContext = new ExecutionContext();
+
       WorkWrapper wrapper = new WorkWrapper(this, work, Task.WAIT_FOR_START, startTimeout, execContext, workListener);
+
       importWork(wrapper);
       executeWork(wrapper);
+
       if (wrapper.getWorkException() != null)
          throw wrapper.getWorkException();
+
       return wrapper.getBlockedElapsed();
    }
    
@@ -167,11 +210,20 @@
                             WorkListener workListener) 
       throws WorkException
    {
+      if (work == null)
+         throw new WorkException("Null work");
+
+      if (specCompliant)
+         verifyWork(work);
+
       if (execContext == null)
          execContext = new ExecutionContext();
+
       WorkWrapper wrapper = new WorkWrapper(this, work, Task.WAIT_NONE, startTimeout, execContext, workListener);
+
       importWork(wrapper);
       executeWork(wrapper);
+
       if (wrapper.getWorkException() != null)
          throw wrapper.getWorkException();
    }
@@ -186,6 +238,9 @@
       trace = log.isTraceEnabled();
       if (trace)
          log.trace("Importing work " + wrapper);
+
+      if (wrapper == null)
+         return;
       
       ExecutionContext ctx = wrapper.getExecutionContext();
       if (ctx != null)
@@ -212,6 +267,9 @@
       if (trace)
          log.trace("Submitting work to thread pool " + wrapper);
 
+      if (wrapper == null)
+         return;
+
       threadPool.runTaskWrapper(wrapper);
 
       if (trace)
@@ -228,6 +286,9 @@
       if (trace)
          log.trace("Starting work " + wrapper);
 
+      if (wrapper == null)
+         return;
+
       ExecutionContext ctx = wrapper.getExecutionContext();
       if (ctx != null)
       {
@@ -250,6 +311,9 @@
       if (trace)
          log.trace("Ending work " + wrapper);
 
+      if (wrapper == null)
+         return;
+
       ExecutionContext ctx = wrapper.getExecutionContext();
       if (ctx != null)
       {
@@ -272,6 +336,9 @@
       if (trace)
          log.trace("Cancel work " + wrapper);
 
+      if (wrapper == null)
+         return;
+
       ExecutionContext ctx = wrapper.getExecutionContext();
       if (ctx != null)
       {
@@ -284,4 +351,34 @@
       if (trace)
          log.trace("Canceled work " + wrapper);
    }
+
+   /**
+    * Verify work
+    * @param work The work
+    * @throws WorkException Thrown if a spec compliant issue is found
+    */
+   private void verifyWork(Work work) throws WorkException
+   {
+      Class[] types = new Class[] {};
+
+      try
+      {
+         if (Modifier.isSynchronized(work.getClass().getMethod("run", types).getModifiers()))
+            throw new WorkException(work.getClass().getName() + ": Run method is synchronized");
+      }
+      catch (NoSuchMethodException nsme)
+      {
+         throw new WorkException(work.getClass().getName() + ": Run method is not defined");
+      }
+
+      try
+      {
+         if (Modifier.isSynchronized(work.getClass().getMethod("release", types).getModifiers()))
+            throw new WorkException(work.getClass().getName() + ": Release method is synchronized");
+      }
+      catch (NoSuchMethodException nsme)
+      {
+         throw new WorkException(work.getClass().getName() + ": Release method is not defined");
+      }
+   }
 }

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/SynchronizedWork.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/SynchronizedWork.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/SynchronizedWork.java	2009-03-23 15:51:21 UTC (rev 86214)
@@ -0,0 +1,56 @@
+/*
+ * 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.jca.test.core.spec.chapter10.common;
+
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkManager;
+
+/**
+ * Synchronized work instance.
+
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class SynchronizedWork implements Work
+{
+   /**
+    * Constructor.
+    */
+   public SynchronizedWork()
+   {
+   }
+   
+   /**
+    * Synchronized release method
+    */
+   public synchronized void release()
+   {
+   }
+
+   /**
+    * Synchronized run method
+    */
+   public synchronized void run()
+   {
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/UnsynchronizedWork.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/UnsynchronizedWork.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/UnsynchronizedWork.java	2009-03-23 15:51:21 UTC (rev 86214)
@@ -0,0 +1,56 @@
+/*
+ * 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.jca.test.core.spec.chapter10.common;
+
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkManager;
+
+/**
+ * Unsynchronized work instance.
+
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class UnsynchronizedWork implements Work
+{
+   /**
+    * Constructor.
+    */
+   public UnsynchronizedWork()
+   {
+   }
+   
+   /**
+    * Unsynchronized release method
+    */
+   public void release()
+   {
+   }
+
+   /**
+    * Unsynchronized run method
+    */
+   public void run()
+   {
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/package.html	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/package.html	2009-03-23 15:51:21 UTC (rev 86214)
@@ -0,0 +1,3 @@
+<body>
+Common interfaces and classes for the JCA Chapter 10 test cases.
+</body>

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkInterfaceTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkInterfaceTestCase.java	2009-03-23 15:34:44 UTC (rev 86213)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkInterfaceTestCase.java	2009-03-23 15:51:21 UTC (rev 86214)
@@ -25,9 +25,9 @@
 import org.jboss.jca.common.threadpool.ThreadPoolImpl;
 
 import org.jboss.jca.test.core.spec.chapter10.SimpleWork;
+import org.jboss.jca.test.core.spec.chapter10.common.SynchronizedWork;
+import org.jboss.jca.test.core.spec.chapter10.common.UnsynchronizedWork;
 
-import java.lang.reflect.Modifier;
-
 import javax.resource.spi.work.Work;
 import javax.resource.spi.work.WorkCompletedException;
 import javax.resource.spi.work.WorkException;
@@ -155,14 +155,37 @@
     * @throws Throwable throwable exception 
     */
    @Test
-   public void testCannotDeclaredSynchronized() throws Throwable
+   public void testCannotDeclaredSynchronizedSynchronizedWork() throws Throwable
    {
-      //In SimpleWork class, both in run() and release(), there are synchronization synchronization
-      Class[] types = new Class[] {};
-      assertFalse(Modifier.isSynchronized(SimpleWork.class.getMethod("run", types).getModifiers()));
-      assertFalse(Modifier.isSynchronized(SimpleWork.class.getMethod("release", types).getModifiers()));
+      WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
+
+      try
+      {
+         SynchronizedWork sw = new SynchronizedWork();
+         workManager.doWork(sw);
+         fail("Synchronized methods not catched");
+      }
+      catch (WorkException we)
+      {
+         // Expected
+      }
    }
    
+   /**
+    * Test for paragraph 5
+    * Both the run and release methods in the Work implementation may contain synchronization 
+    *            synchronization but they must not be declared as synchronized methods.
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testCannotDeclaredSynchronizedUnsynchronizedWork() throws Throwable
+   {
+      WorkManager workManager = bootstrap.lookup("WorkManager", WorkManager.class);
+
+      UnsynchronizedWork usw = new UnsynchronizedWork();
+      workManager.doWork(usw);
+   }
+   
    // --------------------------------------------------------------------------------||
    // Lifecycle Methods --------------------------------------------------------------||
    // --------------------------------------------------------------------------------||




More information about the jboss-cvs-commits mailing list