uima-ducc-common/src/main/java/org/apache/uima/ducc/common/uima/DuccJobProcessFC.java [56:192]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  private List<String> mSequence;
  private boolean mStartsWithCasMultiplier=false;
  private Type mWorkitemType;
  private Feature mSendToAllFeature;
  private Feature mSendToLastFeature;
  

  public void initialize(FlowControllerContext aContext) throws ResourceInitializationException {
    super.initialize(aContext);

    FlowConstraints flowConstraints = aContext.getAggregateMetadata().getFlowConstraints();
    mSequence = new ArrayList<String>();
    if (flowConstraints instanceof FixedFlow) {
      String[] sequence = ((FixedFlow) flowConstraints).getFixedFlow();
      mSequence.addAll(Arrays.asList(sequence));
    } else {
      throw new ResourceInitializationException(ResourceInitializationException.FLOW_CONTROLLER_REQUIRES_FLOW_CONSTRAINTS,
              new Object[]{this.getClass().getName(), "fixedFlow", aContext.getAggregateMetadata().getSourceUrlString()});
    }

    // Check if first delegate is a CasMultiplier.
    // Any other CMs will have no special treatment, 
    // i.e. parent will follow children thru the rest of the pipeline
    
    Iterator<Entry<String, AnalysisEngineMetaData>> aeIter = getContext().getAnalysisEngineMetaDataMap().entrySet().iterator();
    while (aeIter.hasNext()) {
      Entry<String, AnalysisEngineMetaData> entry = aeIter.next();
      AnalysisEngineMetaData md = entry.getValue();
      OperationalProperties op = md.getOperationalProperties();
      if (op.getOutputsNewCASes()) {
        if (mSequence.get(0).equals(entry.getKey())) {
          mStartsWithCasMultiplier = true;
        }
      } 
    }
  }


  public void typeSystemInit(TypeSystem aTypeSystem) throws AnalysisEngineProcessException {
	  // Get a reference to the "Workitem" Type
	  mWorkitemType = aTypeSystem.getType("org.apache.uima.ducc.Workitem");
	  if (mWorkitemType == null) {
		  throw new AnalysisEngineProcessException(AnnotatorInitializationException.TYPE_NOT_FOUND,
				  new Object[] { getClass().getName(), "org.apache.uima.ducc.Workitem" });
	  }
	
	  // Get a reference to the "sendToALL" Feature
	  mSendToAllFeature = mWorkitemType.getFeatureByBaseName("sendToAll");
	  if (mSendToAllFeature == null) {
		  throw new AnalysisEngineProcessException(AnnotatorInitializationException.FEATURE_NOT_FOUND,
				  new Object[] { getClass().getName(), "org.apache.uima.ducc.Workitem:sendToAll" });
	  }
	
	  // Get a reference to the "sendToLast" Feature
	  mSendToLastFeature = mWorkitemType.getFeatureByBaseName("sendToLast");
	  if (mSendToLastFeature == null) {
		  throw new AnalysisEngineProcessException(AnnotatorInitializationException.FEATURE_NOT_FOUND,
				  new Object[] { getClass().getName(), "org.apache.uima.ducc.Workitem:sendToLast" });
	  }
  }
	  
  public Flow computeFlow(CAS aCAS) throws AnalysisEngineProcessException {
    return new FixedFlowObject(0);
  }

  class FixedFlowObject extends CasFlow_ImplBase {
    private int currentStep;
    private boolean internallyCreatedCas = false;

    /**
     * Create a new fixed flow starting at step <code>startStep</code> of the fixed sequence.
     * 
     * @param startStep
     *          index of mSequence to start at
     */
    private FixedFlowObject(int startStep) {
      this(startStep, false);
    }

    /**
     * Create a new fixed flow starting at step <code>startStep</code> of the fixed sequence.
     * 
     * @param startStep
     *          index of mSequence to start at
     * @param internallyCreatedCas
     *          true to indicate that this Flow object is for a CAS that was produced by a
     *          CasMultiplier within this aggregate.
     * 
     */
    private FixedFlowObject(int startStep, boolean internallyCreatedCas) {
      currentStep = startStep;
      this.internallyCreatedCas = internallyCreatedCas;
    }

    public Step next() throws AnalysisEngineProcessException {

      // If this is a work item CAS in a pipeline with an initial CM that has just been
      // to the CM then check if it should be sent to the last step, e.g. the CC.
      if (mStartsWithCasMultiplier && !internallyCreatedCas && currentStep == 1) {
        // Parent CAS has been to the initial CM, so see if a special flow has been requested.
        // Get an iterator only if the Workitem type is in the CAS's typesystem 
        // (avoids JCAS_TYPE_NOT_IN_CAS error)
 
    	FSIterator<FeatureStructure> it = this.getCas().getIndexRepository().getAllIndexedFS(mWorkitemType);
        if (it.isValid()) {
          FeatureStructure wi = it.get();
          it.moveToNext();
          if (it.isValid()) {
            throw new IllegalStateException("More than one instance of Workitem type");
          }
          if (wi.getBooleanValue(mSendToAllFeature)) {
        	// send WI-CAS to all delegates 
          }
          else if (wi.getBooleanValue(mSendToLastFeature)) {
        	// send to last delegate only
        	currentStep = mSequence.size() - 1;
          }
        }
        // No Workitem FS in CAS, WI-CAS is at end of flow
        else return new FinalStep();
      }

      if (currentStep >= mSequence.size()) {
        return new FinalStep(); // this CAS is cooked
      }

      // Send to next component in pipeline
      return new SimpleStep((String)mSequence.get(currentStep++));
    }

    public Flow newCasProduced(CAS newCas, String producedBy) throws AnalysisEngineProcessException {
      // start the new output CAS from the next node after the CasMultiplier that produced it
      // (there may be a CM in other than the first step)
      int i = 0;
      while (!mSequence.get(i).equals(producedBy))
        i++;
      return new FixedFlowObject(i + 1, true);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



uima-ducc-user/src/main/java/org/apache/uima/ducc/FlowController.java [56:192]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  private List<String> mSequence;
  private boolean mStartsWithCasMultiplier=false;
  private Type mWorkitemType;
  private Feature mSendToAllFeature;
  private Feature mSendToLastFeature;
  

  public void initialize(FlowControllerContext aContext) throws ResourceInitializationException {
    super.initialize(aContext);

    FlowConstraints flowConstraints = aContext.getAggregateMetadata().getFlowConstraints();
    mSequence = new ArrayList<String>();
    if (flowConstraints instanceof FixedFlow) {
      String[] sequence = ((FixedFlow) flowConstraints).getFixedFlow();
      mSequence.addAll(Arrays.asList(sequence));
    } else {
      throw new ResourceInitializationException(ResourceInitializationException.FLOW_CONTROLLER_REQUIRES_FLOW_CONSTRAINTS,
              new Object[]{this.getClass().getName(), "fixedFlow", aContext.getAggregateMetadata().getSourceUrlString()});
    }

    // Check if first delegate is a CasMultiplier.
    // Any other CMs will have no special treatment, 
    // i.e. parent will follow children thru the rest of the pipeline
    
    Iterator<Entry<String, AnalysisEngineMetaData>> aeIter = getContext().getAnalysisEngineMetaDataMap().entrySet().iterator();
    while (aeIter.hasNext()) {
      Entry<String, AnalysisEngineMetaData> entry = aeIter.next();
      AnalysisEngineMetaData md = entry.getValue();
      OperationalProperties op = md.getOperationalProperties();
      if (op.getOutputsNewCASes()) {
        if (mSequence.get(0).equals(entry.getKey())) {
          mStartsWithCasMultiplier = true;
        }
      } 
    }
  }


  public void typeSystemInit(TypeSystem aTypeSystem) throws AnalysisEngineProcessException {
	  // Get a reference to the "Workitem" Type
	  mWorkitemType = aTypeSystem.getType("org.apache.uima.ducc.Workitem");
	  if (mWorkitemType == null) {
		  throw new AnalysisEngineProcessException(AnnotatorInitializationException.TYPE_NOT_FOUND,
				  new Object[] { getClass().getName(), "org.apache.uima.ducc.Workitem" });
	  }
	
	  // Get a reference to the "sendToALL" Feature
	  mSendToAllFeature = mWorkitemType.getFeatureByBaseName("sendToAll");
	  if (mSendToAllFeature == null) {
		  throw new AnalysisEngineProcessException(AnnotatorInitializationException.FEATURE_NOT_FOUND,
				  new Object[] { getClass().getName(), "org.apache.uima.ducc.Workitem:sendToAll" });
	  }
	
	  // Get a reference to the "sendToLast" Feature
	  mSendToLastFeature = mWorkitemType.getFeatureByBaseName("sendToLast");
	  if (mSendToLastFeature == null) {
		  throw new AnalysisEngineProcessException(AnnotatorInitializationException.FEATURE_NOT_FOUND,
				  new Object[] { getClass().getName(), "org.apache.uima.ducc.Workitem:sendToLast" });
	  }
  }
	  
  public Flow computeFlow(CAS aCAS) throws AnalysisEngineProcessException {
    return new FixedFlowObject(0);
  }

  class FixedFlowObject extends CasFlow_ImplBase {
    private int currentStep;
    private boolean internallyCreatedCas = false;

    /**
     * Create a new fixed flow starting at step <code>startStep</code> of the fixed sequence.
     * 
     * @param startStep
     *          index of mSequence to start at
     */
    private FixedFlowObject(int startStep) {
      this(startStep, false);
    }

    /**
     * Create a new fixed flow starting at step <code>startStep</code> of the fixed sequence.
     * 
     * @param startStep
     *          index of mSequence to start at
     * @param internallyCreatedCas
     *          true to indicate that this Flow object is for a CAS that was produced by a
     *          CasMultiplier within this aggregate.
     * 
     */
    private FixedFlowObject(int startStep, boolean internallyCreatedCas) {
      currentStep = startStep;
      this.internallyCreatedCas = internallyCreatedCas;
    }

    public Step next() throws AnalysisEngineProcessException {

      // If this is a work item CAS in a pipeline with an initial CM that has just been
      // to the CM then check if it should be sent to the last step, e.g. the CC.
      if (mStartsWithCasMultiplier && !internallyCreatedCas && currentStep == 1) {
        // Parent CAS has been to the initial CM, so see if a special flow has been requested.
        // Get an iterator only if the Workitem type is in the CAS's typesystem 
        // (avoids JCAS_TYPE_NOT_IN_CAS error)
 
    	FSIterator<FeatureStructure> it = this.getCas().getIndexRepository().getAllIndexedFS(mWorkitemType);
        if (it.isValid()) {
          FeatureStructure wi = it.get();
          it.moveToNext();
          if (it.isValid()) {
            throw new IllegalStateException("More than one instance of Workitem type");
          }
          if (wi.getBooleanValue(mSendToAllFeature)) {
        	// send WI-CAS to all delegates 
          }
          else if (wi.getBooleanValue(mSendToLastFeature)) {
        	// send to last delegate only
        	currentStep = mSequence.size() - 1;
          }
        }
        // No Workitem FS in CAS, WI-CAS is at end of flow
        else return new FinalStep();
      }

      if (currentStep >= mSequence.size()) {
        return new FinalStep(); // this CAS is cooked
      }

      // Send to next component in pipeline
      return new SimpleStep((String)mSequence.get(currentStep++));
    }

    public Flow newCasProduced(CAS newCas, String producedBy) throws AnalysisEngineProcessException {
      // start the new output CAS from the next node after the CasMultiplier that produced it
      // (there may be a CM in other than the first step)
      int i = 0;
      while (!mSequence.get(i).equals(producedBy))
        i++;
      return new FixedFlowObject(i + 1, true);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



