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:26:26 UTC

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

Author: schor
Date: Thu Feb  8 14:26:25 2007
New Revision: 505062

URL: http://svn.apache.org/viewvc?view=rev&rev=505062
Log:
UIMA-284 Made a field final, added missing notifyAll, and commented
out unused and dangerous to expose getters.  They're 
dangerous because they return values which if the caller
changes, can cause system failure.

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

Modified: incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/engine/CPECasPool.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/engine/CPECasPool.java?view=diff&rev=505062&r1=505061&r2=505062
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/engine/CPECasPool.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/engine/CPECasPool.java Thu Feb  8 14:26:25 2007
@@ -26,20 +26,13 @@
 import org.apache.uima.UIMAFramework;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.collection.impl.cpm.utils.CPMUtils;
-import org.apache.uima.resource.CasDefinition;
 import org.apache.uima.resource.CasManager;
 import org.apache.uima.resource.ResourceInitializationException;
-import org.apache.uima.util.CasCreationUtils;
 import org.apache.uima.util.Level;
 
 /**
  * Implements object pooling mechanism to limit number of CAS instances. Cas'es are checked out,
- * used and checked back in when done.
- * 
- * 
- * 
- * 
- * 
+ * used and checked back in when done. 
  */
 public class CPECasPool {
 
@@ -49,7 +42,7 @@
 
   private LinkedList checkedOutInstances = new LinkedList();
 
-  private int mNumInstances;
+  private final int mNumInstances;
 
   /**
    * Initialize the pool.
@@ -106,16 +99,17 @@
    * @return - CAS instance, or null on timeout
    */
   public synchronized CAS getCas(long aTimeout) {
-    CAS cas;
+    CAS cas = getCas();
+    
+    if (cas != null) {
+      return cas;
+    }
 
-    if ((cas = getCas()) == null) {
-      try {
-        this.wait(aTimeout);
-      } catch (InterruptedException e) {
-      }
-      cas = getCas();
+    try {
+      this.wait(aTimeout);
+    } catch (InterruptedException e) { // do nothing if interrupted
     }
-    return cas;
+    return getCas();
   }
 
   /**
@@ -198,6 +192,7 @@
                 new Object[] { Thread.currentThread().getName(),
                     String.valueOf(checkedOutInstances.size()) });
       }
+      this.notifyAll();  // when CAS becomes available
     }
 
   }
@@ -235,22 +230,24 @@
     return mNumInstances;
   }
 
-  /**
-   * Returns pool capacity
-   * 
-   * @return - size of the pool
-   */
-  protected Vector getAllInstances() {
-    return mAllInstances;
-  }
-
-  /**
-   * Number of free Cas'es available in the pool
-   * 
-   * @return
-   */
-  protected Vector getFreeInstances() {
-    return mFreeInstances;
-  }
+  // never called and dangerous to expose
+//  /**
+//   * Returns pool capacity
+//   * 
+//   * @return - size of the pool
+//   */
+//  protected Vector getAllInstances() {
+//    return mAllInstances;
+//  }
+
+  // Never called
+//  /**
+//   * Number of free Cas'es available in the pool
+//   * 
+//   * @return
+//   */
+//  protected synchronized Vector getFreeInstances() {
+//    return mFreeInstances;
+//  }
 
 }