djencks 2004/07/06 10:15:54
Modified: modules/connector/src/java/org/apache/geronimo/connector/work GeronimoWorkManager.java WorkerContext.java modules/connector/src/java/org/apache/geronimo/connector/work/pool WorkExecutorPool.java modules/connector/src/test/org/apache/geronimo/connector/work PooledWorkManagerTest.java Added: modules/connector/src/java/org/apache/geronimo/connector/work/pool NullWorkExecutorPool.java ScheduleWorkExecutor.java StartWorkExecutor.java SyncWorkExecutor.java WorkExecutor.java WorkExecutorPoolImpl.java Removed: modules/connector/src/java/org/apache/geronimo/connector/work/pool AbstractWorkExecutorPool.java ScheduleWorkExecutorPool.java StartWorkExecutorPool.java SyncWorkExecutorPool.java Log: Simplify and make the WorkManager work Revision Changes Path 1.8 +77 -56 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java Index: GeronimoWorkManager.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- GeronimoWorkManager.java 2 Jun 2004 05:33:02 -0000 1.7 +++ GeronimoWorkManager.java 6 Jul 2004 17:15:54 -0000 1.8 @@ -19,16 +19,22 @@ import javax.resource.spi.work.ExecutionContext; import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkCompletedException; import javax.resource.spi.work.WorkException; import javax.resource.spi.work.WorkListener; import javax.resource.spi.work.WorkManager; -import org.apache.geronimo.connector.work.pool.ScheduleWorkExecutorPool; -import org.apache.geronimo.connector.work.pool.StartWorkExecutorPool; -import org.apache.geronimo.connector.work.pool.SyncWorkExecutorPool; +import EDU.oswego.cs.dl.util.concurrent.Executor; +import org.apache.geronimo.connector.work.pool.NullWorkExecutorPool; +import org.apache.geronimo.connector.work.pool.ScheduleWorkExecutor; +import org.apache.geronimo.connector.work.pool.StartWorkExecutor; +import org.apache.geronimo.connector.work.pool.SyncWorkExecutor; +import org.apache.geronimo.connector.work.pool.WorkExecutor; import org.apache.geronimo.connector.work.pool.WorkExecutorPool; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoFactory; +import org.apache.geronimo.gbean.GBeanLifecycle; +import org.apache.geronimo.gbean.WaitingException; import org.apache.geronimo.transaction.XAWork; /** @@ -39,70 +45,82 @@ * A WorkManager is a component of the JCA specifications, which allows a * Resource Adapter to submit tasks to an Application Server for execution. * - * TODO There needs to be better lifecycle support. The individual pools can be stopped now, but - * not restarted AFAIK. - * * @version $Revision$ $Date$ */ -public class GeronimoWorkManager implements WorkManager { +public class GeronimoWorkManager implements WorkManager, GBeanLifecycle { - private final static int DEFAULT_MIN_POOL_SIZE = 0; - private final static int DEFAULT_MAX_POOL_SIZE = 10; + private final static int DEFAULT_POOL_SIZE = 10; /** * Pool of threads used by this WorkManager in order to process * the Work instances submitted via the doWork methods. */ - private final WorkExecutorPool syncWorkExecutorPool; + private WorkExecutorPool syncWorkExecutorPool; /** * Pool of threads used by this WorkManager in order to process * the Work instances submitted via the startWork methods. */ - private final WorkExecutorPool startWorkExecutorPool; + private WorkExecutorPool startWorkExecutorPool; /** * Pool of threads used by this WorkManager in order to process * the Work instances submitted via the scheduleWork methods. */ - private final WorkExecutorPool scheduledWorkExecutorPool; + private WorkExecutorPool scheduledWorkExecutorPool; private final XAWork xaWork; + private final WorkExecutor scheduleWorkExecutor = new ScheduleWorkExecutor(); + private final WorkExecutor startWorkExecutor = new StartWorkExecutor(); + private final WorkExecutor syncWorkExecutor = new SyncWorkExecutor(); + /** * Create a WorkManager. */ public GeronimoWorkManager() { - this(DEFAULT_MIN_POOL_SIZE, DEFAULT_MAX_POOL_SIZE, null); + this(DEFAULT_POOL_SIZE, null); } - public GeronimoWorkManager(int minSize, int maxSize, XAWork xaWork) { - this(minSize, maxSize, minSize, maxSize, minSize, maxSize, xaWork); + public GeronimoWorkManager(int size, XAWork xaWork) { + this(size, size, size, xaWork); } - public GeronimoWorkManager(int syncMinSize, int syncMaxSize, int startMinSize, int startMaxSize, int schedMinSize, int schedMaxSize, XAWork xaWork) { - syncWorkExecutorPool = new SyncWorkExecutorPool(syncMinSize, syncMaxSize); - startWorkExecutorPool = new StartWorkExecutorPool(startMinSize, startMaxSize); - scheduledWorkExecutorPool = new ScheduleWorkExecutorPool(schedMinSize, schedMaxSize); + public GeronimoWorkManager(int syncSize, int startSize, int schedSize, XAWork xaWork) { + syncWorkExecutorPool = new NullWorkExecutorPool(syncSize); + startWorkExecutorPool = new NullWorkExecutorPool(startSize); + scheduledWorkExecutorPool = new NullWorkExecutorPool(schedSize); this.xaWork = xaWork; } - public int getSyncThreadCount() { - return syncWorkExecutorPool.getPoolSize(); + public void doStart() throws WaitingException, Exception { + syncWorkExecutorPool = syncWorkExecutorPool.start(); + startWorkExecutorPool = startWorkExecutorPool.start(); + scheduledWorkExecutorPool = scheduledWorkExecutorPool.start(); + } + + public void doStop() throws WaitingException, Exception { + syncWorkExecutorPool = syncWorkExecutorPool.stop(); + startWorkExecutorPool = startWorkExecutorPool.stop(); + scheduledWorkExecutorPool = scheduledWorkExecutorPool.stop(); + } + + public void doFail() { + try { + doStop(); + } catch (Exception e) { + //TODO what to do? + } } - public int getSyncMinimumPoolSize() { - return syncWorkExecutorPool.getMinimumPoolSize(); + public int getSyncThreadCount() { + return syncWorkExecutorPool.getPoolSize(); } public int getSyncMaximumPoolSize() { return syncWorkExecutorPool.getMaximumPoolSize(); } - public void setSyncMinimumPoolSize(int minSize) { - syncWorkExecutorPool.setMinimumPoolSize(minSize); - } - public void setSyncMaximumPoolSize(int maxSize) { syncWorkExecutorPool.setMaximumPoolSize(maxSize); } @@ -111,18 +129,10 @@ return startWorkExecutorPool.getPoolSize(); } - public int getStartMinimumPoolSize() { - return startWorkExecutorPool.getMinimumPoolSize(); - } - public int getStartMaximumPoolSize() { return startWorkExecutorPool.getMaximumPoolSize(); } - public void setStartMinimumPoolSize(int minSize) { - startWorkExecutorPool.setMinimumPoolSize(minSize); - } - public void setStartMaximumPoolSize(int maxSize) { startWorkExecutorPool.setMaximumPoolSize(maxSize); } @@ -131,18 +141,10 @@ return scheduledWorkExecutorPool.getPoolSize(); } - public int getScheduledMinimumPoolSize() { - return scheduledWorkExecutorPool.getMinimumPoolSize(); - } - public int getScheduledMaximumPoolSize() { return scheduledWorkExecutorPool.getMaximumPoolSize(); } - public void setScheduledMinimumPoolSize(int minSize) { - scheduledWorkExecutorPool.setMinimumPoolSize(minSize); - } - public void setScheduledMaximumPoolSize(int maxSize) { scheduledWorkExecutorPool.setMaximumPoolSize(maxSize); } @@ -151,7 +153,7 @@ * @see javax.resource.spi.work.WorkManager#doWork(javax.resource.spi.work.Work) */ public void doWork(Work work) throws WorkException { - syncWorkExecutorPool.executeWork(new WorkerContext(work)); + executeWork(new WorkerContext(work), syncWorkExecutor, syncWorkExecutorPool); } /* (non-Javadoc) @@ -166,7 +168,7 @@ WorkerContext workWrapper = new WorkerContext(work, startTimeout, execContext, xaWork, workListener); workWrapper.setThreadPriority(Thread.currentThread().getPriority()); - syncWorkExecutorPool.executeWork(workWrapper); + executeWork(workWrapper, syncWorkExecutor, syncWorkExecutorPool); } /* (non-Javadoc) @@ -175,7 +177,7 @@ public long startWork(Work work) throws WorkException { WorkerContext workWrapper = new WorkerContext(work); workWrapper.setThreadPriority(Thread.currentThread().getPriority()); - startWorkExecutorPool.executeWork(workWrapper); + executeWork(workWrapper, startWorkExecutor, startWorkExecutorPool); return System.currentTimeMillis() - workWrapper.getAcceptedTime(); } @@ -191,7 +193,7 @@ WorkerContext workWrapper = new WorkerContext(work, startTimeout, execContext, xaWork, workListener); workWrapper.setThreadPriority(Thread.currentThread().getPriority()); - startWorkExecutorPool.executeWork(workWrapper); + executeWork(workWrapper, startWorkExecutor, startWorkExecutorPool); return System.currentTimeMillis() - workWrapper.getAcceptedTime(); } @@ -201,7 +203,7 @@ public void scheduleWork(Work work) throws WorkException { WorkerContext workWrapper = new WorkerContext(work); workWrapper.setThreadPriority(Thread.currentThread().getPriority()); - scheduledWorkExecutorPool.executeWork(workWrapper); + executeWork(workWrapper, scheduleWorkExecutor, scheduledWorkExecutorPool); } /* (non-Javadoc) @@ -216,7 +218,31 @@ WorkerContext workWrapper = new WorkerContext(work, startTimeout, execContext, xaWork, workListener); workWrapper.setThreadPriority(Thread.currentThread().getPriority()); - scheduledWorkExecutorPool.executeWork(workWrapper); + executeWork(workWrapper, scheduleWorkExecutor, scheduledWorkExecutorPool); + } + + /** + * Execute the specified Work. + * + * @param work Work to be executed. + * + * @exception WorkException Indicates that the Work execution has been + * unsuccessful. + */ + private void executeWork(WorkerContext work, WorkExecutor workExecutor, Executor pooledExecutor) throws WorkException { + work.workAccepted(this); + try { + workExecutor.doExecute(work, pooledExecutor); + WorkException exception = work.getWorkException(); + if (null != exception) { + throw exception; + } + } catch (InterruptedException e) { + WorkCompletedException wcj = new WorkCompletedException( + "The execution has been interrupted.", e); + wcj.setErrorCode(WorkException.INTERNAL); + throw wcj; + } } public static final GBeanInfo GBEAN_INFO; @@ -225,21 +251,15 @@ GBeanInfoFactory infoFactory = new GBeanInfoFactory(GeronimoWorkManager.class); infoFactory.addInterface(WorkManager.class); - infoFactory.addAttribute("SyncMinimumPoolSize", Integer.TYPE, true); infoFactory.addAttribute("SyncMaximumPoolSize", Integer.TYPE, true); - infoFactory.addAttribute("StartMinimumPoolSize", Integer.TYPE, true); infoFactory.addAttribute("StartMaximumPoolSize", Integer.TYPE, true); - infoFactory.addAttribute("ScheduledMinimumPoolSize", Integer.TYPE, true); infoFactory.addAttribute("ScheduledMaximumPoolSize", Integer.TYPE, true); infoFactory.addReference("XAWork", XAWork.class); infoFactory.setConstructor(new String[]{ - "SyncMinimumPoolSize", "SyncMaximumPoolSize", - "StartMinimumPoolSize", "StartMaximumPoolSize", - "ScheduledMinimumPoolSize", "ScheduledMaximumPoolSize", "XAWork"}); @@ -249,5 +269,6 @@ public static GBeanInfo getGBeanInfo() { return GBEAN_INFO; } + } 1.7 +5 -3 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/WorkerContext.java Index: WorkerContext.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/WorkerContext.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WorkerContext.java 30 May 2004 19:03:36 -0000 1.6 +++ WorkerContext.java 6 Jul 2004 17:15:54 -0000 1.7 @@ -25,6 +25,7 @@ import javax.resource.spi.work.WorkException; import javax.resource.spi.work.WorkListener; import javax.resource.spi.work.WorkRejectedException; +import javax.resource.spi.work.WorkManager; import EDU.oswego.cs.dl.util.concurrent.Latch; import org.apache.commons.logging.Log; @@ -214,10 +215,11 @@ public synchronized boolean isTimedOut() { assert isAccepted: "The work is not accepted."; // A value of 0 means that the work never times out. - if (0 == startTimeOut) { + //??? really? + if (0 == startTimeOut || startTimeOut == WorkManager.INDEFINITE) { return false; } - boolean isTimeout = + boolean isTimeout = acceptedTime + startTimeOut > 0 && System.currentTimeMillis() > acceptedTime + startTimeOut; if (log.isDebugEnabled()) { log.debug( 1.4 +9 -29 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/pool/WorkExecutorPool.java Index: WorkExecutorPool.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/pool/WorkExecutorPool.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WorkExecutorPool.java 10 Mar 2004 09:58:33 -0000 1.3 +++ WorkExecutorPool.java 6 Jul 2004 17:15:54 -0000 1.4 @@ -20,6 +20,7 @@ import javax.resource.spi.work.WorkException; import org.apache.geronimo.connector.work.WorkerContext; +import EDU.oswego.cs.dl.util.concurrent.Executor; /** * Defines the operations that a pool in charge of the execution of Work @@ -27,18 +28,7 @@ * * @version $Revision$ $Date$ */ -public interface WorkExecutorPool { - - /** - * Executes the specified work. The execution policy (synchronous vs. - * asynchronous) is implementation specific. - * - * @param aWork Work to be executed. - * - * @throws WorkException Indicates that the Work instance can not be - * executed or that its execution has thrown an exception. - */ - public void executeWork(WorkerContext aWork) throws WorkException; +public interface WorkExecutorPool extends Executor { /** * Gets the current number of active threads in the pool. @@ -48,31 +38,21 @@ public int getPoolSize(); /** - * Gets the minimum number of threads to simultaneously execute. - * - * @return Minimum size. - */ - public int getMinimumPoolSize(); - - /** - * Sets the minimum number of threads to simultaneously execute. - * - * @param aSize Minimum size. - */ - public void setMinimumPoolSize(int aSize); - - /** * Gets the maximum number of threads to simultaneously execute. * - * @return Maximim size. + * @return Maximum size. */ public int getMaximumPoolSize(); /** * Sets the maximum number of threads to simultaneously execute. * - * @param Maximum size. + * @param aSize Maximum size. */ public void setMaximumPoolSize(int aSize); + + public WorkExecutorPool start(); + + public WorkExecutorPool stop(); } 1.1 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/pool/NullWorkExecutorPool.java Index: NullWorkExecutorPool.java =================================================================== /** * * Copyright 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.geronimo.connector.work.pool; /** * * * @version $Revision: 1.1 $ $Date: 2004/07/06 17:15:54 $ * * */ public class NullWorkExecutorPool implements WorkExecutorPool { private int maxSize; public NullWorkExecutorPool(int maxSize) { this.maxSize = maxSize; } public int getPoolSize() { return 0; } public int getMaximumPoolSize() { return maxSize; } public void setMaximumPoolSize(int maxSize) { this.maxSize = maxSize; } public WorkExecutorPool start() { return new WorkExecutorPoolImpl(maxSize); } public WorkExecutorPool stop() { return this; } public void execute(Runnable command) throws InterruptedException { throw new IllegalStateException("Stopped"); } } 1.1 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/pool/ScheduleWorkExecutor.java Index: ScheduleWorkExecutor.java =================================================================== /** * * Copyright 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.geronimo.connector.work.pool; import javax.resource.spi.work.WorkException; import org.apache.geronimo.connector.work.WorkerContext; import EDU.oswego.cs.dl.util.concurrent.Executor; /** * * * @version $Revision: 1.1 $ $Date: 2004/07/06 17:15:54 $ * * */ public class ScheduleWorkExecutor implements WorkExecutor { public void doExecute(WorkerContext work, Executor executor) throws WorkException, InterruptedException { executor.execute(work); } } 1.1 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/pool/StartWorkExecutor.java Index: StartWorkExecutor.java =================================================================== /** * * Copyright 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.geronimo.connector.work.pool; import javax.resource.spi.work.WorkException; import org.apache.geronimo.connector.work.WorkerContext; import EDU.oswego.cs.dl.util.concurrent.Executor; import EDU.oswego.cs.dl.util.concurrent.Latch; /** * * * @version $Revision: 1.1 $ $Date: 2004/07/06 17:15:54 $ * * */ public class StartWorkExecutor implements WorkExecutor { public void doExecute(WorkerContext work, Executor executor) throws WorkException, InterruptedException { Latch latch = work.provideStartLatch(); executor.execute(work); latch.acquire(); } } 1.1 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/pool/SyncWorkExecutor.java Index: SyncWorkExecutor.java =================================================================== /** * * Copyright 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.geronimo.connector.work.pool; import javax.resource.spi.work.WorkException; import org.apache.geronimo.connector.work.WorkerContext; import EDU.oswego.cs.dl.util.concurrent.Executor; import EDU.oswego.cs.dl.util.concurrent.Latch; /** * * * @version $Revision: 1.1 $ $Date: 2004/07/06 17:15:54 $ * * */ public class SyncWorkExecutor implements WorkExecutor { public void doExecute(WorkerContext work, Executor executor) throws WorkException, InterruptedException { Latch latch = work.provideEndLatch(); executor.execute(work); latch.acquire(); } } 1.1 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/pool/WorkExecutor.java Index: WorkExecutor.java =================================================================== package org.apache.geronimo.connector.work.pool; import javax.resource.spi.work.WorkException; import org.apache.geronimo.connector.work.WorkerContext; import EDU.oswego.cs.dl.util.concurrent.Executor; /** * * * @version $Revision: 1.1 $ $Date: 2004/07/06 17:15:54 $ * * */ public interface WorkExecutor { /** * This method must be implemented by sub-classes in order to provide the * relevant synchronization policy. It is called by the executeWork template * method. * * @param work Work to be executed. * * @throws javax.resource.spi.work.WorkException Indicates that the work has failed. * @throws InterruptedException Indicates that the thread in charge of the * execution of the specified work has been interrupted. */ void doExecute(WorkerContext work, Executor executor) throws WorkException, InterruptedException; } 1.1 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/work/pool/WorkExecutorPoolImpl.java Index: WorkExecutorPoolImpl.java =================================================================== /** * * Copyright 2003-2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.geronimo.connector.work.pool; import javax.resource.spi.work.WorkCompletedException; import javax.resource.spi.work.WorkException; import EDU.oswego.cs.dl.util.concurrent.Channel; import EDU.oswego.cs.dl.util.concurrent.PooledExecutor; import EDU.oswego.cs.dl.util.concurrent.LinkedQueue; import org.apache.geronimo.connector.work.WorkerContext; /** * Based class for WorkExecutorPool. Sub-classes define the synchronization * policy (should the call block until the end of the work; or when it starts * et cetera). * * @version $Revision: 1.1 $ $Date: 2004/07/06 17:15:54 $ */ public class WorkExecutorPoolImpl implements WorkExecutorPool { /** * A timed out pooled executor. */ private PooledExecutor pooledExecutor; /** * Creates a pool with the specified minimum and maximum sizes. The Channel * used to enqueue the submitted Work instances is queueless synchronous * one. * * @param maxSize Maximum size of the work executor pool. */ public WorkExecutorPoolImpl(int maxSize) { pooledExecutor = new PooledExecutor(new LinkedQueue(), maxSize); pooledExecutor.setMinimumPoolSize(maxSize); pooledExecutor.waitWhenBlocked(); } /** * Creates a pool with the specified minimum and maximum sizes and using the * specified Channel to enqueue the submitted Work instances. * * @param channel Queue to be used as the queueing facility of this pool. * @param maxSize Maximum size of the work executor pool. */ public WorkExecutorPoolImpl( Channel channel, int maxSize) { pooledExecutor = new PooledExecutor(channel, maxSize); pooledExecutor.setMinimumPoolSize(maxSize); pooledExecutor.waitWhenBlocked(); } /** * Execute the specified Work. * * @param work Work to be executed. * * @exception InterruptedException Indicates that the Work execution has been * unsuccessful. */ public void execute(Runnable work) throws InterruptedException { pooledExecutor.execute(work); } /** * Gets the size of this pool. */ public int getPoolSize() { return pooledExecutor.getPoolSize(); } /** * Gets the maximum size of this pool. */ public int getMaximumPoolSize() { return pooledExecutor.getMaximumPoolSize(); } /** * Sets the maximum size of this pool. * @param maxSize New maximum size of this pool. */ public void setMaximumPoolSize(int maxSize) { pooledExecutor.setMaximumPoolSize(maxSize); } public WorkExecutorPool start() { throw new IllegalStateException("This pooled executor is already started"); } /** * Stops this pool. Prior to stop this pool, all the enqueued Work instances * are processed. This is an orderly shutdown. */ public WorkExecutorPool stop() { int maxSize = getMaximumPoolSize(); pooledExecutor.shutdownAfterProcessingCurrentlyQueuedTasks(); return new NullWorkExecutorPool(maxSize); } } 1.7 +17 -5 incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/work/PooledWorkManagerTest.java Index: PooledWorkManagerTest.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/work/PooledWorkManagerTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PooledWorkManagerTest.java 17 May 2004 13:48:13 -0000 1.6 +++ PooledWorkManagerTest.java 6 Jul 2004 17:15:54 -0000 1.7 @@ -37,9 +37,10 @@ private GeronimoWorkManager workManager; protected void setUp() throws Exception { - workManager = new GeronimoWorkManager(1, 1, null); + workManager = new GeronimoWorkManager(1, null); + workManager.doStart(); } - + public void testDoWork() throws Exception { int nbThreads = 2; AbstractDummyWork threads[] = @@ -102,6 +103,13 @@ nbAccepted > 0); } + public void testLifecycle() throws Exception { + testDoWork(); + workManager.doStop(); + workManager.doStart(); + testDoWork(); + } + private AbstractDummyWork[] helperTest(Class aWork, int nbThreads, int aTimeOut, int aTempo) throws Exception { @@ -191,7 +199,7 @@ public static class DummyWork implements Work { private final String name; private final int tempo; - + public DummyWork(String aName, int aTempo) { name = aName; tempo = aTempo; @@ -218,21 +226,25 @@ public WorkEvent rejectedEvent; public WorkEvent startedEvent; public WorkEvent completedEvent; - + public void workAccepted(WorkEvent e) { acceptedEvent = e; + System.out.println("accepted" + e); } public void workRejected(WorkEvent e) { rejectedEvent = e; + System.out.println("rejected" + e); } public void workStarted(WorkEvent e) { startedEvent = e; + System.out.println("started" + e); } public void workCompleted(WorkEvent e) { completedEvent = e; + System.out.println("completed" + e); } } }