gate.creole
Class AbstractController

java.lang.Object
  extended by gate.util.AbstractFeatureBearer
      extended by gate.creole.AbstractResource
          extended by gate.creole.AbstractController
All Implemented Interfaces:
Controller, Executable, ProcessingResource, Resource, Benchmarkable, FeatureBearer, NameBearer, Serializable
Direct Known Subclasses:
SerialController

@CreoleResource(icon="application")
public abstract class AbstractController
extends AbstractResource
implements Controller, ProcessingResource, Benchmarkable

See Also:
Serialized Form

Nested Class Summary
protected  class AbstractController.InternalStatusListener
          A simple status listener used to forward the events upstream.
protected  class AbstractController.IntervalProgressListener
          A progress listener used to convert a 0..100 interval into a smaller one
 
Field Summary
protected  Map benchmarkFeatures
          Shared featureMap
protected  String benchmarkID
          Benchmark ID of this resource.
protected  boolean interrupted
           
protected  String name
           
 
Fields inherited from class gate.util.AbstractFeatureBearer
features
 
Constructor Summary
AbstractController()
           
 
Method Summary
 void addControllerListener(ControllerListener l)
           
 void addProgressListener(ProgressListener l)
          Adds a ProgressListener to the list of listeners for this processing resource.
 void addStatusListener(StatusListener l)
          Adds a StatusListener to the list of listeners for this processing resource
 void cleanup()
          Clears the internal data of the resource, when it gets released *
 void execute()
          Execute this controller.
protected  void executeImpl()
          Executes the PRs in this controller, according to the execution strategy of the particular controller type (simple pipeline, parallel execution, once-per-document in a corpus, etc.).
protected  void fireProcessFinished()
          Notifies all the ProgressListeners of a progress finished.
protected  void fireProgressChanged(int e)
          Notifies all the ProgressListeners of a progress change event.
protected  void fireResourceAdded(ControllerEvent e)
           
protected  void fireResourceRemoved(ControllerEvent e)
           
protected  void fireStatusChanged(String e)
          Notifies all the StatusListeners of a change of status.
 String getBenchmarkId()
          Returns the benchmark ID of this controller.
protected  Set<ControllerAwarePR> getControllerAwarePRs()
          Get the set of PRs from this controller that implement ControllerAwarePR.
 String getName()
          Returns the name of this resource
 List getOffendingPocessingResources()
          Checks whether all the contained PRs have all the required runtime parameters set.
 Resource init()
          Initialise this resource, and return it.
 void interrupt()
          Notifies all the PRs in this controller that they should stop their execution as soon as possible.
 boolean isInterrupted()
          Returns true if this executable has been interrupted via the Executable.interrupt() method since the last time its Executable.execute() method was called
 void reInit()
          Reinitialises the processing resource.
 void removeControllerListener(ControllerListener l)
           
 void removeProgressListener(ProgressListener l)
          Removes a ProgressListener from the list of listeners for this processing resource.
 void removeStatusListener(StatusListener l)
          Removes a StatusListener from the list of listeners for this processing resource
 void setBenchmarkId(String benchmarkID)
          Sets the benchmark ID of this controller.
 void setName(String name)
          Sets the name of this resource
 void setPRs(Collection PRs)
          Populates this controller from a collection of ProcessingResources (optional operation).
 
Methods inherited from class gate.creole.AbstractResource
checkParameterValues, getBeanInfo, getParameterValue, getParameterValue, removeResourceListeners, setParameterValue, setParameterValue, setParameterValues, setParameterValues, setResourceListeners
 
Methods inherited from class gate.util.AbstractFeatureBearer
getFeatures, setFeatures
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gate.Controller
getPRs
 
Methods inherited from interface gate.Resource
getParameterValue, setParameterValue, setParameterValues
 

Field Detail

benchmarkID

protected String benchmarkID
Benchmark ID of this resource.


benchmarkFeatures

protected Map benchmarkFeatures
Shared featureMap


name

protected String name

interrupted

protected boolean interrupted
Constructor Detail

AbstractController

public AbstractController()
Method Detail

execute

public void execute()
             throws ExecutionException
Execute this controller. This implementation takes care of informing any ControllerAwarePRs of the start and end of execution, and delegates to the executeImpl() method to do the real work. Subclasses should override executeImpl() rather than this method.

Specified by:
execute in interface Controller
Specified by:
execute in interface Executable
Throws:
ExecutionException

getControllerAwarePRs

protected Set<ControllerAwarePR> getControllerAwarePRs()
Get the set of PRs from this controller that implement ControllerAwarePR. If there are no such PRs in this controller, an empty set is returned. This implementation simply filters the collection returned by Controller.getPRs(), override this method if your subclass admits a more efficient implementation.


executeImpl

protected void executeImpl()
                    throws ExecutionException
Executes the PRs in this controller, according to the execution strategy of the particular controller type (simple pipeline, parallel execution, once-per-document in a corpus, etc.). Subclasses should override this method, allowing the default execute() method to handle sending notifications to controller aware PRs.

Throws:
ExecutionException

init

public Resource init()
              throws ResourceInstantiationException
Initialise this resource, and return it.

Specified by:
init in interface Resource
Overrides:
init in class AbstractResource
Throws:
ResourceInstantiationException

reInit

public void reInit()
            throws ResourceInstantiationException
Description copied from interface: ProcessingResource
Reinitialises the processing resource. After calling this method the resource should be in the state it is after calling init. If the resource depends on external resources (such as rules files) then the resource will re-read those resources. If the data used to create the resource has changed since the resource has been created then the resource will change too after calling reInit().

Specified by:
reInit in interface ProcessingResource
Throws:
ResourceInstantiationException

cleanup

public void cleanup()
Clears the internal data of the resource, when it gets released *

Specified by:
cleanup in interface Resource
Overrides:
cleanup in class AbstractResource

setPRs

public void setPRs(Collection PRs)
Populates this controller from a collection of ProcessingResources (optional operation). Controllers that are serializable must implement this method needed by GATE to restore their contents.

Specified by:
setPRs in interface Controller
Throws:
UnsupportedOperationException - if the setPRs method is not supported by this controller.

interrupt

public void interrupt()
Notifies all the PRs in this controller that they should stop their execution as soon as possible.

Specified by:
interrupt in interface Executable

isInterrupted

public boolean isInterrupted()
Description copied from interface: Executable
Returns true if this executable has been interrupted via the Executable.interrupt() method since the last time its Executable.execute() method was called

Specified by:
isInterrupted in interface Executable

removeStatusListener

public void removeStatusListener(StatusListener l)
Removes a StatusListener from the list of listeners for this processing resource


addStatusListener

public void addStatusListener(StatusListener l)
Adds a StatusListener to the list of listeners for this processing resource


fireStatusChanged

protected void fireStatusChanged(String e)
Notifies all the StatusListeners of a change of status.

Parameters:
e - the message describing the status change

addProgressListener

public void addProgressListener(ProgressListener l)
Adds a ProgressListener to the list of listeners for this processing resource.


removeProgressListener

public void removeProgressListener(ProgressListener l)
Removes a ProgressListener from the list of listeners for this processing resource.


fireProgressChanged

protected void fireProgressChanged(int e)
Notifies all the ProgressListeners of a progress change event.

Parameters:
e - the new value of execution completion

fireProcessFinished

protected void fireProcessFinished()
Notifies all the ProgressListeners of a progress finished.


getOffendingPocessingResources

public List getOffendingPocessingResources()
                                    throws ResourceInstantiationException
Checks whether all the contained PRs have all the required runtime parameters set.

Returns:
a List of ProcessingResources that have required parameters with null values if they exist null otherwise.
Throws:
{@link - ResourceInstantiationException} if problems occur while inspecting the parameters for one of the resources. These will normally be introspection problems and are usually caused by the lack of a parameter or of the read accessor for a parameter.
ResourceInstantiationException

setName

public void setName(String name)
Sets the name of this resource

Specified by:
setName in interface NameBearer
Overrides:
setName in class AbstractResource

getName

public String getName()
Returns the name of this resource

Specified by:
getName in interface NameBearer
Overrides:
getName in class AbstractResource

removeControllerListener

public void removeControllerListener(ControllerListener l)

addControllerListener

public void addControllerListener(ControllerListener l)

fireResourceAdded

protected void fireResourceAdded(ControllerEvent e)

fireResourceRemoved

protected void fireResourceRemoved(ControllerEvent e)

setBenchmarkId

public void setBenchmarkId(String benchmarkID)
Sets the benchmark ID of this controller.

Specified by:
setBenchmarkId in interface Benchmarkable
Parameters:
benchmarkID - the benchmark ID, which must not contain spaces as it is already used as a separator in the log, you can use Benchmark.createBenchmarkId(String, String) for it.

getBenchmarkId

public String getBenchmarkId()
Returns the benchmark ID of this controller.

Specified by:
getBenchmarkId in interface Benchmarkable
Returns: