You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2007/02/08 23:22:54 UTC

svn commit: r505061 - /incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/engine/BoundedWorkQueue.java

Author: schor
Date: Thu Feb  8 14:22:53 2007
New Revision: 505061

URL: http://svn.apache.org/viewvc?view=rev&rev=505061
Log:
UIMA-284: Added missing notifyAll to the enqueue, and renamed
a field to indicate it was the max size.

Modified:
    incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/engine/BoundedWorkQueue.java

Modified: incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/engine/BoundedWorkQueue.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/engine/BoundedWorkQueue.java?view=diff&rev=505061&r1=505060&r2=505061
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/engine/BoundedWorkQueue.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/engine/BoundedWorkQueue.java Thu Feb  8 14:22:53 2007
@@ -30,12 +30,15 @@
  * Implementation of a Bounded Queue, a queue with a fixed number of slots. Used primarily to feed
  * data to Processing Units, it is filled by a producer like ArtifactProducer and consumed by
  * ProcessingUnit(s). When the queue is full it will block a request for enqueue until a slot frees
- * up.
+ * up.  
+ * 
+ * <p>There are 2 dequeue calls.  One returns null if the queue is empty, the other can be given a 
+ * timeout - and it will wait up to that time waiting for something to get enqueued.
  * 
  * 
  */
 public class BoundedWorkQueue {
-  protected int queueSize = 0;
+  protected final int queueMaxSize;
 
   protected LinkedList queue = new LinkedList();
 
@@ -58,7 +61,7 @@
    *          CPE Engine reference
    */
   public BoundedWorkQueue(int aQueueSize, String aQueueName, CPMEngine aCpmEngine) {
-    queueSize = aQueueSize;
+    queueMaxSize = aQueueSize;
     queueName = aQueueName;
     cpm = aCpmEngine;
   }
@@ -96,7 +99,7 @@
    * @return - queue max size
    */
   public int getCapacity() {
-    return queueSize;
+    return queueMaxSize;
   }
 
   /**
@@ -123,7 +126,7 @@
       // terminating the CPE
       if (!(anObject instanceof Object[] && ((Object[]) anObject)[0] instanceof EOFToken)) {
         // Block if the queue is full AND the CPE is running
-        while (numberElementsInQueue == queueSize && (cpm == null || cpm.isRunning())) {
+        while (numberElementsInQueue == queueMaxSize && (cpm == null || cpm.isRunning())) {
           if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
             UIMAFramework.getLogger(this.getClass()).logrb(
                     Level.FINEST,
@@ -164,6 +167,7 @@
               new Object[] { Thread.currentThread().getName(), queueName,
                   String.valueOf(numberElementsInQueue) });
     }
+    notifyAll();  
   }
 
   /**
@@ -218,6 +222,7 @@
               new Object[] { Thread.currentThread().getName(), queueName,
                   String.valueOf(numberElementsInQueue) });
     }
+ 
     return returnedObject;
   }
 
@@ -231,8 +236,8 @@
    * @return - Object from the queue, or null if time out
    */
   public synchronized Object dequeue(long aTimeout) {
-    Object resource = null;
-    if ((resource = dequeue()) == null && cpm.isRunning()) {
+    Object resource = dequeue();
+    if (resource == null && cpm.isRunning()) {
       try {
         if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
           UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),