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

svn commit: r505066 - in /incubator/uima/uimaj/trunk/uimaj-core/src: main/java/org/apache/uima/analysis_engine/impl/PrimitiveAnalysisEngine_impl.java test/java/org/apache/uima/cas/impl/ComponentInfoTest.java

Author: alally
Date: Thu Feb  8 14:31:29 2007
New Revision: 505066

URL: http://svn.apache.org/viewvc?view=rev&rev=505066
Log:
Fix for problem with CAS's currentComponentInfo not being cleared
after processing, which led to subsequent problems in a 
mixed-deployment CPE pipeline.
UIMA-294: https://issues.apache.org/jira/browse/UIMA-294

Added:
    incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/ComponentInfoTest.java
Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PrimitiveAnalysisEngine_impl.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PrimitiveAnalysisEngine_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PrimitiveAnalysisEngine_impl.java?view=diff&rev=505066&r1=505065&r2=505066
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PrimitiveAnalysisEngine_impl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PrimitiveAnalysisEngine_impl.java Thu Feb  8 14:31:29 2007
@@ -293,7 +293,7 @@
 
       // return a CasIterator that allows caller to step through the outputs
       // of this AnalysisComponent (if any)
-      return new AnalysisComponentCasIterator(mAnalysisComponent);
+      return new AnalysisComponentCasIterator(mAnalysisComponent, aCAS);
     } finally {
       exitProcess();
     }
@@ -372,6 +372,10 @@
         // call the process method
         mAnalysisComponent.process(casToPass);
         getMBean().incrementCASesProcessed();
+        
+        //note we do not clear the CAS's currentComponentInfo at this time.  The AnalysisComponents still
+        //can access the CAS until such time as its hasNext method returns false.  Thus is is the
+        //AnalysisComponentCasIterator that knows when it is time to clear the currentComponentInfo.
       } catch (Exception e) {
         aCAS.setCurrentComponentInfo(null);
         if (e instanceof AnalysisEngineProcessException) {
@@ -515,9 +519,11 @@
    */
   class AnalysisComponentCasIterator implements CasIterator {
     private AnalysisComponent mMyAnalysisComponent;
+    private CAS mInputCas;
 
-    AnalysisComponentCasIterator(AnalysisComponent aAnalysisComponent) {
+    AnalysisComponentCasIterator(AnalysisComponent aAnalysisComponent, CAS aInputCas) {
       mMyAnalysisComponent = aAnalysisComponent;
+      mInputCas = aInputCas;
     }
 
     /*
@@ -528,7 +534,14 @@
     public boolean hasNext() throws AnalysisEngineProcessException {
       enterProcess();
       try {
-        return mMyAnalysisComponent.hasNext();
+        boolean result = mMyAnalysisComponent.hasNext();
+        if (!result) {
+          //when hasNext returns false, by contract the AnalysisComponent is done processing its
+          //input CAS.  Now is the time to clear the currentComponentInfo to indicate that the
+          //CAS is no longer being processed.
+          mInputCas.setCurrentComponentInfo(null);
+        }
+        return result;
       } finally {
         exitProcess();
       }

Added: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/ComponentInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/ComponentInfoTest.java?view=auto&rev=505066
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/ComponentInfoTest.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/ComponentInfoTest.java Thu Feb  8 14:31:29 2007
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.uima.cas.impl;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.test.junit_extension.JUnitExtension;
+import org.apache.uima.util.XMLInputSource;
+
+/**
+ * 
+ */
+public class ComponentInfoTest extends TestCase {
+  public void testComponentInfo() throws Exception {
+    //test the CAS.getCurrentComponentInfo() is null after a component has
+    //been processed
+    File descFile = JUnitExtension.getFile("TextAnalysisEngineImplTest/TestPrimitiveTae1.xml");
+    AnalysisEngineDescription desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
+            new XMLInputSource(descFile));
+    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc);
+    CAS cas = ae.newCAS();
+    ae.process(cas);
+    assertNull(((CASImpl)cas).getCurrentComponentInfo());
+    
+    //same test for aggregate
+    //test the CAS.getCurrentComponentInfo() is null after a component has
+    //been processed
+    descFile = JUnitExtension.getFile("TextAnalysisEngineImplTest/AggregateTaeForMergeTest.xml");
+    desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
+            new XMLInputSource(descFile));
+    ae = UIMAFramework.produceAnalysisEngine(desc);
+    cas = ae.newCAS();
+    ae.process(cas);
+    assertNull(((CASImpl)cas).getCurrentComponentInfo());
+  }
+}