Revision: 16726
          http://sourceforge.net/p/gate/code/16726
Author:   johann_p
Date:     2013-07-08 10:28:56 +0000 (Mon, 08 Jul 2013)
Log Message:
-----------
Attempt to fix bug #177.
Corpus controllers overwrite the default execute()
method from AbstractController so that if the corpus
controller is invoked as a subpipeline, its congroller
aware PRs are not notified. Instead, the corpus controller
is made to be a corpus aware PR too and passes on
the notifications it gets to its corpus aware PRs.

Modified Paths:
--------------
    gate/trunk/src/gate/creole/ConditionalSerialAnalyserController.java
    gate/trunk/src/gate/creole/SerialAnalyserController.java

Modified: gate/trunk/src/gate/creole/ConditionalSerialAnalyserController.java
===================================================================
--- gate/trunk/src/gate/creole/ConditionalSerialAnalyserController.java 
2013-07-07 10:04:45 UTC (rev 16725)
+++ gate/trunk/src/gate/creole/ConditionalSerialAnalyserController.java 
2013-07-08 10:28:56 UTC (rev 16726)
@@ -15,6 +15,7 @@
 
 package gate.creole;
 
+import java.lang.reflect.UndeclaredThrowableException;
 import java.util.*;
 
 import gate.*;
@@ -35,8 +36,13 @@
  * NOTE: if at the time when execute() is invoked, the document is not null,
  * it is assumed that this controller is invoked from another controller and
  * only this document is processed while the corpus (which must still be
- * non-null) is ignored. If the document is null, all documents in the corpus
- * are processed in sequence. 
+ * non-null) is ignored. Also, if the document is not null, the CorpusAwarePRs
+ * are not notified at the beginning, end, or abnormal termination of the 
pipeline. 
+ * <p>
+ * If the document is null, all documents in the corpus
+ * are processed in sequence and CorpusAwarePRs are notified
+ * before the processing of the documents and after all documents
+ * have been processed or an abnormal termination occurred.
  * 
  */
 @CreoleResource(name = "Conditional Corpus Pipeline",
@@ -45,7 +51,7 @@
     helpURL = "http://gate.ac.uk/userguide/sec:developer:cond";)
 public class ConditionalSerialAnalyserController
        extends ConditionalSerialController
-       implements CorpusController, LanguageAnalyser {
+       implements CorpusController, LanguageAnalyser, ControllerAwarePR {
 
   /** Debug flag */
   private static final boolean DEBUG = false;
@@ -76,6 +82,75 @@
     this.corpus = corpus;
   }
 
+  protected boolean runningAsSubPipeline = false;
+  
+  @Override
+  public void execute() throws ExecutionException {
+
+    // Our assumption of if we run as a subpipeline of another corpus pipeline 
or
+    // not is based on whether or not the document is null or not:
+    if(document != null) {
+      runningAsSubPipeline = true;
+    } else {
+      runningAsSubPipeline = false;
+    }
+    // inform ControllerAware PRs that execution has started, but only if we 
are not
+    // running as a subpipeline of another corpus pipeline.
+    if(!runningAsSubPipeline) {
+      for(ControllerAwarePR pr : getControllerAwarePRs()) {
+        pr.controllerExecutionStarted(this);
+      }
+    }
+    Throwable thrown = null;
+    try {
+      if(Benchmark.isBenchmarkingEnabled()) {
+        // write a start marker to the benchmark log for this
+        // controller as a whole
+        Benchmark.startPoint(getBenchmarkId());
+      }
+      // do the real work
+      this.executeImpl();
+    }
+    catch(Throwable t) {
+      thrown = t;
+    }
+    finally {
+      if(thrown == null) {
+        // successfully completed
+        if(!runningAsSubPipeline) {
+          for(ControllerAwarePR pr : getControllerAwarePRs()) {
+            pr.controllerExecutionFinished(this);
+          }
+        }
+      }
+      else {
+        // aborted
+        if(!runningAsSubPipeline) {
+          for(ControllerAwarePR pr : getControllerAwarePRs()) {
+            pr.controllerExecutionAborted(this, thrown);
+          }
+        } 
+        // rethrow the aborting exception or error
+        if(thrown instanceof Error) {
+          throw (Error)thrown;
+        }
+        else if(thrown instanceof RuntimeException) {
+          throw (RuntimeException)thrown;
+        }
+        else if(thrown instanceof ExecutionException) {
+          throw (ExecutionException)thrown;
+        }
+        else {
+          // we have a checked exception that isn't one executeImpl can
+          // throw. This shouldn't be possible, but just in case...
+          throw new UndeclaredThrowableException(thrown);
+        }
+      }
+    }
+  }
+  
+  
+
   /** Run the Processing Resources in sequence. */
   protected void executeImpl() throws ExecutionException{
     interrupted = false;
@@ -346,4 +421,29 @@
       setCorpus(null);
     }
   }
+
+  @Override
+  public void controllerExecutionStarted(Controller c)
+      throws ExecutionException {
+    for(ControllerAwarePR pr : getControllerAwarePRs()) {
+      pr.controllerExecutionStarted(this);
+    }
+    
+  }
+
+  @Override
+  public void controllerExecutionFinished(Controller c)
+      throws ExecutionException {
+    for(ControllerAwarePR pr : getControllerAwarePRs()) {
+      pr.controllerExecutionFinished(this);
+    }    
+  }
+
+  @Override
+  public void controllerExecutionAborted(Controller c, Throwable t)
+      throws ExecutionException {
+    for(ControllerAwarePR pr : getControllerAwarePRs()) {
+      pr.controllerExecutionAborted(c, t);
+    }    
+  }
 }

Modified: gate/trunk/src/gate/creole/SerialAnalyserController.java
===================================================================
--- gate/trunk/src/gate/creole/SerialAnalyserController.java    2013-07-07 
10:04:45 UTC (rev 16725)
+++ gate/trunk/src/gate/creole/SerialAnalyserController.java    2013-07-08 
10:28:56 UTC (rev 16726)
@@ -15,6 +15,7 @@
 
 package gate.creole;
 
+import java.lang.reflect.UndeclaredThrowableException;
 import java.util.*;
 
 import gate.*;
@@ -31,15 +32,20 @@
  * NOTE: if at the time when execute() is invoked, the document is not null,
  * it is assumed that this controller is invoked from another controller and
  * only this document is processed while the corpus (which must still be
- * non-null) is ignored. If the document is null, all documents in the corpus
- * are processed in sequence. 
+ * non-null) is ignored. Also, if the document is not null, the CorpusAwarePRs
+ * are not notified at the beginning, end, or abnormal termination of the 
pipeline. 
+ * <p>
+ * If the document is null, all documents in the corpus
+ * are processed in sequence and CorpusAwarePRs are notified
+ * before the processing of the documents and after all documents
+ * have been processed or an abnormal termination occurred.
  * 
  */
 @CreoleResource(name = "Corpus Pipeline",
     comment = "A serial controller for PR pipelines over corpora.",
     helpURL = "http://gate.ac.uk/userguide/sec:developer:apps";)
 public class SerialAnalyserController extends SerialController 
-       implements CorpusController, LanguageAnalyser {
+       implements CorpusController, LanguageAnalyser, ControllerAwarePR {
 
   /** Debug flag */
   private static final boolean DEBUG = false;
@@ -51,6 +57,9 @@
     return document;
   }
 
+  protected boolean runningAsSubPipeline = false;
+  
+  
   /**
    * @param document the document to set
    */
@@ -68,7 +77,75 @@
   public void setCorpus(gate.Corpus corpus) {
     this.corpus = corpus;
   }
+  
+  @Override
+  public void execute() throws ExecutionException {
 
+    // Our assumption of if we run as a subpipeline of another corpus pipeline 
or
+    // not is based on whether or not the document is null or not:
+    if(document != null) {
+      runningAsSubPipeline = true;
+    } else {
+      runningAsSubPipeline = false;
+    }
+    // inform ControllerAware PRs that execution has started, but only if we 
are not
+    // running as a subpipeline of another corpus pipeline.
+    if(!runningAsSubPipeline) {
+      for(ControllerAwarePR pr : getControllerAwarePRs()) {
+        pr.controllerExecutionStarted(this);
+      }
+    }
+    Throwable thrown = null;
+    try {
+      if(Benchmark.isBenchmarkingEnabled()) {
+        // write a start marker to the benchmark log for this
+        // controller as a whole
+        Benchmark.startPoint(getBenchmarkId());
+      }
+      // do the real work
+      this.executeImpl();
+    }
+    catch(Throwable t) {
+      thrown = t;
+    }
+    finally {
+      if(thrown == null) {
+        // successfully completed
+        if(!runningAsSubPipeline) {
+          for(ControllerAwarePR pr : getControllerAwarePRs()) {
+            pr.controllerExecutionFinished(this);
+          }
+        }
+      }
+      else {
+        // aborted
+        if(!runningAsSubPipeline) {
+          for(ControllerAwarePR pr : getControllerAwarePRs()) {
+            pr.controllerExecutionAborted(this, thrown);
+          }
+        } 
+        // rethrow the aborting exception or error
+        if(thrown instanceof Error) {
+          throw (Error)thrown;
+        }
+        else if(thrown instanceof RuntimeException) {
+          throw (RuntimeException)thrown;
+        }
+        else if(thrown instanceof ExecutionException) {
+          throw (ExecutionException)thrown;
+        }
+        else {
+          // we have a checked exception that isn't one executeImpl can
+          // throw. This shouldn't be possible, but just in case...
+          throw new UndeclaredThrowableException(thrown);
+        }
+      }
+    }
+  }
+  
+  
+  
+
   /** Run the Processing Resources in sequence. */
   protected void executeImpl() throws ExecutionException {
     interrupted = false;
@@ -299,4 +376,28 @@
       setCorpus(null);
     }
   }
+
+  @Override
+  public void controllerExecutionStarted(Controller c)
+      throws ExecutionException {
+    // TODO Auto-generated method stub
+    for(ControllerAwarePR pr : getControllerAwarePRs()) {
+      pr.controllerExecutionFinished(this);
+    }
+    
+  }
+
+  @Override
+  public void controllerExecutionFinished(Controller c)
+      throws ExecutionException {
+    // TODO Auto-generated method stub
+    
+  }
+
+  @Override
+  public void controllerExecutionAborted(Controller c, Throwable t)
+      throws ExecutionException {
+    // TODO Auto-generated method stub
+    
+  }
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to