djencks 2003/11/25 18:15:33
Modified: modules/core/src/java/org/apache/geronimo/connector/work
GeronimoWorkManager.java
modules/core/src/java/org/apache/geronimo/connector/work/pool
AbstractWorkExecutorPool.java
ScheduleWorkExecutorPool.java
StartWorkExecutorPool.java
SyncWorkExecutorPool.java
TimedOutPooledExecutor.java
modules/core/src/test/org/apache/geronimo/connector/work
PooledWorkManagerTest.java
Log:
Simplify the setup of a WorkManager instance, using some IOC ideas. There are
still lifecycle problems.
Revision Changes Path
1.4 +102 -130
incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java
Index: GeronimoWorkManager.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/GeronimoWorkManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GeronimoWorkManager.java 17 Nov 2003 00:46:09 -0000 1.3
+++ GeronimoWorkManager.java 26 Nov 2003 02:15:32 -0000 1.4
@@ -55,90 +55,136 @@
*/
package org.apache.geronimo.connector.work;
-import javax.management.MBeanOperationInfo;
import javax.resource.spi.work.ExecutionContext;
import javax.resource.spi.work.Work;
import javax.resource.spi.work.WorkException;
import javax.resource.spi.work.WorkListener;
import javax.resource.spi.work.WorkManager;
-import javax.resource.spi.work.WorkRejectedException;
-import org.apache.geronimo.common.Classes;
+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 org.apache.geronimo.connector.work.pool.WorkExecutorPool;
-import org.apache.geronimo.kernel.management.State;
-import org.apache.geronimo.kernel.service.GeronimoMBeanContext;
import org.apache.geronimo.kernel.service.GeronimoMBeanInfo;
-import org.apache.geronimo.kernel.service.GeronimoMBeanTarget;
-import org.apache.geronimo.kernel.service.GeronimoOperationInfo;
-import org.apache.geronimo.kernel.service.GeronimoParameterInfo;
+import org.apache.geronimo.kernel.service.GeronimoAttributeInfo;
/**
* WorkManager implementation which uses under the cover three
WorkExecutorPool
- * - one for each synchronization policy - in order to dispatch the
submitted
- * Work instances.
+ * - one for each synchronization policy - in order to dispatch the submitted
+ * Work instances.
* <P>
* A WorkManager is a component of the JCA specifications, which allows a
- * Resource Adapter to submit tasks to an Application Server for execution.
- *
+ * 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, GeronimoMBeanTarget
{
+public class GeronimoWorkManager implements WorkManager {
+
+ private final static int DEFAULT_MIN_POOL_SIZE = 0;
+ private final static int DEFAULT_MAX_POOL_SIZE = 10;
/**
* Pool of threads used by this WorkManager in order to process
- * the Work instances submitted via the doWork methods.
+ * the Work instances submitted via the doWork methods.
*/
- private WorkExecutorPool syncWorkExecutorPool;
+ private final WorkExecutorPool syncWorkExecutorPool;
/**
* Pool of threads used by this WorkManager in order to process
- * the Work instances submitted via the startWork methods.
+ * the Work instances submitted via the startWork methods.
*/
- private WorkExecutorPool startWorkExecutorPool;
-
+ private final WorkExecutorPool startWorkExecutorPool;
+
/**
* Pool of threads used by this WorkManager in order to process
* the Work instances submitted via the scheduleWork methods.
*/
- private WorkExecutorPool scheduledWorkExecutorPool;
- private GeronimoMBeanContext geronimoMBeanContext;
-
+ private final WorkExecutorPool scheduledWorkExecutorPool;
+
/**
- * Create a WorkManager.
+ * Create a WorkManager.
*/
public GeronimoWorkManager() {
+ this(DEFAULT_MIN_POOL_SIZE, DEFAULT_MAX_POOL_SIZE);
}
- /**
- * Set the executor in charge of the processing of synchronous works.
- * @param anExecutorPool An executor.
- */
- public void setSyncExecutor(WorkExecutorPool anExecutorPool) {
- syncWorkExecutorPool = anExecutorPool;
+ public GeronimoWorkManager(int minSize, int maxSize) {
+ this(minSize, maxSize, minSize, maxSize, minSize, maxSize);
}
- /**
- * Sets the executor in charge of the processing of synchronous until
start
- * works.
- * @param anExecutorPool An executor.
- */
- public void setStartExecutor(WorkExecutorPool anExecutorPool) {
- startWorkExecutorPool = anExecutorPool;
+ public GeronimoWorkManager(int syncMinSize, int syncMaxSize, int
startMinSize, int startMaxSize, int schedMinSize, int schedMaxSize) {
+ syncWorkExecutorPool = new SyncWorkExecutorPool(syncMinSize,
syncMaxSize);
+ startWorkExecutorPool = new StartWorkExecutorPool(startMinSize,
startMaxSize);
+ scheduledWorkExecutorPool = new
ScheduleWorkExecutorPool(schedMinSize, schedMaxSize);
}
-
- /**
- * Set the executor in charge of the processing of asynchronous works.
- * @param anExecutorPool An executor.
- */
- public void setAsyncExecutor(WorkExecutorPool anExecutorPool) {
- scheduledWorkExecutorPool = anExecutorPool;
+
+ public int getSyncThreadCount() {
+ return syncWorkExecutorPool.getPoolSize();
+ }
+
+ public int getSyncMinimumPoolSize() {
+ return syncWorkExecutorPool.getMinimumPoolSize();
+ }
+
+ public int getSyncMaximumPoolSize() {
+ return syncWorkExecutorPool.getMaximumPoolSize();
+ }
+
+ public void setSyncMinimumPoolSize(int minSize) {
+ syncWorkExecutorPool.setMinimumPoolSize(minSize);
+ }
+
+ public void setSyncMaximumPoolSize(int maxSize) {
+ syncWorkExecutorPool.setMaximumPoolSize(maxSize);
+ }
+
+ public int getStartThreadCount() {
+ 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);
+ }
+
+ public int getsSheduledThreadCount() {
+ 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);
+ }
+
/* (non-Javadoc)
* @see
javax.resource.spi.work.WorkManager#doWork(javax.resource.spi.work.Work)
*/
public void doWork(Work work) throws WorkException {
- checkStateBeforeAccept(syncWorkExecutorPool, "synchronous");
syncWorkExecutorPool.executeWork(new WorkerContext(work));
}
@@ -151,7 +197,6 @@
ExecutionContext execContext,
WorkListener workListener)
throws WorkException {
- checkStateBeforeAccept(syncWorkExecutorPool, "synchronous");
WorkerContext workWrapper =
new WorkerContext(work, startTimeout, execContext, workListener);
workWrapper.setThreadPriority(Thread.currentThread().getPriority());
@@ -162,8 +207,6 @@
* @see
javax.resource.spi.work.WorkManager#startWork(javax.resource.spi.work.Work)
*/
public long startWork(Work work) throws WorkException {
- checkStateBeforeAccept(startWorkExecutorPool,
- "synchronous until start");
WorkerContext workWrapper = new WorkerContext(work);
workWrapper.setThreadPriority(Thread.currentThread().getPriority());
startWorkExecutorPool.executeWork(workWrapper);
@@ -179,8 +222,6 @@
ExecutionContext execContext,
WorkListener workListener)
throws WorkException {
- checkStateBeforeAccept(startWorkExecutorPool,
- "synchronous until start");
WorkerContext workWrapper =
new WorkerContext(work, startTimeout, execContext, workListener);
workWrapper.setThreadPriority(Thread.currentThread().getPriority());
@@ -192,7 +233,6 @@
* @see
javax.resource.spi.work.WorkManager#scheduleWork(javax.resource.spi.work.Work)
*/
public void scheduleWork(Work work) throws WorkException {
- checkStateBeforeAccept(scheduledWorkExecutorPool, "asynchronous");
WorkerContext workWrapper = new WorkerContext(work);
workWrapper.setThreadPriority(Thread.currentThread().getPriority());
scheduledWorkExecutorPool.executeWork(workWrapper);
@@ -207,101 +247,33 @@
ExecutionContext execContext,
WorkListener workListener)
throws WorkException {
- checkStateBeforeAccept(scheduledWorkExecutorPool, "asynchronous");
WorkerContext workWrapper =
new WorkerContext(work, startTimeout, execContext, workListener);
workWrapper.setThreadPriority(Thread.currentThread().getPriority());
scheduledWorkExecutorPool.executeWork(workWrapper);
}
- /**
- * This helper method MUST be called prior to accept a Work instance. It
- * ensures that the state of this WorkManager is running and that the
- * provided work executor is defined.
- *
- * @param aPool Work executor, which will accept the Work instance.
- * @param aType "Label" of this work executor. It is only used to
- * create an more accurate message when the provided Work executor is not
- * defined (null).
- *
- * @throws WorkRejectedException Indicates that this WorkManager is not
- * running and hence that a work can not be accepted.
- */
- private void checkStateBeforeAccept(WorkExecutorPool aPool,
- String aType) throws WorkRejectedException {
- if ( !(State.RUNNING_INDEX == getState()) ) {
- throw new WorkRejectedException(getClass() + " is not running.",
- WorkException.INTERNAL);
- } else if ( null == aPool ) {
- throw new WorkRejectedException(getClass() + " is partially" +
- " running. Its " + aType + " work facilities are unmounted.",
- WorkException.INTERNAL);
- }
- }
-
-
- public int getState() throws WorkRejectedException {
- try {
- return geronimoMBeanContext.getState();
- } catch (Exception e) {
- throw new WorkRejectedException("WorkManager is not ready.",
WorkException.INTERNAL);
- }
- }
-
- /**
- * @see
org.apache.geronimo.kernel.service.GeronimoMBeanTarget#setMBeanContext(org.apache.geronimo.kernel.service.GeronimoMBeanContext)
- */
- public void setMBeanContext(GeronimoMBeanContext geronimoMBeanContext) {
- this.geronimoMBeanContext = geronimoMBeanContext;
- }
-
- /**
- * @see org.apache.geronimo.kernel.service.GeronimoMBeanTarget#canStart()
- */
- public boolean canStart() {
- return true;
- }
-
- /**
- * @see org.apache.geronimo.kernel.service.GeronimoMBeanTarget#doStart()
- */
- public void doStart() {
- }
/**
- * @see org.apache.geronimo.kernel.service.GeronimoMBeanTarget#canStop()
- */
- public boolean canStop() {
- return true;
- }
-
- /**
- * @see org.apache.geronimo.kernel.service.GeronimoMBeanTarget#doStop()
- */
- public void doStop() {
- }
-
- /**
- * @see org.apache.geronimo.kernel.service.GeronimoMBeanTarget#doFail()
- */
- public void doFail() {
- }
-
-
- /**
* Provides the GeronimoMBean description for this class
* @return
*/
public static GeronimoMBeanInfo getGeronimoMBeanInfo() throws Exception {
- // TODO: add descriptions to all operations.
GeronimoMBeanInfo rc = new GeronimoMBeanInfo();
rc.setTargetClass(GeronimoWorkManager.class);
- rc.addOperationFor( Classes.getMethod(GeronimoWorkManager.class,
"setSyncExecutor") );
- rc.addOperationFor( Classes.getMethod(GeronimoWorkManager.class,
"setStartExecutor") );
- rc.addOperationFor( Classes.getMethod(GeronimoWorkManager.class,
"setAsyncExecutor") );
+ rc.addOperationsDeclaredIn(WorkManager.class);
+ rc.addAttributeInfo(new GeronimoAttributeInfo("SyncThreadCount",
true, false, "Actual size of sync thread pool"));
+ rc.addAttributeInfo(new GeronimoAttributeInfo("SyncMinimumPoolSize",
true, true, "Minimum size of sync thread pool"));
+ rc.addAttributeInfo(new GeronimoAttributeInfo("SyncMaximumPoolSize",
true, true, "Maximum size of sync thread pool"));
+ rc.addAttributeInfo(new GeronimoAttributeInfo("StartThreadCount",
true, false, "Actual size of sync thread pool"));
+ rc.addAttributeInfo(new
GeronimoAttributeInfo("StartMinimumPoolSize", true, true, "Minimum size of sync
thread pool"));
+ rc.addAttributeInfo(new
GeronimoAttributeInfo("StartMaximumPoolSize", true, true, "Maximum size of sync
thread pool"));
+ rc.addAttributeInfo(new
GeronimoAttributeInfo("ScheduledThreadCount", true, false, "Actual size of sync
thread pool"));
+ rc.addAttributeInfo(new
GeronimoAttributeInfo("ScheduledMinimumPoolSize", true, true, "Minimum size of
sync thread pool"));
+ rc.addAttributeInfo(new
GeronimoAttributeInfo("ScheduledMaximumPoolSize", true, true, "Maximum size of
sync thread pool"));
return rc;
}
-
+
}
1.3 +45 -46
incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/pool/AbstractWorkExecutorPool.java
Index: AbstractWorkExecutorPool.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/pool/AbstractWorkExecutorPool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractWorkExecutorPool.java 16 Nov 2003 23:12:07 -0000 1.2
+++ AbstractWorkExecutorPool.java 26 Nov 2003 02:15:32 -0000 1.3
@@ -59,11 +59,10 @@
import javax.resource.spi.work.WorkCompletedException;
import javax.resource.spi.work.WorkException;
+import EDU.oswego.cs.dl.util.concurrent.Channel;
+import org.apache.geronimo.connector.work.WorkerContext;
import org.apache.geronimo.kernel.service.GeronimoAttributeInfo;
import org.apache.geronimo.kernel.service.GeronimoMBeanInfo;
-import org.apache.geronimo.connector.work.WorkerContext;
-
-import EDU.oswego.cs.dl.util.concurrent.Channel;
/**
* Based class for WorkExecutorPool. Sub-classes define the synchronization
@@ -72,7 +71,7 @@
*
* @jmx:mbean
*
extends="org.apache.geronimo.kernel.management.StateManageable,org.apache.geronimo.kernel.management.ManagedObject"
- *
+ *
* @version $Revision$ $Date$
*/
public abstract class AbstractWorkExecutorPool implements WorkExecutorPool {
@@ -85,57 +84,57 @@
/**
* Creates a pool with the specified minimum and maximum sizes. The
Channel
* used to enqueue the submitted Work instances is queueless synchronous
- * one.
- *
- * @param aMinSize Minimum size of the work executor pool.
- * @param aMaxSize Maximum size of the work executor pool.
+ * one.
+ *
+ * @param minSize Minimum size of the work executor pool.
+ * @param maxSize Maximum size of the work executor pool.
*/
- public AbstractWorkExecutorPool(int aMinSize, int aMaxSize) {
+ public AbstractWorkExecutorPool(int minSize, int maxSize) {
pooledExecutor = new TimedOutPooledExecutor();
- pooledExecutor.setMinimumPoolSize(aMinSize);
- pooledExecutor.setMaximumPoolSize(aMaxSize);
+ pooledExecutor.setMinimumPoolSize(minSize);
+ pooledExecutor.setMaximumPoolSize(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 aChannel Queue to be used as the queueing facility of this
pool.
- * @param aMinSize Minimum size of the work executor pool.
- * @param aMaxSize Maximum size of the work executor pool.
+ *
+ * @param channel Queue to be used as the queueing facility of this pool.
+ * @param minSize Minimum size of the work executor pool.
+ * @param maxSize Maximum size of the work executor pool.
*/
public AbstractWorkExecutorPool(
- Channel aChannel,
- int aMinSize, int aMaxSize) {
- pooledExecutor = new TimedOutPooledExecutor(aChannel);
- pooledExecutor.setMinimumPoolSize(aMinSize);
- pooledExecutor.setMaximumPoolSize(aMaxSize);
+ Channel channel,
+ int minSize, int maxSize) {
+ pooledExecutor = new TimedOutPooledExecutor(channel);
+ pooledExecutor.setMinimumPoolSize(minSize);
+ pooledExecutor.setMaximumPoolSize(maxSize);
pooledExecutor.waitWhenBlocked();
}
/**
* Delegates the work execution to the pooled executor.
- *
- * @param aWork Work to be executed.
+ *
+ * @param work Work to be executed.
*/
- protected void execute(WorkerContext aWork) throws InterruptedException {
- pooledExecutor.execute(aWork);
+ protected void execute(WorkerContext work) throws InterruptedException {
+ pooledExecutor.execute(work);
}
/**
* Execute the specified Work.
- *
- * @param aWork Work to be executed.
- *
+ *
+ * @param work Work to be executed.
+ *
* @exception WorkException Indicates that the Work execution has been
* unsuccessful.
*/
- public void executeWork(WorkerContext aWork) throws WorkException {
- aWork.workAccepted(this);
+ public void executeWork(WorkerContext work) throws WorkException {
+ work.workAccepted(this);
try {
- doExecute(aWork);
- WorkException exception = aWork.getWorkException();
+ doExecute(work);
+ WorkException exception = work.getWorkException();
if ( null != exception ) {
throw exception;
}
@@ -143,7 +142,7 @@
WorkCompletedException wcj = new WorkCompletedException(
"The execution has been interrupted.", e);
wcj.setErrorCode(WorkException.INTERNAL);
- throw wcj;
+ throw wcj;
}
}
@@ -172,10 +171,10 @@
/**
* Sets the minimum size of this pool.
- * @param aSize New minimum size of the pool.
+ * @param minSize New minimum size of the pool.
*/
- public void setMinimumPoolSize(int aSize) {
- pooledExecutor.setMinimumPoolSize(aSize);
+ public void setMinimumPoolSize(int minSize) {
+ pooledExecutor.setMinimumPoolSize(minSize);
}
/**
@@ -187,24 +186,24 @@
/**
* Sets the maximum size of this pool.
- * @param aSize New maximum size of this pool.
+ * @param maxSize New maximum size of this pool.
*/
- public void setMaximumPoolSize(int aSize) {
- pooledExecutor.setMaximumPoolSize(aSize);
+ public void setMaximumPoolSize(int maxSize) {
+ pooledExecutor.setMaximumPoolSize(maxSize);
}
/**
* 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 aWork Work to be executed.
- *
+ *
+ * @param work Work to be executed.
+ *
* @throws 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.
+ * @throws InterruptedException Indicates that the thread in charge of
the
+ * execution of the specified work has been interrupted.
*/
- protected abstract void doExecute(WorkerContext aWork)
+ protected abstract void doExecute(WorkerContext work)
throws WorkException, InterruptedException;
/**
@@ -214,5 +213,5 @@
public void doStop() {
pooledExecutor.shutdownAfterProcessingCurrentlyQueuedTasks();
}
-
+
}
1.3 +16 -39
incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/pool/ScheduleWorkExecutorPool.java
Index: ScheduleWorkExecutorPool.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/pool/ScheduleWorkExecutorPool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ScheduleWorkExecutorPool.java 16 Nov 2003 23:12:07 -0000 1.2
+++ ScheduleWorkExecutorPool.java 26 Nov 2003 02:15:32 -0000 1.3
@@ -56,24 +56,17 @@
package org.apache.geronimo.connector.work.pool;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
import javax.resource.spi.work.WorkException;
-import org.apache.geronimo.kernel.service.GeronimoMBeanEndpoint;
-import org.apache.geronimo.kernel.service.GeronimoMBeanInfo;
-import org.apache.geronimo.connector.work.GeronimoWorkManager;
-import org.apache.geronimo.connector.work.WorkerContext;
-
import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
+import org.apache.geronimo.connector.work.WorkerContext;
/**
- * WorkExecutorPool handling the submitted Work instances asynchronously.
- * More accurately, its execute method returns immediately after the work
+ * WorkExecutorPool handling the submitted Work instances asynchronously.
+ * More accurately, its execute method returns immediately after the work
* submission.
- *
- * @jmx:mbean extends="AbstractWorkExecutorPoolMBean"
- *
+ *
+ *
* @version $Revision$ $Date$
*/
public class ScheduleWorkExecutorPool
@@ -82,38 +75,22 @@
/**
* Creates a pool with the specified minimum and maximum sizes.
- *
- * @param aMinSize Minimum size of the work executor pool.
- * @param aMaxSize Maximum size of the work executor pool.
+ *
+ * @param minSize Minimum size of the work executor pool.
+ * @param maxSize Maximum size of the work executor pool.
*/
- public ScheduleWorkExecutorPool(int aMinSize, int aMaxSize) {
- super(new LinkedQueue(), aMinSize, aMaxSize);
+ public ScheduleWorkExecutorPool(int minSize, int maxSize) {
+ super(new LinkedQueue(), minSize, maxSize);
}
-
- public void setGeronimoWorkManager( GeronimoWorkManager wm ) {
- wm.setAsyncExecutor(this);
- }
-
+
/**
* Performs the actual execution of the specified work.
- *
- * @param aWork Work to be executed.
+ *
+ * @param work Work to be executed.
*/
- public void doExecute(WorkerContext aWork)
+ public void doExecute(WorkerContext work)
throws WorkException, InterruptedException {
- super.execute(aWork);
+ super.execute(work);
}
-
- public static GeronimoMBeanInfo getGeronimoMBeanInfo() throws Exception {
- try {
- GeronimoMBeanInfo rc
=AbstractWorkExecutorPool.getGeronimoMBeanInfo();
- rc.setTargetClass(ScheduleWorkExecutorPool.class);
- rc.addEndpoint(new GeronimoMBeanEndpoint("GeronimoWorkManager",
GeronimoWorkManager.class, new ObjectName("geronimo.jca:role=WorkManager"),
true));
- return rc;
- } catch (MalformedObjectNameException e) {
- throw new RuntimeException("GeronimoMBeanInfo could not be
gernerated.", e);
- }
- }
-
}
1.3 +15 -37
incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/pool/StartWorkExecutorPool.java
Index: StartWorkExecutorPool.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/pool/StartWorkExecutorPool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StartWorkExecutorPool.java 16 Nov 2003 23:12:07 -0000 1.2
+++ StartWorkExecutorPool.java 26 Nov 2003 02:15:32 -0000 1.3
@@ -56,25 +56,18 @@
package org.apache.geronimo.connector.work.pool;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
import javax.resource.spi.work.WorkException;
-import org.apache.geronimo.kernel.service.GeronimoMBeanEndpoint;
-import org.apache.geronimo.kernel.service.GeronimoMBeanInfo;
-import org.apache.geronimo.connector.work.GeronimoWorkManager;
-import org.apache.geronimo.connector.work.WorkerContext;
-
import EDU.oswego.cs.dl.util.concurrent.Latch;
import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
+import org.apache.geronimo.connector.work.WorkerContext;
/**
- * WorkExecutorPool handling the submitted Work instances synchronously
+ * WorkExecutorPool handling the submitted Work instances synchronously
* until the work start. More accurately, its execute method returns when the
* work is started.
- *
- * @jmx:mbean extends="AbstractWorkExecutorPoolMBean"
- *
+ *
+ *
* @version $Revision$ $Date$
*/
public class StartWorkExecutorPool
@@ -83,40 +76,25 @@
/**
* Creates a pool with the specified minimum and maximum sizes.
- *
- * @param aMinSize Minimum size of the work executor pool.
- * @param aMaxSize Maximum size of the work executor pool.
+ *
+ * @param minSize Minimum size of the work executor pool.
+ * @param maxSize Maximum size of the work executor pool.
*/
- public StartWorkExecutorPool(int aMinSize, int aMaxSize) {
- super(new LinkedQueue(), aMinSize, aMaxSize);
- }
-
- public void setGeronimoWorkManager( GeronimoWorkManager wm ) {
- wm.setStartExecutor(this);
+ public StartWorkExecutorPool(int minSize, int maxSize) {
+ super(new LinkedQueue(), minSize, maxSize);
}
/**
* Performs the actual work execution. This execution is synchronous
until
* the start of the submitted work.
*
- * @param aWork Work to be executed.
+ * @param work Work to be executed.
*/
- public void doExecute(WorkerContext aWork)
+ public void doExecute(WorkerContext work)
throws WorkException, InterruptedException {
- Latch latch = aWork.provideStartLatch();
- execute(aWork);
+ Latch latch = work.provideStartLatch();
+ execute(work);
latch.acquire();
}
-
- public static GeronimoMBeanInfo getGeronimoMBeanInfo() throws Exception {
- try {
- GeronimoMBeanInfo rc
=AbstractWorkExecutorPool.getGeronimoMBeanInfo();
- rc.setTargetClass(StartWorkExecutorPool.class);
- rc.addEndpoint(new GeronimoMBeanEndpoint("GeronimoWorkManager",
GeronimoWorkManager.class, new ObjectName("geronimo.jca:role=WorkManager"),
true));
- return rc;
- } catch (MalformedObjectNameException e) {
- throw new RuntimeException("GeronimoMBeanInfo could not be
gernerated.", e);
- }
- }
-
+
}
1.3 +13 -34
incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/pool/SyncWorkExecutorPool.java
Index: SyncWorkExecutorPool.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/pool/SyncWorkExecutorPool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SyncWorkExecutorPool.java 16 Nov 2003 23:12:07 -0000 1.2
+++ SyncWorkExecutorPool.java 26 Nov 2003 02:15:32 -0000 1.3
@@ -56,19 +56,13 @@
package org.apache.geronimo.connector.work.pool;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
import javax.resource.spi.work.WorkException;
-import org.apache.geronimo.kernel.service.GeronimoMBeanEndpoint;
-import org.apache.geronimo.kernel.service.GeronimoMBeanInfo;
-import org.apache.geronimo.connector.work.GeronimoWorkManager;
-import org.apache.geronimo.connector.work.WorkerContext;
-
import EDU.oswego.cs.dl.util.concurrent.Latch;
+import org.apache.geronimo.connector.work.WorkerContext;
/**
- * WorkExecutorPool handling the submitted Work instances synchronously.
+ * WorkExecutorPool handling the submitted Work instances synchronously.
* More accurately, its execute method blocks until the work completion.
*
* @version $Revision$ $Date$
@@ -79,39 +73,24 @@
/**
* Creates a pool with the specified minimum and maximum sizes.
- *
- * @param aMinSize Minimum size of the work executor pool.
- * @param aMaxSize Maximum size of the work executor pool.
+ *
+ * @param minSize Minimum size of the work executor pool.
+ * @param maxSize Maximum size of the work executor pool.
*/
- public SyncWorkExecutorPool(int aMinSize, int aMaxSize) {
- super(aMinSize, aMaxSize);
- }
-
- public void setGeronimoWorkManager( GeronimoWorkManager wm ) {
- wm.setSyncExecutor(this);
+ public SyncWorkExecutorPool(int minSize, int maxSize) {
+ super(minSize, maxSize);
}
/**
* Performs the actual work execution. This execution is synchronous.
*
- * @param aWork Work to be executed.
+ * @param work Work to be executed.
*/
- public void doExecute(WorkerContext aWork)
+ public void doExecute(WorkerContext work)
throws WorkException, InterruptedException {
- Latch latch = aWork.provideEndLatch();
- execute(aWork);
+ Latch latch = work.provideEndLatch();
+ execute(work);
latch.acquire();
}
-
- public static GeronimoMBeanInfo getGeronimoMBeanInfo() throws Exception {
- try {
- GeronimoMBeanInfo rc
=AbstractWorkExecutorPool.getGeronimoMBeanInfo();
- rc.setTargetClass(SyncWorkExecutorPool.class);
- rc.addEndpoint(new GeronimoMBeanEndpoint("GeronimoWorkManager",
GeronimoWorkManager.class, new ObjectName("geronimo.jca:role=WorkManager"),
true));
- return rc;
- } catch (MalformedObjectNameException e) {
- throw new RuntimeException("GeronimoMBeanInfo could not be
gernerated.", e);
- }
- }
-
+
}
1.3 +10 -11
incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/pool/TimedOutPooledExecutor.java
Index: TimedOutPooledExecutor.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/connector/work/pool/TimedOutPooledExecutor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TimedOutPooledExecutor.java 16 Nov 2003 23:12:07 -0000 1.2
+++ TimedOutPooledExecutor.java 26 Nov 2003 02:15:32 -0000 1.3
@@ -56,20 +56,19 @@
package org.apache.geronimo.connector.work.pool;
-import org.apache.geronimo.connector.work.WorkerContext;
-
import EDU.oswego.cs.dl.util.concurrent.Channel;
import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
+import org.apache.geronimo.connector.work.WorkerContext;
/**
* PooledExecutor enforcing a timed out "blocked execution policy". The works
* submitted to this pooled executor MUST be a WorkWrapper.
- *
+ *
* @version $Revision$ $Date$
*/
public class TimedOutPooledExecutor extends PooledExecutor
{
-
+
/**
* Creates a pooled executor. The Channel used to enqueue the submitted
* Work instance is a queueless synchronous one.
@@ -81,10 +80,10 @@
/**
* Creates a pooled executor, which uses the provided Channel as its
* queueing mechanism.
- *
+ *
* @param aChannel Channel to be used to enqueue the submitted Work
* intances.
- */
+ */
public TimedOutPooledExecutor(Channel aChannel) {
super(aChannel);
setBlockedExecutionHandler(new TimedOutSpinHandler());
@@ -92,7 +91,7 @@
/**
* Executes the provided task, which MUST be an instance of WorkWrapper.
- *
+ *
* @throws IllegalArgumentException Indicates that the provided task is
not
* a WorkWrapper instance.
*/
@@ -102,11 +101,11 @@
}
super.execute(aTask);
}
-
+
/**
* This class implements a time out policy when a work is blocked: it
offers
* the task to the pool until the work has timed out.
- *
+ *
* @version $Revision$ $Date$
*/
private class TimedOutSpinHandler
1.3 +13 -34
incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/work/PooledWorkManagerTest.java
Index: PooledWorkManagerTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/work/PooledWorkManagerTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PooledWorkManagerTest.java 16 Nov 2003 23:12:07 -0000 1.2
+++ PooledWorkManagerTest.java 26 Nov 2003 02:15:32 -0000 1.3
@@ -77,7 +77,7 @@
/**
* Timing is crucial for this test case, which focuses on the synchronization
* specificities of the doWork, startWork and scheduleWork.
- *
+ *
* @version $Revision$ $Date$
*/
public class PooledWorkManagerTest extends TestCase
@@ -90,29 +90,8 @@
private static final int m_timeout = 300;
private static final int m_tempo = 200;
- public PooledWorkManagerTest() throws Exception {
- super("WorkManager");
- initMinimalisticServer();
- m_workManager = new GeronimoWorkManager();
-
- // We are mocking the GeronimoMBeanContext
- m_workManager.setMBeanContext(new GeronimoMBeanContext(null, null,
null){
- public int getState() throws Exception {
- return State.RUNNING_INDEX;
- }
- });
-
- SyncWorkExecutorPool syncWorkExecutorPool = new
SyncWorkExecutorPool(1, 1);
- syncWorkExecutorPool.setGeronimoWorkManager(m_workManager);
-
- StartWorkExecutorPool startWorkExecutorPool = new
StartWorkExecutorPool(1, 1);
- startWorkExecutorPool.setGeronimoWorkManager(m_workManager);
-
- ScheduleWorkExecutorPool scheduleWorkExecutorPool = new
ScheduleWorkExecutorPool(1, 1);
- scheduleWorkExecutorPool.setGeronimoWorkManager(m_workManager);
- }
-
- public void initMinimalisticServer() throws Exception {
+ protected void setUp() throws Exception {
+ m_workManager = new GeronimoWorkManager(1, 1);
}
public void testDoWork() throws Exception {
@@ -141,7 +120,7 @@
assertTrue("Wrong number of works in the START_TIMED_OUT state: " +
"expected 1; retrieved " + nbTimeout, 1 == nbTimeout);
}
-
+
public void testStartWork() throws Exception {
AbstractDummyWork threads[] = helperTest(DummyStartWork.class, 2);
int nbStopped = 0;
@@ -183,11 +162,11 @@
assertTrue("At least one work should be in the WORK_ACCEPTED state.",
nbAccepted > 0);
}
-
+
private AbstractDummyWork[] helperTest(Class aWork, int nbThreads)
throws Exception {
Constructor constructor = aWork.getConstructor(
- new Class[]{WorkManager.class, String.class});
+ new Class[]{WorkManager.class, String.class});
AbstractDummyWork rarThreads[] =
new AbstractDummyWork[nbThreads];
for (int i = 0; i < nbThreads; i++) {
@@ -200,7 +179,7 @@
}
return rarThreads;
}
-
+
public static abstract class AbstractDummyWork extends Thread {
public DummyWorkListener m_listener;
protected WorkManager m_workManager;
@@ -212,7 +191,7 @@
}
public void run() {
try {
- perform(new DummyWork(m_name), m_timeout, null, m_listener);
+ perform(new DummyWork(m_name), m_timeout, null, m_listener);
} catch (Exception e) {
e.printStackTrace();
}
@@ -234,7 +213,7 @@
m_workManager.doWork(work, startTimeout, execContext,
workListener);
}
}
-
+
public static class DummyStartWork extends AbstractDummyWork {
public DummyStartWork(WorkManager aWorkManager, String aName) {
super(aWorkManager, aName);
@@ -246,7 +225,7 @@
m_workManager.startWork(work, startTimeout, execContext,
workListener);
}
}
-
+
public static class DummyScheduleWork extends AbstractDummyWork {
public DummyScheduleWork(WorkManager aWorkManager, String aName) {
super(aWorkManager, aName);
@@ -258,7 +237,7 @@
m_workManager.scheduleWork(work, startTimeout, execContext,
workListener);
}
}
-
+
public static class DummyWork implements Work {
private String m_name;
public DummyWork(String aName) {m_name = aName;}
@@ -272,7 +251,7 @@
}
public String toString() {return m_name;}
}
-
+
public static class DummyWorkListener implements WorkListener {
public WorkEvent m_event;
public void workAccepted(WorkEvent e) {m_event = e;}