[jboss-cvs] JBossAS SVN: r100758 - in projects/jboss-jca/trunk: common/src/main/java/org/jboss/jca/common and 12 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 9 11:01:39 EST 2010


Author: jesper.pedersen
Date: 2010-02-09 11:01:38 -0500 (Tue, 09 Feb 2010)
New Revision: 100758

Added:
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/workmanager/WorkWrapper.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingDoWorkTestCase.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingScheduleWorkTestCase.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingStartWorkTestCase.java
   projects/jboss-jca/trunk/core/src/test/resources/rejecting-workmanager-jboss-beans.xml
Removed:
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/ThreadPool.java
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/threadpool/
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/WorkWrapper.java
Modified:
   projects/jboss-jca/trunk/build.xml
   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/main/resources/deployment/jca.xml
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerDoWorkTestCase.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerScheduleWorkTestCase.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerStartWorkTestCase.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkTestCase.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/MyWorkAdapter.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section1/ManageThreadTestCase.java
   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/WorkListenerInterfaceTestCase.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/workmanager/unit/WorkManagerTestCase.java
   projects/jboss-jca/trunk/core/src/test/resources/logging.properties
   projects/jboss-jca/trunk/core/src/test/resources/workmanager-jboss-beans.xml
   projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml
   projects/jboss-jca/trunk/ivy.xml
   projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml
Log:
[JBJCA-260] Create a WorkManager implementation that uses JBoss Threads

Modified: projects/jboss-jca/trunk/build.xml
===================================================================
--- projects/jboss-jca/trunk/build.xml	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/build.xml	2010-02-09 16:01:38 UTC (rev 100758)
@@ -109,6 +109,7 @@
   <property name="version.jboss.slf4j" value="1.0.2.GA"/>
   <property name="version.jboss.slf4j.logmanager" value="1.0.0.CR2"/>
   <property name="version.jboss.stdio" value="1.0.0.CR2"/>
+  <property name="version.jboss.threads" value="2.0.0.CR3"/>
   <property name="version.jboss.ts" value="4.9.0.GA"/>
   <property name="version.jboss.vfs" value="2.1.3.SP1"/>
   <property name="version.jboss.xb" value="2.0.1.GA"/>

Deleted: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/ThreadPool.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/ThreadPool.java	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/ThreadPool.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -1,31 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, 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.common.api;
-
-/**
- * The thread pool interface
- */
-public interface ThreadPool extends org.jboss.util.threadpool.ThreadPool
-{
-
-}

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	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/WorkManager.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -22,10 +22,9 @@
 
 package org.jboss.jca.core.api;
 
-import org.jboss.jca.common.api.ThreadPool;
-
 import javax.resource.spi.work.WorkException;
 
+import org.jboss.threads.BlockingExecutor;
 import org.jboss.tm.JBossXATerminator;
 
 /**
@@ -34,18 +33,30 @@
 public interface WorkManager extends javax.resource.spi.work.WorkManager
 {
    /**
-    * Retrieve the thread pool
-    * @return the thread pool
+    * Retrieve the executor for short running tasks
+    * @return The executor
     */
-   public ThreadPool getThreadPool();
+   public BlockingExecutor getShortRunningThreadPool();
 
    /**
-    * Set the thread pool
-    * @param threadPool the thread pool
+    * Set the executor for short running tasks
+    * @param executor The executor
     */
-   public void setThreadPool(ThreadPool threadPool);
+   public void setShortRunningThreadPool(BlockingExecutor executor);
 
    /**
+    * Retrieve the executor for long running tasks
+    * @return The executor
+    */
+   public BlockingExecutor getLongRunningThreadPool();
+
+   /**
+    * Set the executor for long running tasks
+    * @param executor The executor
+    */
+   public void setLongRunningThreadPool(BlockingExecutor executor);
+
+   /**
     * Get the XATerminator
     * @return The XA terminator
     */
@@ -68,23 +79,4 @@
     * @param v The value
     */
    public void setSpecCompliant(boolean v);
-
-   /**
-    * Start work
-    * @param wrapper the work wrapper
-    * @throws WorkException for any error 
-    */
-   public void startWork(WorkWrapper wrapper) throws WorkException;
-
-   /**
-    * End work
-    * @param wrapper the work wrapper
-    */
-   public void endWork(WorkWrapper wrapper);
-
-   /**
-    * Cancel work
-    * @param wrapper the work wrapper
-    */
-   public void cancelWork(WorkWrapper wrapper);
 }

Deleted: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/WorkWrapper.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/WorkWrapper.java	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/WorkWrapper.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -1,460 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, 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.core.api;
-
-import java.util.HashMap;
-import java.util.Map;
-
-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.WorkEvent;
-import javax.resource.spi.work.WorkException;
-import javax.resource.spi.work.WorkListener;
-import javax.resource.spi.work.WorkRejectedException;
-
-import org.jboss.logging.Logger;
-import org.jboss.util.NestedRuntimeException;
-import org.jboss.util.threadpool.BasicTaskWrapper;
-import org.jboss.util.threadpool.StartTimeoutException;
-import org.jboss.util.threadpool.Task;
-
-/**
- * Wraps the resource adapter's work.
- *
- * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
- * @version $Revision: 71538 $
- */
-public class WorkWrapper extends BasicTaskWrapper implements Task
-{
-   /** The log */
-   private static Logger log = Logger.getLogger(WorkWrapper.class);
-
-   /** Whether we are tracing */
-   private boolean trace = log.isTraceEnabled();
-   
-   /** The work */
-   private Work work;
-
-   /** The execution context */
-   private ExecutionContext executionContext;
-   
-   /**If work is an instance of WorkContextProvider, it may containt WorkContext instance*/
-   private Map<Class<? extends WorkContext>, WorkContext> workContexts = 
-      new HashMap<Class<? extends WorkContext>, WorkContext>();
-
-   /** the work listener */
-   private WorkListener workListener;   
-
-   /** The start timeout */
-   private long startTimeout;
-
-   /** The work manager */
-   private org.jboss.jca.core.api.WorkManager workManager;
-
-   /** The wait type */
-   private int waitType;
-
-   /** The blocked time */
-   private long blockedTime;
-
-   /** Any exception */
-   private WorkException exception;
-
-   /**
-    * Create a new WorkWrapper
-    *
-    * @param workManager the work manager
-    * @param work the work
-    * @param waitType the waitType
-    * @param startTimeout the start timeout
-    * @param executionContext the execution context
-    * @param workListener the WorkListener
-    * @throws IllegalArgumentException for null work, execution context or a negative start timeout
-    */
-   public WorkWrapper(org.jboss.jca.core.api.WorkManager workManager, 
-                      Work work, 
-                      int waitType, 
-                      long startTimeout, 
-                      ExecutionContext executionContext, 
-                      WorkListener workListener)
-   {
-      super();
-
-      if (work == null)
-         throw new IllegalArgumentException("Null work");
-      if (executionContext == null)
-         throw new IllegalArgumentException("Null execution context");
-      if (startTimeout < 0)
-         throw new IllegalArgumentException("Illegal start timeout: " + startTimeout);
-
-      this.workManager = workManager;
-      this.work = work;
-      this.waitType = waitType;
-      this.startTimeout = startTimeout;
-      this.executionContext = executionContext;
-      this.workListener = workListener;
-
-      setTask(this);
-   }
-   
-   /**
-    * Adds new work context.
-    * 
-    * @param workContext new work context
-    * @param workContextClass work context class
-    */
-   public void addWorkContext(Class<? extends WorkContext> workContextClass, WorkContext workContext)
-   {
-      if (workContextClass == null)
-      {
-         throw new IllegalArgumentException("Work context class is null");
-      }
-
-      if (workContext == null)
-      {
-         throw new IllegalArgumentException("Work context is null");
-      }
-
-      this.workContexts.put(workContextClass, workContext);
-   }
-   
-   /**
-    * Get the work manager
-    *
-    * @return the work manager
-    */
-   public org.jboss.jca.core.api.WorkManager getWorkManager()
-   {
-      return workManager;
-   }
-
-   /**
-    * Retrieve the work
-    *
-    * @return the work
-    */
-   public Work getWork()
-   {
-      return work;
-   }
-
-   /**
-    * Retrieve the work listener
-    *
-    * @return the WorkListener
-    */
-   public WorkListener getWorkListener()
-   {
-      return workListener;
-   }
-
-   /**
-    * Retrieve the exection context
-    *
-    * @return the execution context
-    */
-   public ExecutionContext getExecutionContext()
-   {
-      return executionContext;
-   }
-   
-   /**
-    * Returns work context instance.
-    * 
-    * @param <T> class type info
-    * @param workContextClass work context type
-    * @return work context instance
-    */
-   public <T> T getWorkContext(Class<T> workContextClass)
-   {
-      T instance = null;
-
-      if (this.workContexts.containsKey(workContextClass))
-      {
-         instance = workContextClass.cast(this.workContexts.get(workContextClass));
-      }
-
-      return instance;
-   }
-
-   /**
-    * Retrieve the time blocked
-    *
-    * @return the blocked time
-    */
-   public long getBlockedElapsed()
-   {
-      return blockedTime;
-   }
-   
-   /**
-    * Get any exception
-    * 
-    * @return the exception or null if there is none
-    */
-   public WorkException getWorkException()
-   {
-      return exception;
-   }
-
-   /**
-    * Get the wait type
-    * @return The wait type
-    */
-   public int getWaitType()
-   {
-      return waitType;
-   }
-
-   /**
-    * Get the priority
-    * @return The priority
-    */
-   public int getPriority()
-   {
-      return Thread.NORM_PRIORITY;
-   }
-
-   /**
-    * Get the start timeout
-    * @return The start timeout
-    */
-   public long getStartTimeout()
-   {
-      return startTimeout;
-   }
-
-   /**
-    * Get the completion timeout in milliseconds
-    * @return The completion timeout
-    */
-   public long getCompletionTimeout()
-   {
-      return executionContext.getTransactionTimeout() * 1000L;
-   }
-
-   /**
-    * Execute
-    */
-   public void execute()
-   {
-      if (trace)
-      {
-         log.trace("Starting work " + this);  
-      }
-      
-      try
-      {
-         workManager.startWork(this);
-         work.run();
-
-      }
-      catch (WorkException e)
-      {
-         taskCompleted(new NestedRuntimeException(e));
-      }      
-      finally
-      {
-         workManager.endWork(this);
-      }
-      
-      if (trace)
-      {
-         log.trace("Executed work " + this);  
-      }
-   }
-
-   /**
-    * Stop
-    */
-   public void stop()
-   {
-      if (trace)
-      {
-         log.trace("Stopping work " + this);  
-      }
-
-      work.release();
-   }
-
-   /**
-    * Work is accepted.
-    * @param time The blocked time
-    */
-   public void accepted(long time)
-   {
-      blockedTime = time;
-
-      if (trace)
-      {
-         log.trace("Accepted work " + this);  
-      }
-
-      if (workListener != null)
-      {
-         WorkEvent event = new WorkEvent(workManager, WorkEvent.WORK_ACCEPTED, work, null);
-         workListener.workAccepted(event);
-      }
-   }
-
-   /**
-    * Work is rejected.
-    * @param time The blocked time
-    * @param throwable The throwable
-    */
-   public void rejected(long time, Throwable throwable)
-   {
-      blockedTime = time;
-
-      if (trace)
-      {
-         if (throwable != null)
-         {
-            log.trace("Rejecting work " + this, throwable);  
-         }
-         else
-         {
-            log.trace("Rejecting work " + this);  
-         }
-      }
-
-      if (throwable != null)
-      {
-         exception = new WorkRejectedException(throwable);
-         if (throwable instanceof StartTimeoutException)
-         {
-            exception.setErrorCode(WorkRejectedException.START_TIMED_OUT);  
-         }
-      }
-      
-      workManager.cancelWork(this);
-      
-      if (workListener != null)
-      {
-         WorkEvent event = new WorkEvent(workManager, WorkEvent.WORK_REJECTED, work, exception);
-         workListener.workRejected(event);
-      }
-   }
-
-   /**
-    * Started
-    * @param time The blocked time
-    */
-   public void started(long time)
-   {
-      if (waitType != WAIT_NONE)
-      {
-         blockedTime = time;  
-      }
-
-      if (workListener != null)
-      {
-         WorkEvent event = new WorkEvent(workManager, WorkEvent.WORK_STARTED, work, null);
-         workListener.workStarted(event);
-      }
-   }
-
-   /**
-    * Completed
-    * @param time The blocked time
-    * @param throwable The throwable
-    */
-   public void completed(long time, Throwable throwable)
-   {
-      if (waitType == WAIT_FOR_COMPLETE)
-      {
-         blockedTime = time;  
-      }
-
-      if (throwable != null)
-      {
-         exception = new WorkCompletedException(throwable);  
-      }
-
-      if (trace)
-      {
-         log.trace("Completed work " + this);  
-      }
-
-      if (workListener != null)
-      {
-         WorkEvent event = new WorkEvent(workManager, WorkEvent.WORK_COMPLETED, work, exception);
-         workListener.workCompleted(event);
-      }
-   }
-   
-   /**
-    * String representation
-    * @return The string
-    */
-   public String toString()
-   {
-      StringBuilder buffer = new StringBuilder(100);
-      buffer.append("WorkWrapper@").append(Integer.toHexString(System.identityHashCode(this)));
-      buffer.append("[workManger=").append(workManager);
-      buffer.append(" work=").append(work);
-      buffer.append(" state=").append(getStateString());
-      if (executionContext != null && executionContext.getXid() != null)
-      {
-         buffer.append(" xid=").append(executionContext.getXid());
-         buffer.append(" txTimeout=").append(executionContext.getTransactionTimeout());
-      }
-      buffer.append(" waitType=");
-      switch (waitType)
-      {
-         case WAIT_NONE:
-         {
-            buffer.append("WAIT_NONE");
-            break;
-         }
-         case WAIT_FOR_START:
-         {
-            buffer.append("WAIT_FOR_START");
-            break;
-         }
-         case WAIT_FOR_COMPLETE:
-         {
-            buffer.append("WAIT_FOR_COMPLETE");
-            break;
-         }
-         default:
-            buffer.append("???");
-      }
-      if (startTimeout != javax.resource.spi.work.WorkManager.INDEFINITE)
-         buffer.append(" startTimeout=").append(startTimeout);
-      long completionTimeout = getCompletionTimeout();
-      if (completionTimeout != -1)
-         buffer.append(" completionTimeout=").append(completionTimeout);
-      if (blockedTime != 0)
-         buffer.append(" blockTime=").append(blockedTime);
-      buffer.append(" elapsedTime=").append(getElapsedTime());
-      if (workListener != null)
-         buffer.append(" workListener=").append(workListener);
-      if (exception != null)
-         buffer.append(" exception=").append(exception);
-      buffer.append("]");
-      return buffer.toString();
-   }
-}

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	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/workmanager/WorkManagerImpl.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -1,6 +1,6 @@
 /*
  * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2010, 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.
  *
@@ -22,16 +22,17 @@
 
 package org.jboss.jca.core.workmanager;
 
-import org.jboss.jca.common.api.ThreadPool;
 import org.jboss.jca.common.util.ClassUtil;
 import org.jboss.jca.core.api.WorkManager;
-import org.jboss.jca.core.api.WorkWrapper;
 
 import java.lang.reflect.Method;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
-
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.TimeUnit;
 import javax.resource.spi.work.ExecutionContext;
 import javax.resource.spi.work.HintsContext;
 import javax.resource.spi.work.SecurityContext;
@@ -42,49 +43,55 @@
 import javax.resource.spi.work.WorkContextErrorCodes;
 import javax.resource.spi.work.WorkContextLifecycleListener;
 import javax.resource.spi.work.WorkContextProvider;
+import javax.resource.spi.work.WorkEvent;
 import javax.resource.spi.work.WorkException;
 import javax.resource.spi.work.WorkListener;
 import javax.resource.spi.work.WorkRejectedException;
 import javax.transaction.xa.Xid;
 
 import org.jboss.logging.Logger;
+import org.jboss.threads.BlockingExecutor;
+import org.jboss.threads.ExecutionTimedOutException;
 import org.jboss.tm.JBossXATerminator;
-import org.jboss.util.threadpool.Task;
 
 /**
  * The work manager implementation.
  * 
- * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
- * @version $Rev: $
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
  */
 public class WorkManagerImpl implements WorkManager
 {
    /** The logger */
    private static Logger log = Logger.getLogger(WorkManagerImpl.class);
    
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+
+   /**Work run method name*/
+   private static final String RUN_METHOD_NAME = "run";
+   
+   /**Work release method name*/
+   private static final String RELEASE_METHOD_NAME = "release";
+
    /**Supported work context set*/
    private static final Set<Class<? extends WorkContext>> SUPPORTED_WORK_CONTEXT_CLASSES = 
-       new HashSet<Class<? extends WorkContext>>(); 
+       new HashSet<Class<? extends WorkContext>>(3); 
 
-   /** Whether trace is enabled */
-   private boolean trace = log.isTraceEnabled();
-
    /** Running in spec compliant mode */
    private boolean specCompliant;
 
-   /** The thread pool */
-   private ThreadPool threadPool;
+   /** The short running executor */
+   private BlockingExecutor shortRunningExecutor;
 
+   /** The long running executor */
+   private BlockingExecutor longRunningExecutor;
+
    /** The XA terminator */
    private JBossXATerminator xaTerminator;
-   
-   /**Work run method name*/
-   private static final String RUN_METHOD_NAME = "run";
-   
-   /**Work release method name*/
-   private static final String RELEASE_METHOD_NAME = "release";
-   
 
+   /** Validated work instances */
+   private Set<String> validatedWork;
+
    /**Default supported workcontext types*/
    static
    {
@@ -94,35 +101,51 @@
    }
    
    /**
-    * Default constructor.
-    * <p>
-    * Defines a default spec compliant.
-    * </p>
+    * Constructor - by default the WorkManager is running in spec-compliant mode
     */
    public WorkManagerImpl()
    {
       specCompliant = true;
+      validatedWork = new HashSet<String>();
    }
    
    /**
-    * Retrieve the thread pool
-    * @return the thread pool
+    * Retrieve the executor for short running tasks
+    * @return The executor
     */
-   public ThreadPool getThreadPool()
+   public BlockingExecutor getShortRunningThreadPool()
    {
-      return threadPool;
+      return shortRunningExecutor;
    }
 
    /**
-    * Set the thread pool
-    * @param threadPool the thread pool
+    * Set the executor for short running tasks
+    * @param executor The executor
     */
-   public void setThreadPool(ThreadPool threadPool)
+   public void setShortRunningThreadPool(BlockingExecutor executor)
    {
-      this.threadPool = threadPool;
+      this.shortRunningExecutor = executor;
    }
 
    /**
+    * Retrieve the executor for long running tasks
+    * @return The executor
+    */
+   public BlockingExecutor getLongRunningThreadPool()
+   {
+      return longRunningExecutor;
+   }
+
+   /**
+    * Set the executor for long running tasks
+    * @param executor The executor
+    */
+   public void setLongRunningThreadPool(BlockingExecutor executor)
+   {
+      this.longRunningExecutor = executor;
+   }
+
+   /**
     * Get the XATerminator
     * @return The XA terminator
     */
@@ -175,22 +198,81 @@
                       WorkListener workListener) 
       throws WorkException
    {
-      checkAndVerifyWork(work, execContext);
+      WorkException exception = null;
+      WorkWrapper wrapper = null;
+      try
+      {
+         if (work == null)
+            throw new WorkRejectedException("Work is null");
+
+         if (startTimeout < 0)
+            throw new WorkRejectedException("StartTimeout is negative: " + startTimeout);
+
+         checkAndVerifyWork(work, execContext);
       
-      if (execContext == null)
+         if (execContext == null)
+         {
+            execContext = new ExecutionContext();  
+         }
+
+         final CountDownLatch completedLatch = new CountDownLatch(1);
+
+         wrapper = new WorkWrapper(this, work, execContext, workListener, null, completedLatch);
+
+         setup(wrapper);
+
+         if (workListener != null)
+         {
+            WorkEvent event = new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null);
+            workListener.workAccepted(event);
+         }
+
+         BlockingExecutor executor = getExecutor(work);
+
+         if (startTimeout == WorkManager.INDEFINITE)
+         {
+            executor.executeBlocking(wrapper);
+         }
+         else
+         {
+            executor.executeBlocking(wrapper, startTimeout, TimeUnit.MILLISECONDS);
+         }
+
+         completedLatch.await();
+      }
+      catch (ExecutionTimedOutException etoe)
       {
-         execContext = new ExecutionContext();  
+         exception = new WorkRejectedException(etoe);
+         exception.setErrorCode(WorkRejectedException.START_TIMED_OUT);  
       }
+      catch (RejectedExecutionException ree)
+      {
+         exception = new WorkRejectedException(ree);
+      }
+      catch (WorkException we)
+      {
+         exception = we;
+      }
+      catch (InterruptedException ie)
+      {
+         Thread.currentThread().interrupt();
+         exception = new WorkRejectedException("Interrupted while requesting permit");
+      }
+      finally
+      {
+         if (exception != null)
+         {
+            if (workListener != null)
+            {
+               WorkEvent event = new WorkEvent(this, WorkEvent.WORK_REJECTED, work, exception);
+               workListener.workRejected(event);
+            }
 
-      WorkWrapper wrapper = 
-         new WorkWrapper(this, work, Task.WAIT_FOR_COMPLETE, startTimeout, execContext, workListener);
+            throw exception;
+         }
 
-      //Submit Work Instance
-      submitWork(wrapper);
-      
-      //Check Result
-      checkWorkCompletionException(wrapper);
-
+         checkWorkCompletionException(wrapper);
+      }
    }
    
    /**
@@ -210,22 +292,87 @@
                          WorkListener workListener) 
       throws WorkException
    {
-      checkAndVerifyWork(work, execContext);
+      WorkException exception = null;
+      WorkWrapper wrapper = null;
+      try
+      {
+         if (work == null)
+            throw new WorkRejectedException("Work is null");
+
+         if (startTimeout < 0)
+            throw new WorkRejectedException("StartTimeout is negative: " + startTimeout);
+
+         long started = System.currentTimeMillis();
+
+         checkAndVerifyWork(work, execContext);
       
-      if (execContext == null)
+         if (execContext == null)
+         {
+            execContext = new ExecutionContext();  
+         }
+
+         final CountDownLatch startedLatch = new CountDownLatch(1);
+
+         wrapper = new WorkWrapper(this, work, execContext, workListener, startedLatch, null);
+
+         setup(wrapper);
+
+         if (workListener != null)
+         {
+            WorkEvent event = new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null);
+            workListener.workAccepted(event);
+         }
+
+         BlockingExecutor executor = getExecutor(work);
+
+         if (startTimeout == WorkManager.INDEFINITE)
+         {
+            executor.executeBlocking(wrapper);
+         }
+         else
+         {
+            executor.executeBlocking(wrapper, startTimeout, TimeUnit.MILLISECONDS);
+         }
+
+         startedLatch.await();
+
+         return System.currentTimeMillis() - started;
+      }
+      catch (ExecutionTimedOutException etoe)
       {
-         execContext = new ExecutionContext();  
+         exception = new WorkRejectedException(etoe);
+         exception.setErrorCode(WorkRejectedException.START_TIMED_OUT);  
       }
+      catch (RejectedExecutionException ree)
+      {
+         exception = new WorkRejectedException(ree);
+      }
+      catch (WorkException we)
+      {
+         exception = we;
+      }
+      catch (InterruptedException ie)
+      {
+         Thread.currentThread().interrupt();
+         exception = new WorkRejectedException("Interrupted while requesting permit");
+      }
+      finally
+      {
+         if (exception != null)
+         {
+            if (workListener != null)
+            {
+               WorkEvent event = new WorkEvent(this, WorkEvent.WORK_REJECTED, work, exception);
+               workListener.workRejected(event);
+            }
 
-      WorkWrapper wrapper = new WorkWrapper(this, work, Task.WAIT_FOR_START, startTimeout, execContext, workListener);
-      
-      //Submit Work Instance
-      submitWork(wrapper);
-      
-      //Check Result
-      checkWorkCompletionException(wrapper);
+            throw exception;
+         }
 
-      return wrapper.getBlockedElapsed();
+         checkWorkCompletionException(wrapper);
+      }
+
+      return WorkManager.UNKNOWN;
    }
    
    /**
@@ -245,217 +392,141 @@
                             WorkListener workListener) 
       throws WorkException
    {
-      checkAndVerifyWork(work, execContext);
-      
-      if (execContext == null)
+      WorkException exception = null;
+      WorkWrapper wrapper = null;
+      try
       {
-         execContext = new ExecutionContext();  
-      }
+         if (work == null)
+            throw new WorkRejectedException("Work is null");
 
-      WorkWrapper wrapper = new WorkWrapper(this, work, Task.WAIT_NONE, startTimeout, execContext, workListener);
-      
-      //Submit Work Instance
-      submitWork(wrapper);
-      
-      //Check Result
-      checkWorkCompletionException(wrapper);
-   }
+         if (startTimeout < 0)
+            throw new WorkRejectedException("StartTimeout is negative: " + startTimeout);
 
-   /**
-    * Imports any work.
-    * @param wrapper the work wrapper
-    * @throws WorkException for any error 
-    */
-   protected void importWork(WorkWrapper wrapper) throws WorkException
-   {
-      if (wrapper == null)
-      {
-         return;  
-      }
-            
-      trace = log.isTraceEnabled();
+         checkAndVerifyWork(work, execContext);
       
-      if (trace)
-      {
-         log.trace("Importing work " + wrapper);  
-      }
+         if (execContext == null)
+         {
+            execContext = new ExecutionContext();  
+         }
 
-      ExecutionContext ctx = wrapper.getWorkContext(TransactionContext.class);
-      if (ctx == null)
-      {
-         ctx = wrapper.getExecutionContext();
-      }
-      
-      if (ctx != null)
-      {
-         Xid xid = ctx.getXid();
-         if (xid != null)
+         wrapper = new WorkWrapper(this, work, execContext, workListener, null, null);
+
+         setup(wrapper);
+
+         if (workListener != null)
          {
-            //JBAS-4002 base value is in seconds as per the API, here we convert to millis
-            long timeout = (ctx.getTransactionTimeout() * 1000);
-            xaTerminator.registerWork(wrapper.getWork(), xid, timeout);
+            WorkEvent event = new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null);
+            workListener.workAccepted(event);
          }
-      }
-      
-      //Fires Context setup complete
-      fireWorkContextSetupComplete(ctx);
-      
-      if (trace)
-      {
-         log.trace("Imported work " + wrapper);  
-      }
-   }
-   
-   /**
-    * Submit the given work instance for executing by the thread pool.
-    * @param wrapper the work wrapper
-    * @throws WorkException for any error 
-    */
-   protected void submitWork(WorkWrapper wrapper) throws WorkException
-   {
-      if (wrapper == null)
-      {
-         return;  
-      }
-      
-      if (trace)
-      {
-         log.trace("Submitting work to thread pool " + wrapper);  
-      }
 
-      threadPool.runTaskWrapper(wrapper);
+         BlockingExecutor executor = getExecutor(work);
 
-      if (trace)
-      {
-         log.trace("Submitted work to thread pool " + wrapper);  
+         if (startTimeout == WorkManager.INDEFINITE)
+         {
+            executor.executeBlocking(wrapper);
+         }
+         else
+         {
+            executor.executeBlocking(wrapper, startTimeout, TimeUnit.MILLISECONDS);
+         }
       }
-   }
-
-   /**
-    * Starts given work instance.
-    * @param wrapper the work wrapper
-    * @throws WorkException for any error 
-    */
-   public void startWork(WorkWrapper wrapper) throws WorkException
-   {
-      if (wrapper == null)
+      catch (ExecutionTimedOutException etoe)
       {
-         return;  
-      }      
-
-      if (trace)
-      {
-         log.trace("Setting up work contexts " + wrapper);  
+         exception = new WorkRejectedException(etoe);
+         exception.setErrorCode(WorkRejectedException.START_TIMED_OUT);  
       }
-      
-      //Setting up WorkContexts if an exist
-      setupWorkContextProviders(wrapper);
-      
-      if (trace)
+      catch (RejectedExecutionException ree)
       {
-         log.trace("Setted up work contexts " + wrapper);  
+         exception = new WorkRejectedException(ree);
       }
-      
-      //Import work instance
-      importWork(wrapper);
-            
-      if (trace)
+      catch (WorkException we)
       {
-         log.trace("Starting work " + wrapper);  
+         exception = we;
       }
-
-      ExecutionContext ctx = wrapper.getWorkContext(TransactionContext.class);
-      if (ctx == null)
+      catch (InterruptedException ie)
       {
-         ctx = wrapper.getExecutionContext();
+         Thread.currentThread().interrupt();
+         exception = new WorkRejectedException("Interrupted while requesting permit");
       }
-      
-      if (ctx != null)
+      finally
       {
-         Xid xid = ctx.getXid();
-         if (xid != null)
+         if (exception != null)
          {
-            xaTerminator.startWork(wrapper.getWork(), xid);
+            if (workListener != null)
+            {
+               WorkEvent event = new WorkEvent(this, WorkEvent.WORK_REJECTED, work, exception);
+               workListener.workRejected(event);
+            }
+
+            throw exception;
          }
+
+         checkWorkCompletionException(wrapper);
       }
-      if (trace)
-      {
-         log.trace("Started work " + wrapper);  
-      }
    }
 
    /**
-    * Ends given work instance.
-    * @param wrapper the work wrapper
+    * Get the executor
+    * @param work The work instance
+    * @return The executor
     */
-   public void endWork(WorkWrapper wrapper)
+   private BlockingExecutor getExecutor(Work work)
    {
-      if (wrapper == null)
+      BlockingExecutor executor = shortRunningExecutor;
+      if (work instanceof WorkContextProvider)
       {
-         return;  
-      }
-      
-      if (trace)
-      {
-         log.trace("Ending work " + wrapper);  
-      }
+         WorkContextProvider wcProvider = (WorkContextProvider)work;
+         List<WorkContext> contexts = wcProvider.getWorkContexts();
 
-      ExecutionContext ctx = wrapper.getWorkContext(TransactionContext.class);
-      if (ctx == null)
-      {
-         ctx = wrapper.getExecutionContext();
-      }
-
-      if (ctx != null)
-      {
-         Xid xid = ctx.getXid();
-         if (xid != null)
+         if (contexts != null && contexts.size() > 0)
          {
-            xaTerminator.endWork(wrapper.getWork(), xid);
+            boolean found = false;
+            Iterator<WorkContext> it = contexts.iterator();
+            while (!found && it.hasNext())
+            {
+               WorkContext wc = it.next();
+               if (wc instanceof HintsContext)
+               {
+                  HintsContext hc = (HintsContext)wc;
+                  if (hc.getHints().containsKey(HintsContext.LONGRUNNING_HINT))
+                  {
+                     executor = longRunningExecutor;
+                     found = true;
+                  }
+               }
+            }
          }
       }
-      if (trace)
-      {
-         log.trace("Ended work " + wrapper);  
-      }
+
+      return executor;
    }
 
+
+
    /**
-    * Cancels given work instance.
-    * @param wrapper the work wrapper
+    * Check and verify work before submitting.
+    * @param work the work instance
+    * @param executionContext any execution context that is passed by apadater
+    * @throws WorkException if any exception occurs
     */
-   public void cancelWork(WorkWrapper wrapper)
+   private void checkAndVerifyWork(Work work, ExecutionContext executionContext) throws WorkException
    {
-      if (wrapper == null)
+      if (specCompliant)
       {
-         return;  
-      }
+         verifyWork(work);  
+      }   
       
-      if (trace)
+      if (work instanceof WorkContextProvider)
       {
-         log.trace("Cancel work " + wrapper);  
-      }
-
-      ExecutionContext ctx = wrapper.getWorkContext(TransactionContext.class);
-      if (ctx == null)
-      {
-         ctx = wrapper.getExecutionContext();
-      }
-
-      if (ctx != null)
-      {
-         Xid xid = ctx.getXid();
-         if (xid != null)
+          //Implements WorkContextProvider and not-null ExecutionContext
+         if (executionContext != null)
          {
-            xaTerminator.cancelWork(wrapper.getWork(), xid);
-         }
-      }
-      if (trace)
-      {
-         log.trace("Canceled work " + wrapper);  
-      }
+            throw new WorkRejectedException("Work execution context must be null because " +
+               "work instance implements WorkContextProvider!");
+         }          
+      }      
    }
-
+   
    /**
     * Verify the given work instance.
     * @param work The work
@@ -463,45 +534,84 @@
     */
    private void verifyWork(Work work) throws WorkException
    {     
-      Class<?> workClass = work.getClass();
-      boolean result = false;
+      if (!validatedWork.contains(work.getClass().getName()))
+      {
+         Class<?> workClass = work.getClass();
+         boolean result = false;
       
-      result = verfiyWorkMethods(workClass, RUN_METHOD_NAME, null, workClass.getName() + 
-            ": Run method is not defined");
+         result = verifyWorkMethods(workClass, RUN_METHOD_NAME, null, workClass.getName() + 
+                                    ": Run method is not defined");
      
-      if (!result)
-      {
-         throw new WorkException(workClass.getName() + ": Run method is synchronized");
-      }
+         if (!result)
+         {
+            throw new WorkException(workClass.getName() + ": Run method is synchronized");
+         }
       
-      result = verfiyWorkMethods(workClass, RELEASE_METHOD_NAME, null, workClass.getName() + 
-            ": Release method is not defined");
+         result = verifyWorkMethods(workClass, RELEASE_METHOD_NAME, null, workClass.getName() + 
+                                    ": Release method is not defined");
       
-      if (!result)
+         if (!result)
+         {
+            throw new WorkException(workClass.getName() + ": Release method is synchronized");
+         }
+
+         validatedWork.add(work.getClass().getName());
+      }
+   }
+   
+   private boolean verifyWorkMethods(Class<?> workClass, String methodName, 
+                                     Class<?>[] parameterTypes, String errorMessage) throws WorkException
+   {
+      Method method = null;
+      try
       {
-         throw new WorkException(workClass.getName() + ": Release method is synchronized");
+         method = ClassUtil.getClassMethod(workClass, methodName, null);
+         
+         if (ClassUtil.modifiersHasSynchronizedKeyword(method.getModifiers()))
+         {
+            return false;  
+         }
       }
+      catch (NoSuchMethodException nsme)
+      {
+         throw new WorkException(errorMessage);
+      }
+      
+      return true;
    }
-   
+
    /**
+    * Checks work completed status. 
+    * @param wrapper work wrapper instance
+    * @throws {@link WorkException} if work is completed with an exception
+    */
+   private void checkWorkCompletionException(WorkWrapper wrapper) throws WorkException
+   {
+      if (wrapper.getWorkException() != null)
+      {
+         throw wrapper.getWorkException();  
+      }      
+   }
+
+   /**
     * Setup work context's of the given work instance.
     * 
-    * @param wrapper wrapper work instance
+    * @param wrapper The work wrapper instance
     * @throws WorkException if any exception occurs
     */
-   private void setupWorkContextProviders(WorkWrapper wrapper) throws WorkException
+   private void setup(WorkWrapper wrapper) throws WorkException
    {
       if (trace)
       {
-         log.trace("Starting checking work context providers");
+         log.trace("Setting up work contexts " + wrapper);  
       }
 
       Work work = wrapper.getWork();
-
+      
       //If work is an instanceof WorkContextProvider
       if (work instanceof WorkContextProvider)
       {
-         WorkContextProvider wcProvider = (WorkContextProvider) work;
+         WorkContextProvider wcProvider = (WorkContextProvider)work;
          List<WorkContext> contexts = wcProvider.getWorkContexts();
 
          if (contexts != null && contexts.size() > 0)
@@ -608,38 +718,26 @@
             }
          }         
       }      
+
+      if (trace)
+      {
+         log.trace("Setted up work contexts " + wrapper);  
+      }      
    }
 
    /**
-    * Returns work context class if given work context is supported by server,
-    * returns null instance otherwise.
-    * 
-    * @param <T> work context class
-    * @param adaptorWorkContext adaptor supplied work context class
-    * @return work context class
+    * Calls listener with given error code.
+    * @param listener work context listener
+    * @param errorCode error code
     */
-   @SuppressWarnings("unchecked")
-   private <T extends WorkContext> Class<T> getSupportedWorkContextClass(Class<T> adaptorWorkContext)
+   private void fireWorkContextSetupFailed(Object workContext, String errorCode)
    {
-      for (Class<? extends WorkContext> supportedWorkContext : SUPPORTED_WORK_CONTEXT_CLASSES)
+      if (workContext instanceof WorkContextLifecycleListener)
       {
-         // Assignable or not
-         if (supportedWorkContext.isAssignableFrom(adaptorWorkContext))
-         {
-            // Supported by the server
-            if (adaptorWorkContext.equals(supportedWorkContext))
-            {
-               return adaptorWorkContext;
-            }
-            else
-            {
-               // Fallback to super class
-               return (Class<T>) adaptorWorkContext.getSuperclass();
-            }
-         }
+         WorkContextLifecycleListener listener = (WorkContextLifecycleListener)workContext;
+         listener.contextSetupFailed(errorCode);   
       }
-
-      return null;
+      
    }
 
    /**
@@ -689,97 +787,36 @@
 
       return false;
    }
-   
-   /**
-    * Check and verfiy work before submitting.
-    * @param work the work instance
-    * @param executionContext any execution context that is passed by apadater
-    * @throws WorkException if any exception occurs
-    */
-   private void checkAndVerifyWork(Work work, ExecutionContext executionContext) throws WorkException
-   {
-      if (work == null)
-      {
-         throw new WorkException("Null work");  
-      }
 
-      if (specCompliant)
-      {
-         verifyWork(work);  
-      }   
-      
-      if (work instanceof WorkContextProvider)
-      {
-          //Implements WorkContextProvider and not-null ExecutionContext
-         if (executionContext != null)
-         {
-            throw new WorkRejectedException("Work execution context must be null because " +
-               "work instance implements WorkContextProvider!");
-         }          
-      }      
-   }
-   
    /**
-    * Checks work completed status. 
-    * @param wrapper work wrapper instance
-    * @throws {@link WorkException} if work is completed with an exception
+    * Returns work context class if given work context is supported by server,
+    * returns null instance otherwise.
+    * 
+    * @param <T> work context class
+    * @param adaptorWorkContext adaptor supplied work context class
+    * @return work context class
     */
-   private void checkWorkCompletionException(WorkWrapper wrapper) throws WorkException
+   @SuppressWarnings("unchecked")
+   private <T extends WorkContext> Class<T> getSupportedWorkContextClass(Class<T> adaptorWorkContext)
    {
-      if (wrapper.getWorkException() != null)
+      for (Class<? extends WorkContext> supportedWorkContext : SUPPORTED_WORK_CONTEXT_CLASSES)
       {
-         throw wrapper.getWorkException();  
-      }      
-   }
-
-   private boolean verfiyWorkMethods(Class<?> workClass, String methodName, 
-         Class<?>[] parameterTypes, String errorMessage) throws WorkException
-   {
-      Method method = null;
-      try
-      {
-         method = ClassUtil.getClassMethod(workClass, methodName, null);
-         
-         if (ClassUtil.modifiersHasSynchronizedKeyword(method.getModifiers()))
+         // Assignable or not
+         if (supportedWorkContext.isAssignableFrom(adaptorWorkContext))
          {
-            return false;  
+            // Supported by the server
+            if (adaptorWorkContext.equals(supportedWorkContext))
+            {
+               return adaptorWorkContext;
+            }
+            else
+            {
+               // Fallback to super class
+               return (Class<T>) adaptorWorkContext.getSuperclass();
+            }
          }
       }
-      catch (NoSuchMethodException nsme)
-      {
-         throw new WorkException(errorMessage);
-      }
-      
-      return true;
+
+      return null;
    }
-   
-   /**
-    * Calls listener with given error code.
-    * @param listener work context listener
-    * @param errorCode error code
-    */
-   private void fireWorkContextSetupFailed(Object workContext, String errorCode)
-   {
-      if (workContext instanceof WorkContextLifecycleListener)
-      {
-         WorkContextLifecycleListener listener = (WorkContextLifecycleListener)workContext;
-         listener.contextSetupFailed(errorCode);   
-      }
-      
-   }
-   
-   /**
-    * Calls listener after work context is setted up.
-    * @param listener work context listener
-    */
-   private void fireWorkContextSetupComplete(Object workContext)
-   {
-      if (workContext instanceof WorkContextLifecycleListener)
-      {
-         WorkContextLifecycleListener listener = (WorkContextLifecycleListener)workContext;
-         listener.contextSetupComplete();   
-      }
-      
-   }
-   
 }

Copied: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/workmanager/WorkWrapper.java (from rev 99906, projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/WorkWrapper.java)
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/workmanager/WorkWrapper.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/workmanager/WorkWrapper.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -0,0 +1,415 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.core.workmanager;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+
+import javax.resource.spi.work.ExecutionContext;
+import javax.resource.spi.work.HintsContext;
+import javax.resource.spi.work.SecurityContext;
+import javax.resource.spi.work.TransactionContext;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkCompletedException;
+import javax.resource.spi.work.WorkContext;
+import javax.resource.spi.work.WorkContextErrorCodes;
+import javax.resource.spi.work.WorkContextLifecycleListener;
+import javax.resource.spi.work.WorkContextProvider;
+import javax.resource.spi.work.WorkEvent;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkListener;
+import javax.resource.spi.work.WorkRejectedException;
+import javax.transaction.xa.Xid;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Wraps the resource adapter's work.
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: 71538 $
+ */
+public class WorkWrapper implements Runnable
+{
+   /** The log */
+   private static Logger log = Logger.getLogger(WorkWrapper.class);
+
+   /** Whether we are tracing */
+   private static boolean trace = log.isTraceEnabled();
+   
+   /** The work */
+   private Work work;
+
+   /** The execution context */
+   private ExecutionContext executionContext;
+   
+   /**If work is an instance of WorkContextProvider, it may contain WorkContext instances */
+   private Map<Class<? extends WorkContext>, WorkContext> workContexts;
+
+   /** the work listener */
+   private WorkListener workListener;   
+
+   /** The work manager */
+   private org.jboss.jca.core.api.WorkManager workManager;
+
+   /** The blocked time */
+   private long blockedTime;
+
+   /** Any exception */
+   private WorkException exception;
+
+   /** Started latch */
+   private CountDownLatch startedLatch;
+
+   /** Completed latch */
+   private CountDownLatch completedLatch;
+
+   /**
+    * Create a new WorkWrapper
+    *
+    * @param workManager the work manager
+    * @param work the work
+    * @param waitType the waitType
+    * @param executionContext the execution context
+    * @param workListener the WorkListener
+    * @throws IllegalArgumentException for null work, execution context or a negative start timeout
+    */
+   public WorkWrapper(org.jboss.jca.core.api.WorkManager workManager, 
+                      Work work, 
+                      ExecutionContext executionContext, 
+                      WorkListener workListener,
+                      CountDownLatch startedLatch,
+                      CountDownLatch completedLatch)
+   {
+      super();
+
+      if (work == null)
+         throw new IllegalArgumentException("Null work");
+      if (executionContext == null)
+         throw new IllegalArgumentException("Null execution context");
+
+      this.workManager = workManager;
+      this.work = work;
+      this.executionContext = executionContext;
+      this.workListener = workListener;
+      this.startedLatch = startedLatch;
+      this.completedLatch = completedLatch;
+      this.workContexts = null;
+   }
+   
+   /**
+    * Get the work manager
+    *
+    * @return the work manager
+    */
+   public org.jboss.jca.core.api.WorkManager getWorkManager()
+   {
+      return workManager;
+   }
+
+   /**
+    * Retrieve the work
+    *
+    * @return the work
+    */
+   public Work getWork()
+   {
+      return work;
+   }
+
+   /**
+    * Retrieve the exection context
+    *
+    * @return the execution context
+    */
+   public ExecutionContext getExecutionContext()
+   {
+      return executionContext;
+   }
+
+   /**
+    * Retrieve the work listener
+    *
+    * @return the WorkListener
+    */
+   public WorkListener getWorkListener()
+   {
+      return workListener;
+   }
+   
+   /**
+    * Get any exception
+    * 
+    * @return the exception or null if there is none
+    */
+   public WorkException getWorkException()
+   {
+      return exception;
+   }
+
+   /**
+    * Run
+    */
+   public void run()
+   {
+      if (trace)
+         log.trace("Starting work " + this);  
+
+      try
+      {
+         start();
+
+         if (startedLatch != null)
+            startedLatch.countDown();
+
+         work.run();
+
+         end();
+      }
+      catch (Exception e)
+      {
+         exception = new WorkCompletedException(e);
+
+         cancel();
+      } 
+      finally
+      {
+         work.release();
+
+         if (workListener != null)
+         {
+            WorkEvent event = new WorkEvent(workManager, WorkEvent.WORK_COMPLETED, work, exception);
+            workListener.workCompleted(event);
+         }
+
+         if (startedLatch != null)
+         {
+            while (startedLatch.getCount() != 0)
+               startedLatch.countDown();
+         }
+
+         if (completedLatch != null)
+            completedLatch.countDown();
+
+         if (trace)
+            log.trace("Executed work " + this);  
+      }
+   }
+
+   /**
+    * Start
+    * @throws WorkException for any error 
+    */
+   protected void start() throws WorkException
+   {
+      if (trace)
+      {
+         log.trace("Starting work " + this);  
+      }
+
+      ExecutionContext ctx = getWorkContext(TransactionContext.class);
+      if (ctx == null)
+      {
+         ctx = getExecutionContext();
+      }
+      
+      if (ctx != null)
+      {
+         Xid xid = ctx.getXid();
+         if (xid != null)
+         {
+            //JBAS-4002 base value is in seconds as per the API, here we convert to millis
+            long timeout = (ctx.getTransactionTimeout() * 1000);
+            workManager.getXATerminator().registerWork(work, xid, timeout);
+         }
+      }
+      
+      //Fires Context setup complete
+      fireWorkContextSetupComplete(ctx);
+      
+      if (ctx != null)
+      {
+         Xid xid = ctx.getXid();
+         if (xid != null)
+         {
+            workManager.getXATerminator().startWork(work, xid);
+         }
+      }
+
+      if (workListener != null)
+      {
+         WorkEvent event = new WorkEvent(workManager, WorkEvent.WORK_STARTED, work, null);
+         workListener.workStarted(event);
+      }
+
+      if (trace)
+      {
+         log.trace("Started work " + this);  
+      }
+   }
+
+   /**
+    * End
+    */
+   protected void end()
+   {
+      if (trace)
+      {
+         log.trace("Ending work " + this);  
+      }
+
+      ExecutionContext ctx = getWorkContext(TransactionContext.class);
+      if (ctx == null)
+      {
+         ctx = getExecutionContext();
+      }
+
+      if (ctx != null)
+      {
+         Xid xid = ctx.getXid();
+         if (xid != null)
+         {
+            workManager.getXATerminator().endWork(work, xid);
+         }
+      }
+
+      if (trace)
+      {
+         log.trace("Ended work " + this);  
+      }
+   }
+
+   /**
+    * Cancel
+    */
+   protected void cancel()
+   {
+      if (trace)
+         log.trace("Cancel work " + this);  
+
+      ExecutionContext ctx = getWorkContext(TransactionContext.class);
+      if (ctx == null)
+      {
+         ctx = getExecutionContext();
+      }
+
+      if (ctx != null)
+      {
+         Xid xid = ctx.getXid();
+         if (xid != null)
+         {
+            workManager.getXATerminator().cancelWork(work, xid);
+         }
+      }
+
+      if (trace)
+         log.trace("Canceled work " + this);  
+   }
+
+   /**
+    * Returns work context instance.
+    * 
+    * @param <T> class type info
+    * @param workContextClass work context type
+    * @return work context instance
+    */
+   public <T> T getWorkContext(Class<T> workContextClass)
+   {
+      T instance = null;
+
+      if (workContexts != null && workContexts.containsKey(workContextClass))
+      {
+         instance = workContextClass.cast(workContexts.get(workContextClass));
+      }
+
+      return instance;
+   }
+
+   /**
+    * Adds new work context.
+    * 
+    * @param workContext new work context
+    * @param workContextClass work context class
+    */
+   public void addWorkContext(Class<? extends WorkContext> workContextClass, WorkContext workContext)
+   {
+      if (workContextClass == null)
+      {
+         throw new IllegalArgumentException("Work context class is null");
+      }
+
+      if (workContext == null)
+      {
+         throw new IllegalArgumentException("Work context is null");
+      }
+
+      if (workContexts == null)
+      {
+         workContexts = new HashMap<Class<? extends WorkContext>, WorkContext>(1);
+      }
+
+      workContexts.put(workContextClass, workContext);
+   }
+   
+   /**
+    * Calls listener after work context is setted up.
+    * @param listener work context listener
+    */
+   private void fireWorkContextSetupComplete(Object workContext)
+   {
+      if (workContext != null && workContext instanceof WorkContextLifecycleListener)
+      {
+         WorkContextLifecycleListener listener = (WorkContextLifecycleListener)workContext;
+         listener.contextSetupComplete();   
+      }
+   }
+   
+   /**
+    * String representation
+    * @return The string
+    */
+   public String toString()
+   {
+      StringBuilder buffer = new StringBuilder(100);
+      buffer.append("WorkWrapper@").append(Integer.toHexString(System.identityHashCode(this)));
+      buffer.append("[workManger=").append(workManager);
+      buffer.append(" work=").append(work);
+
+      if (executionContext != null && executionContext.getXid() != null)
+      {
+         buffer.append(" xid=").append(executionContext.getXid());
+         buffer.append(" txTimeout=").append(executionContext.getTransactionTimeout());
+      }
+
+      if (workListener != null)
+         buffer.append(" workListener=").append(workListener);
+      if (exception != null)
+         buffer.append(" exception=").append(exception);
+      buffer.append("]");
+      return buffer.toString();
+   }
+}

Modified: projects/jboss-jca/trunk/core/src/main/resources/deployment/jca.xml
===================================================================
--- projects/jboss-jca/trunk/core/src/main/resources/deployment/jca.xml	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/main/resources/deployment/jca.xml	2010-02-09 16:01:38 UTC (rev 100758)
@@ -5,26 +5,54 @@
 -->
 <deployment xmlns="urn:jboss:bean-deployer:2.0">
 
-  <!-- Work Manager thread pool -->
-  <bean name="WorkManagerThreadPool" interface="org.jboss.jca.common.threadpool.ThreadPool" class="org.jboss.jca.common.threadpool.ThreadPoolImpl">
-    <!-- The name that appears in thread names -->
-    <property name="name">WorkManager</property>
+  <!-- Thread group -->
+  <bean name="ThreadGroup"
+        class="java.lang.ThreadGroup">
+    <constructor>
+      <parameter>workmanager</parameter>
+    </constructor>
+    <ignoreStop/>
+    <ignoreDestroy/>
+  </bean>
 
-    <!-- The maximum amount of work in the queue -->
-    <property name="maximumQueueSize">1024</property>
-    
-    <!-- The maximum number of active threads -->
-    <property name="maximumPoolSize">100</property>
-    
-    <!-- How long to keep threads alive after their last work (default one minute) -->
-    <property name="keepAliveTime">60000</property>
+  <!-- Thread factory -->
+  <bean name="ThreadFactory"
+        interface="java.util.concurrent.ThreadFactory"
+        class="org.jboss.threads.JBossThreadFactory">
+    <constructor>
+      <parameter><inject bean="ThreadGroup"/></parameter>
+      <parameter>false</parameter>
+      <parameter>5</parameter>
+      <parameter>work</parameter>
+      <parameter><null/></parameter>
+      <parameter><null/></parameter>
+    </constructor>
   </bean>
 
+  <!-- Short running thread pool -->
+  <bean name="ShortRunningThreadPool">
+    <constructor factoryMethod="threadFactoryExecutor" 
+                 factoryClass="org.jboss.threads.JBossExecutors">
+      <parameter><inject bean="ThreadFactory"/></parameter>
+    </constructor>
+  </bean>
+
+  <!-- Long running thread pool -->
+  <bean name="LongRunningThreadPool">
+    <constructor factoryMethod="threadFactoryExecutor" 
+                 factoryClass="org.jboss.threads.JBossExecutors">
+      <parameter><inject bean="ThreadFactory"/></parameter>
+    </constructor>
+  </bean>
+
   <!-- Work Manager -->
   <bean name="WorkManager" interface="org.jboss.jca.core.api.WorkManager" class="org.jboss.jca.core.workmanager.WorkManagerImpl">
-    <!-- The thread pool -->
-    <property name="threadPool"><inject bean="WorkManagerThreadPool"/></property>
+    <!-- The short running thread pool -->
+    <property name="ShortRunningThreadPool"><inject bean="ShortRunningThreadPool"/></property>
 
+    <!-- The long running thread pool -->
+    <property name="LongRunningThreadPool"><inject bean="LongRunningThreadPool"/></property>
+
     <!-- The XA terminator -->
     <property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
   </bean>

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerDoWorkTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerDoWorkTestCase.java	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerDoWorkTestCase.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -30,6 +30,7 @@
 import javax.resource.spi.work.Work;
 import javax.resource.spi.work.WorkException;
 import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.WorkRejectedException;
 
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -187,7 +188,7 @@
     * to indicate an negative value start delay duration
     * @throws Throwable throwable exception 
     */
-   @Test(expected = IllegalArgumentException.class)
+   @Test(expected = WorkRejectedException.class)
    public void testDoWorkFullSpecWithNegativeStartTimeout() throws Throwable
    {
       WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
@@ -196,7 +197,6 @@
       assertFalse(work.hasCallRun());
 
       workManager.doWork(work, -5, null, null);
-      assertTrue(work.hasCallRun());
    }
    
    /**

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingDoWorkTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingDoWorkTestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingDoWorkTestCase.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.api;
+
+import org.jboss.jca.embedded.EmbeddedJCA;
+import org.jboss.jca.test.core.spec.chapter10.common.MyWorkAdapter;
+import org.jboss.jca.test.core.spec.chapter10.common.ShortRunningWork;
+
+import javax.resource.spi.work.ExecutionContext;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.WorkRejectedException;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * WorkManagerRejectingDoWorkTestCase.
+ * 
+ * Tests for rejecting work instance to the WorkManager doWork() methods
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class WorkManagerRejectingDoWorkTestCase
+{
+   /*
+    * Embedded
+    */
+   private static EmbeddedJCA embedded;
+   
+   /**
+    * doWork method
+    * @throws Throwable throwable exception 
+    */
+   @Test(expected = WorkRejectedException.class)
+   public void testDoWork() throws Throwable
+   {
+      WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
+
+      ShortRunningWork work = new ShortRunningWork();
+
+      workManager.doWork(work);
+   }
+   
+   /**
+    * doWork method (full signature)
+    * @throws Throwable throwable exception 
+    */
+   @Test(expected = WorkRejectedException.class)
+   public void testDoWorkFullSignature() throws Throwable
+   {
+      WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
+
+      ShortRunningWork work = new ShortRunningWork();
+      MyWorkAdapter wa = new MyWorkAdapter();
+      
+      workManager.doWork(work, WorkManager.INDEFINITE, null, wa);
+   }
+   
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+   /**
+    * Lifecycle start, before the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @BeforeClass
+   public static void beforeClass() throws Throwable
+   {
+      // Create and set an embedded JCA instance
+      embedded = new EmbeddedJCA(false);
+
+      // Startup
+      embedded.startup();
+
+      // Deploy Naming, Transaction and WorkManager
+      embedded.deploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "naming-jboss-beans.xml");
+      embedded.deploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "transaction-jboss-beans.xml");
+      embedded.deploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), 
+                      "rejecting-workmanager-jboss-beans.xml");
+   }
+
+   /**
+    * Lifecycle stop, after the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @AfterClass
+   public static void afterClass() throws Throwable
+   {
+      // Undeploy WorkManager, Transaction and Naming
+      embedded.undeploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), 
+                        "rejecting-workmanager-jboss-beans.xml");
+      embedded.undeploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "transaction-jboss-beans.xml");
+      embedded.undeploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "naming-jboss-beans.xml");
+
+      // Shutdown embedded
+      embedded.shutdown();
+
+      // Set embedded to null
+      embedded = null;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingScheduleWorkTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingScheduleWorkTestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingScheduleWorkTestCase.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.api;
+
+import org.jboss.jca.embedded.EmbeddedJCA;
+import org.jboss.jca.test.core.spec.chapter10.common.MyWorkAdapter;
+import org.jboss.jca.test.core.spec.chapter10.common.ShortRunningWork;
+
+import javax.resource.spi.work.ExecutionContext;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.WorkRejectedException;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * WorkManagerRejectingScheduleWorkTestCase.
+ * 
+ * Tests for rejecting work instance to the WorkManager scheduleWork() methods
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class WorkManagerRejectingScheduleWorkTestCase
+{
+   /*
+    * Embedded
+    */
+   private static EmbeddedJCA embedded;
+   
+   /**
+    * scheduleWork method
+    * @throws Throwable throwable exception 
+    */
+   @Test(expected = WorkRejectedException.class)
+   public void testScheduleWork() throws Throwable
+   {
+      WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
+
+      ShortRunningWork work = new ShortRunningWork();
+
+      workManager.scheduleWork(work);
+   }
+   
+   /**
+    * scheduleWork method (full signature)
+    * @throws Throwable throwable exception 
+    */
+   @Test(expected = WorkRejectedException.class)
+   public void testScheduleWorkFullSignature() throws Throwable
+   {
+      WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
+
+      ShortRunningWork work = new ShortRunningWork();
+      MyWorkAdapter wa = new MyWorkAdapter();
+      
+      workManager.scheduleWork(work, WorkManager.INDEFINITE, null, wa);
+   }
+   
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+   /**
+    * Lifecycle start, before the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @BeforeClass
+   public static void beforeClass() throws Throwable
+   {
+      // Create and set an embedded JCA instance
+      embedded = new EmbeddedJCA(false);
+
+      // Startup
+      embedded.startup();
+
+      // Deploy Naming, Transaction and WorkManager
+      embedded.deploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "naming-jboss-beans.xml");
+      embedded.deploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "transaction-jboss-beans.xml");
+      embedded.deploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), 
+                      "rejecting-workmanager-jboss-beans.xml");
+   }
+
+   /**
+    * Lifecycle stop, after the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @AfterClass
+   public static void afterClass() throws Throwable
+   {
+      // Undeploy WorkManager, Transaction and Naming
+      embedded.undeploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), 
+                        "rejecting-workmanager-jboss-beans.xml");
+      embedded.undeploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "transaction-jboss-beans.xml");
+      embedded.undeploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "naming-jboss-beans.xml");
+
+      // Shutdown embedded
+      embedded.shutdown();
+
+      // Set embedded to null
+      embedded = null;
+   }
+}

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingStartWorkTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingStartWorkTestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerRejectingStartWorkTestCase.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.api;
+
+import org.jboss.jca.embedded.EmbeddedJCA;
+import org.jboss.jca.test.core.spec.chapter10.common.MyWorkAdapter;
+import org.jboss.jca.test.core.spec.chapter10.common.ShortRunningWork;
+
+import javax.resource.spi.work.ExecutionContext;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.WorkRejectedException;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * WorkManagerRejectingStartWorkTestCase.
+ * 
+ * Tests for rejecting work instance to the WorkManager startWork() methods
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class WorkManagerRejectingStartWorkTestCase
+{
+   /*
+    * Embedded
+    */
+   private static EmbeddedJCA embedded;
+   
+   /**
+    * startWork method
+    * @throws Throwable throwable exception 
+    */
+   @Test(expected = WorkRejectedException.class)
+   public void testStartWork() throws Throwable
+   {
+      WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
+
+      ShortRunningWork work = new ShortRunningWork();
+
+      workManager.startWork(work);
+   }
+   
+   /**
+    * startWork method (full signature)
+    * @throws Throwable throwable exception 
+    */
+   @Test(expected = WorkRejectedException.class)
+   public void testStartWorkFullSignature() throws Throwable
+   {
+      WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
+
+      ShortRunningWork work = new ShortRunningWork();
+      MyWorkAdapter wa = new MyWorkAdapter();
+      
+      workManager.startWork(work, WorkManager.INDEFINITE, null, wa);
+   }
+   
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+   /**
+    * Lifecycle start, before the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @BeforeClass
+   public static void beforeClass() throws Throwable
+   {
+      // Create and set an embedded JCA instance
+      embedded = new EmbeddedJCA(false);
+
+      // Startup
+      embedded.startup();
+
+      // Deploy Naming, Transaction and WorkManager
+      embedded.deploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "naming-jboss-beans.xml");
+      embedded.deploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "transaction-jboss-beans.xml");
+      embedded.deploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), 
+                      "rejecting-workmanager-jboss-beans.xml");
+   }
+
+   /**
+    * Lifecycle stop, after the suite is executed
+    * @throws Throwable throwable exception 
+    */
+   @AfterClass
+   public static void afterClass() throws Throwable
+   {
+      // Undeploy WorkManager, Transaction and Naming
+      embedded.undeploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), 
+                        "rejecting-workmanager-jboss-beans.xml");
+      embedded.undeploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "transaction-jboss-beans.xml");
+      embedded.undeploy(WorkManagerRejectingStartWorkTestCase.class.getClassLoader(), "naming-jboss-beans.xml");
+
+      // Shutdown embedded
+      embedded.shutdown();
+
+      // Set embedded to null
+      embedded = null;
+   }
+}

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerScheduleWorkTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerScheduleWorkTestCase.java	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerScheduleWorkTestCase.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -32,6 +32,7 @@
 import javax.resource.spi.work.Work;
 import javax.resource.spi.work.WorkException;
 import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.WorkRejectedException;
 
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -214,7 +215,7 @@
     *       to indicate an unknown start delay duration or other unknown values.
     * @throws Throwable throwable exception 
     */
-   @Test(expected = IllegalArgumentException.class)
+   @Test(expected = WorkRejectedException.class)
    public void testScheduleWorkFullSpecWithUnknowStartTimeout() throws Throwable
    {
       WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
@@ -237,7 +238,7 @@
     *   to indicate an negative value start delay duration
     * @throws Throwable throwable exception 
     */
-   @Test(expected = IllegalArgumentException.class)
+   @Test(expected = WorkRejectedException.class)
    public void testScheduleWorkFullSpecWithNegativeStartTimeout() throws Throwable
    {
       WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerStartWorkTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerStartWorkTestCase.java	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkManagerStartWorkTestCase.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -32,6 +32,7 @@
 import javax.resource.spi.work.Work;
 import javax.resource.spi.work.WorkException;
 import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.WorkRejectedException;
 
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -225,7 +226,7 @@
     *       to indicate an unknown start delay duration or other unknown values.
     * @throws Throwable throwable exception 
     */
-   @Test(expected = IllegalArgumentException.class)
+   @Test(expected = WorkRejectedException.class)
    public void testStartWorkFullSpecWithUnknowStartTimeout() throws Throwable
    {
       WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
@@ -248,7 +249,7 @@
     *       to indicate an negative value start delay duration
     * @throws Throwable throwable exception 
     */
-   @Test(expected = IllegalArgumentException.class)
+   @Test(expected = WorkRejectedException.class)
    public void testStartWorkFullSpecWithNegativeStartTimeout() throws Throwable
    {
       WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkTestCase.java	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/api/WorkTestCase.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -78,17 +78,9 @@
       WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
       
       ShortRunningWork shortWork = new ShortRunningWork();
-      workManager.startWork(shortWork);
       assertFalse(shortWork.getWasReleased());
-      
-      final CountDownLatch start = new CountDownLatch(1);
-      final CountDownLatch done = new CountDownLatch(1);
-      
-      LongRunningWork longWork = new LongRunningWork(start, done);
-      workManager.startWork(longWork);
-      //TODO we should impl call release()
-      //assertTrue(longWork.getWasReleased();
-
+      workManager.doWork(shortWork);
+      assertTrue(shortWork.getWasReleased());
    }
    
    // --------------------------------------------------------------------------------||

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/MyWorkAdapter.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/MyWorkAdapter.java	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/common/MyWorkAdapter.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -51,10 +51,15 @@
       source = e.getSource();
       work = e.getWork();
       startDuration = e.getStartDuration();
-      synchronized (this) 
+      
+      if (callbackCount != null)
       {
-         callbackCount.setAcceptCount(callbackCount.getAcceptCount() + 1);
+         synchronized (this) 
+         {
+            callbackCount.setAcceptCount(callbackCount.getAcceptCount() + 1);
+         }
       }
+
       super.workCompleted(e);
    }
 
@@ -66,10 +71,14 @@
    @Override
    public void workStarted(WorkEvent e)
    {
-      synchronized (this) 
+      if (callbackCount != null)
       {
-         callbackCount.setStartCount(callbackCount.getStartCount() + 1);
+         synchronized (this) 
+         {
+            callbackCount.setStartCount(callbackCount.getStartCount() + 1);
+         }
       }
+
       super.workStarted(e);
    }
    
@@ -81,10 +90,14 @@
    @Override
    public void workCompleted(WorkEvent e)
    {
-      synchronized (this) 
+      if (callbackCount != null)
       {
-         callbackCount.setCompletedCount(callbackCount.getCompletedCount() + 1);
+         synchronized (this) 
+         {
+            callbackCount.setCompletedCount(callbackCount.getCompletedCount() + 1);
+         }
       }
+
       super.workCompleted(e);
    }
 

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section1/ManageThreadTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section1/ManageThreadTestCase.java	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section1/ManageThreadTestCase.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -21,9 +21,10 @@
  */
 package org.jboss.jca.test.core.spec.chapter10.section1;
 
-import org.jboss.jca.common.api.ThreadPool;
 import org.jboss.jca.embedded.EmbeddedJCA;
 
+import org.jboss.threads.BlockingExecutor;
+
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -54,8 +55,12 @@
    {
       org.jboss.jca.core.api.WorkManager workManager = 
          embedded.lookup("WorkManager", org.jboss.jca.core.api.WorkManager.class);
-      ThreadPool threadPool = workManager.getThreadPool();
-      assertNotNull(threadPool);
+
+      BlockingExecutor shortRunning = workManager.getShortRunningThreadPool();
+      assertNotNull(shortRunning);
+
+      BlockingExecutor longRunning = workManager.getShortRunningThreadPool();
+      assertNotNull(longRunning);
    }
 
    /**

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	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkInterfaceTestCase.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -112,17 +112,9 @@
       WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
       
       ShortRunningWork shortWork = new ShortRunningWork();
-      workManager.startWork(shortWork);
       assertFalse(shortWork.getWasReleased());
-      
-      final CountDownLatch start = new CountDownLatch(1);
-      final CountDownLatch done = new CountDownLatch(1);
-      
-      LongRunningWork longWork = new LongRunningWork(start, done);
-      workManager.startWork(longWork);
-      //TODO we should impl call release()
-      //assertTrue(longWork.getWasReleased();
-
+      workManager.doWork(shortWork);
+      assertTrue(shortWork.getWasReleased());
    }
    
    /**

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkListenerInterfaceTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkListenerInterfaceTestCase.java	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/spec/chapter10/section3/WorkListenerInterfaceTestCase.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -99,7 +99,7 @@
     * Test for paragraph 1 Section 3.3.4
     * @throws Throwable throwable exception 
     */
-   @Test
+   @Ignore
    public void testWorkStartedStatus() throws Throwable
    {
       WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
@@ -186,7 +186,7 @@
    public void testSourceObjectIsInitial() throws Throwable
    {
       WorkManager workManager = embedded.lookup("WorkManager", WorkManager.class);
-      
+
       Work work = new ShortRunningWork();
       MyWorkAdapter wa = new MyWorkAdapter();
       workManager.doWork(work, 0, null, wa);

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/workmanager/unit/WorkManagerTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/workmanager/unit/WorkManagerTestCase.java	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/test/core/workmanager/unit/WorkManagerTestCase.java	2010-02-09 16:01:38 UTC (rev 100758)
@@ -83,8 +83,8 @@
          embedded.lookup("WorkManager", org.jboss.jca.core.api.WorkManager.class);
 
       assertNotNull(workManager);
-      assertNotNull(workManager.getThreadPool());
-      assertTrue(workManager.getThreadPool() instanceof org.jboss.jca.common.api.ThreadPool);
+      assertNotNull(workManager.getShortRunningThreadPool());
+      assertNotNull(workManager.getLongRunningThreadPool());
    }
 
    /**

Modified: projects/jboss-jca/trunk/core/src/test/resources/logging.properties
===================================================================
--- projects/jboss-jca/trunk/core/src/test/resources/logging.properties	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/test/resources/logging.properties	2010-02-09 16:01:38 UTC (rev 100758)
@@ -30,7 +30,7 @@
 logger.handlers=CONSOLE, FILE
 
 # org.jboss.jca
-logger.org.jboss.jca.level=DEBUG
+logger.org.jboss.jca.level=TRACE
 
 # org.jboss
 logger.org.jboss.level=INFO
@@ -50,7 +50,7 @@
 
 # File handler configuration
 handler.FILE=org.jboss.logmanager.handlers.FileHandler
-handler.FILE.level=${jboss.jca.log.file.level:DEBUG}
+handler.FILE.level=${jboss.jca.log.file.level:TRACE}
 handler.FILE.properties=autoFlush,fileName
 handler.FILE.autoFlush=true
 handler.FILE.fileName=${test.dir}/core/test.log

Added: projects/jboss-jca/trunk/core/src/test/resources/rejecting-workmanager-jboss-beans.xml
===================================================================
--- projects/jboss-jca/trunk/core/src/test/resources/rejecting-workmanager-jboss-beans.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/resources/rejecting-workmanager-jboss-beans.xml	2010-02-09 16:01:38 UTC (rev 100758)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+    JBoss JCA
+-->
+<deployment>
+
+  <!-- Short running thread pool -->
+  <bean name="ShortRunningThreadPool">
+    <constructor factoryMethod="blockingRejectingExecutor" 
+                 factoryClass="org.jboss.threads.JBossExecutors"/>
+  </bean>
+
+  <!-- Long running thread pool -->
+  <bean name="LongRunningThreadPool">
+    <constructor factoryMethod="blockingRejectingExecutor" 
+                 factoryClass="org.jboss.threads.JBossExecutors"/>
+  </bean>
+
+  <!-- Work Manager -->
+  <bean name="WorkManager" 
+        interface="org.jboss.jca.core.api.WorkManager" 
+        class="org.jboss.jca.core.workmanager.WorkManagerImpl">
+
+    <!-- The short running thread pool -->
+    <property name="ShortRunningThreadPool"><inject bean="ShortRunningThreadPool"/></property>
+
+    <!-- The long running thread pool -->
+    <property name="LongRunningThreadPool"><inject bean="LongRunningThreadPool"/></property>
+
+    <!-- The XA terminator -->
+    <property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
+  </bean>
+
+</deployment>

Modified: projects/jboss-jca/trunk/core/src/test/resources/workmanager-jboss-beans.xml
===================================================================
--- projects/jboss-jca/trunk/core/src/test/resources/workmanager-jboss-beans.xml	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/core/src/test/resources/workmanager-jboss-beans.xml	2010-02-09 16:01:38 UTC (rev 100758)
@@ -5,24 +5,57 @@
 -->
 <deployment>
 
-  <bean name="WorkManagerThreadPool" interface="org.jboss.jca.common.api.ThreadPool" class="org.jboss.jca.common.threadpool.ThreadPoolImpl">
-    <!-- The name that appears in thread names -->
-    <property name="name">WorkManager</property>
+  <!-- Thread group -->
+  <bean name="ThreadGroup"
+        class="java.lang.ThreadGroup">
+    <constructor>
+      <parameter>workmanager</parameter>
+    </constructor>
+    <ignoreStop/>
+    <ignoreDestroy/>
+  </bean>
 
-    <!-- The maximum amount of work in the queue -->
-    <property name="maximumQueueSize">1024</property>
-    
-    <!-- The maximum number of active threads -->
-    <property name="maximumPoolSize">100</property>
-    
-    <!-- How long to keep threads alive after their last work (default one minute) -->
-    <property name="keepAliveTime">60000</property>
+  <!-- Thread factory -->
+  <bean name="ThreadFactory"
+        interface="java.util.concurrent.ThreadFactory"
+        class="org.jboss.threads.JBossThreadFactory">
+    <constructor>
+      <parameter><inject bean="ThreadGroup"/></parameter>
+      <parameter>false</parameter>
+      <parameter>5</parameter>
+      <parameter>work</parameter>
+      <parameter><null/></parameter>
+      <parameter><null/></parameter>
+    </constructor>
   </bean>
 
-  <bean name="WorkManager" interface="org.jboss.jca.core.api.WorkManager" class="org.jboss.jca.core.workmanager.WorkManagerImpl">
-    <!-- The thread pool -->
-    <property name="threadPool"><inject bean="WorkManagerThreadPool"/></property>
+  <!-- Short running thread pool -->
+  <bean name="ShortRunningThreadPool">
+    <constructor factoryMethod="threadFactoryExecutor" 
+                 factoryClass="org.jboss.threads.JBossExecutors">
+      <parameter><inject bean="ThreadFactory"/></parameter>
+    </constructor>
+  </bean>
 
+  <!-- Long running thread pool -->
+  <bean name="LongRunningThreadPool">
+    <constructor factoryMethod="threadFactoryExecutor" 
+                 factoryClass="org.jboss.threads.JBossExecutors">
+      <parameter><inject bean="ThreadFactory"/></parameter>
+    </constructor>
+  </bean>
+
+  <!-- Work Manager -->
+  <bean name="WorkManager" 
+        interface="org.jboss.jca.core.api.WorkManager" 
+        class="org.jboss.jca.core.workmanager.WorkManagerImpl">
+
+    <!-- The short running thread pool -->
+    <property name="ShortRunningThreadPool"><inject bean="ShortRunningThreadPool"/></property>
+
+    <!-- The long running thread pool -->
+    <property name="LongRunningThreadPool"><inject bean="LongRunningThreadPool"/></property>
+
     <!-- The XA terminator -->
     <property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
   </bean>

Modified: projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml
===================================================================
--- projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml	2010-02-09 16:01:38 UTC (rev 100758)
@@ -5,26 +5,54 @@
     <depends>NamingServer</depends>
   </bean>
 
-  <!-- Work Manager thread pool -->
-  <bean name="WorkManagerThreadPool" interface="org.jboss.jca.common.threadpool.ThreadPool" class="org.jboss.jca.common.threadpool.ThreadPoolImpl">
-    <!-- The name that appears in thread names -->
-    <property name="name">WorkManager</property>
+  <!-- Thread group -->
+  <bean name="ThreadGroup"
+        class="java.lang.ThreadGroup">
+    <constructor>
+      <parameter>workmanager</parameter>
+    </constructor>
+    <ignoreStop/>
+    <ignoreDestroy/>
+  </bean>
 
-    <!-- The maximum amount of work in the queue -->
-    <property name="maximumQueueSize">1024</property>
-    
-    <!-- The maximum number of active threads -->
-    <property name="maximumPoolSize">100</property>
-    
-    <!-- How long to keep threads alive after their last work (default one minute) -->
-    <property name="keepAliveTime">60000</property>
+  <!-- Thread factory -->
+  <bean name="ThreadFactory"
+        interface="java.util.concurrent.ThreadFactory"
+        class="org.jboss.threads.JBossThreadFactory">
+    <constructor>
+      <parameter><inject bean="ThreadGroup"/></parameter>
+      <parameter>false</parameter>
+      <parameter>5</parameter>
+      <parameter>work</parameter>
+      <parameter><null/></parameter>
+      <parameter><null/></parameter>
+    </constructor>
   </bean>
 
+  <!-- Short running thread pool -->
+  <bean name="ShortRunningThreadPool">
+    <constructor factoryMethod="threadFactoryExecutor" 
+                 factoryClass="org.jboss.threads.JBossExecutors">
+      <parameter><inject bean="ThreadFactory"/></parameter>
+    </constructor>
+  </bean>
+
+  <!-- Long running thread pool -->
+  <bean name="LongRunningThreadPool">
+    <constructor factoryMethod="threadFactoryExecutor" 
+                 factoryClass="org.jboss.threads.JBossExecutors">
+      <parameter><inject bean="ThreadFactory"/></parameter>
+    </constructor>
+  </bean>
+
   <!-- Work Manager -->
   <bean name="WorkManager" interface="org.jboss.jca.core.api.WorkManager" class="org.jboss.jca.core.workmanager.WorkManagerImpl">
-    <!-- The thread pool -->
-    <property name="threadPool"><inject bean="WorkManagerThreadPool"/></property>
+    <!-- The short running thread pool -->
+    <property name="ShortRunningThreadPool"><inject bean="ShortRunningThreadPool"/></property>
 
+    <!-- The long running thread pool -->
+    <property name="LongRunningThreadPool"><inject bean="LongRunningThreadPool"/></property>
+
     <!-- The XA terminator -->
     <property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
   </bean>

Modified: projects/jboss-jca/trunk/ivy.xml
===================================================================
--- projects/jboss-jca/trunk/ivy.xml	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/ivy.xml	2010-02-09 16:01:38 UTC (rev 100758)
@@ -89,13 +89,15 @@
     <dependency org="org.jboss.microcontainer" name="jboss-kernel" rev="${version.jboss.mc.kernel}" conf="standalone->default"/>
     <dependency org="org.jboss.naming" name="jnpserver" rev="${version.jboss.naming}" conf="standalone->default;sjc->*"/>
     <dependency org="org.jboss.papaki" name="papaki-core" rev="${version.jboss.papaki}" conf="standalone->default;sjc->*"/>
+    <dependency org="org.jboss.security" name="jboss-security-spi-bare" rev="${version.jboss.security}" conf="standalone->default;sjc->*"/>
     <dependency org="org.jboss.shrinkwrap" name="shrinkwrap-api" rev="${version.jboss.shrinkwrap}" conf="standalone->default;sjc->*"/>
     <dependency org="org.jboss.shrinkwrap" name="shrinkwrap-impl-base" rev="${version.jboss.shrinkwrap}" conf="standalone->default;sjc->*"/>
     <dependency org="org.jboss.shrinkwrap" name="shrinkwrap-spi" rev="${version.jboss.shrinkwrap}" conf="standalone->default;sjc->*"/>
     <dependency org="org.jboss.slf4j" name="slf4j-jboss-logging" rev="${version.jboss.slf4j}" conf="standalone->default;sjc->*"/>
-    <dependency org="org.jboss.security" name="jboss-security-spi-bare" rev="${version.jboss.security}" conf="standalone->default;sjc->*"/>
     <dependency org="org.jboss.slf4j" name="slf4j-jboss-logmanager" rev="${version.jboss.slf4j.logmanager}" conf="standalone->default;sjc->*"/>
     <dependency org="org.jboss.stdio" name="jboss-stdio" rev="${version.jboss.stdio}" conf="standalone->default;sjc->*"/>
+    <dependency org="org.jboss.threads" name="jboss-threads" rev="${version.jboss.threads}" conf="standalone->default;sjc->*"/>
+    <dependency org="org.jboss.threads" name="jboss-threads-metadata" rev="${version.jboss.threads}" conf="standalone->default"/>
     <dependency org="org.mortbay.jetty" name="jetty" rev="${version.jetty}" conf="standalone->default;sjc->*"/>
     <dependency org="org.mortbay.jetty" name="jetty-util" rev="${version.jetty}" conf="standalone->default;sjc->*"/>
     <dependency org="org.mortbay.jetty" name="servlet-api-2.5" rev="${version.jetty.servlet}" conf="standalone->default;sjc->*"/>

Modified: projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml	2010-02-09 15:58:46 UTC (rev 100757)
+++ projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml	2010-02-09 16:01:38 UTC (rev 100758)
@@ -5,26 +5,54 @@
     <depends>NamingServer</depends>
   </bean>
 
-  <!-- Work Manager thread pool -->
-  <bean name="WorkManagerThreadPool" interface="org.jboss.jca.common.threadpool.ThreadPool" class="org.jboss.jca.common.threadpool.ThreadPoolImpl">
-    <!-- The name that appears in thread names -->
-    <property name="name">WorkManager</property>
+  <!-- Thread group -->
+  <bean name="ThreadGroup"
+        class="java.lang.ThreadGroup">
+    <constructor>
+      <parameter>workmanager</parameter>
+    </constructor>
+    <ignoreStop/>
+    <ignoreDestroy/>
+  </bean>
 
-    <!-- The maximum amount of work in the queue -->
-    <property name="maximumQueueSize">1024</property>
-    
-    <!-- The maximum number of active threads -->
-    <property name="maximumPoolSize">100</property>
-    
-    <!-- How long to keep threads alive after their last work (default one minute) -->
-    <property name="keepAliveTime">60000</property>
+  <!-- Thread factory -->
+  <bean name="ThreadFactory"
+        interface="java.util.concurrent.ThreadFactory"
+        class="org.jboss.threads.JBossThreadFactory">
+    <constructor>
+      <parameter><inject bean="ThreadGroup"/></parameter>
+      <parameter>false</parameter>
+      <parameter>5</parameter>
+      <parameter>work</parameter>
+      <parameter><null/></parameter>
+      <parameter><null/></parameter>
+    </constructor>
   </bean>
 
+  <!-- Short running thread pool -->
+  <bean name="ShortRunningThreadPool">
+    <constructor factoryMethod="threadFactoryExecutor" 
+                 factoryClass="org.jboss.threads.JBossExecutors">
+      <parameter><inject bean="ThreadFactory"/></parameter>
+    </constructor>
+  </bean>
+
+  <!-- Long running thread pool -->
+  <bean name="LongRunningThreadPool">
+    <constructor factoryMethod="threadFactoryExecutor" 
+                 factoryClass="org.jboss.threads.JBossExecutors">
+      <parameter><inject bean="ThreadFactory"/></parameter>
+    </constructor>
+  </bean>
+
   <!-- Work Manager -->
   <bean name="WorkManager" interface="org.jboss.jca.core.api.WorkManager" class="org.jboss.jca.core.workmanager.WorkManagerImpl">
-    <!-- The thread pool -->
-    <property name="threadPool"><inject bean="WorkManagerThreadPool"/></property>
+    <!-- The short running thread pool -->
+    <property name="ShortRunningThreadPool"><inject bean="ShortRunningThreadPool"/></property>
 
+    <!-- The long running thread pool -->
+    <property name="LongRunningThreadPool"><inject bean="LongRunningThreadPool"/></property>
+
     <!-- The XA terminator -->
     <property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
   </bean>




More information about the jboss-cvs-commits mailing list