Package org.apache.uima.collection.base_cpm

Examples of org.apache.uima.collection.base_cpm.CasProcessor


      String previous = ""; // hold the previous name of the Cas Processor

      // Check the list of CP instances to check if its parallelizable
      for (int j = 0; j < cp_instance_list.size(); j++) {
        CasProcessor cp = (CasProcessor) cp_instance_list.get(j);
        String name = cp.getProcessingResourceMetaData().getName();
        // Check if the CP is parallelizable
        boolean parallizable = isParallizable(cp, name);

        // If Cas Processor is not parallizable and we have not yet hit a parallizable component
        // place the Cas Processor in a pipeline that supports single instance components
View Full Code Here


        UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                "UIMA_CPM_checkout_cp_from_container__FINEST",
                new Object[] { Thread.currentThread().getName(), container.getName() });
      }
      CasProcessor processor = container.getCasProcessor();
      try {
        if (processor instanceof AnalysisEngineImplBase) {
          //Integrated AEs already have added their metadata to the CasManager during
          //their initialization, so we don't need to do it again.
          //(Exception: when running from "old" CPM interface - where AEs are created outside
          // and passed in, the AE may not share a ResourceManager with the CPE.  In that case
          // we DO need to register its metadata.)
          if (((AnalysisEngine)processor).getResourceManager() == this.cpeFactory.getResourceManager())
            continue;       
        }
        ProcessingResourceMetaData md = processor.getProcessingResourceMetaData();
 
        if (md != null) {
          manager.addMetaData(md);
        }
      }
      finally {
        container.releaseCasProcessor(processor);
      }
    }
    for (int i = 0; i < consumerList.size(); i++) {
      ProcessingContainer container = (ProcessingContainer) consumerList.get(i);
      if (container.getStatus() == Constants.CAS_PROCESSOR_DISABLED) {
        continue; // skip over disabled CasProcessors
      }

      if (UIMAFramework.getLogger().isLoggable(Level.FINE)) {
        UIMAFramework.getLogger(this.getClass()).logrb(Level.FINE, this.getClass().getName(),
                "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                "UIMA_CPM_checkout_cp_from_container__FINEST",
                new Object[] { Thread.currentThread().getName(), container.getName() });
      }

      CasProcessor processor = container.getCasProcessor();
      try {
        if (processor instanceof AnalysisEngineImplBase) {
          //(Exception: when running from "old" CPM interface - where AEs are created outside
          // and passed in, the AE may not share a ResourceManager with the CPE.  In that case
          // we DO need to register its metadata.)
          if (((AnalysisEngine)processor).getResourceManager() == this.cpeFactory.getResourceManager())
            continue;        
        }
        ProcessingResourceMetaData md = processor.getProcessingResourceMetaData();
 
        if (md != null) {
          manager.addMetaData(md);
        }
      }
View Full Code Here

      for (int i = 0; i < annotatorList.size(); i++) {
        ProcessingContainer container = (ProcessingContainer) annotatorList.get(i);
        if (container.getStatus() == Constants.CAS_PROCESSOR_DISABLED) {
          continue; // skip over disabled CasProcessors
        }
        CasProcessor processor = container.getCasProcessor();
        if (processor instanceof CasObjectProcessor) {
          ((CasObjectProcessor) processor).typeSystemInit(cas.getTypeSystem());
        }
        container.releaseCasProcessor(processor);
      }
      for (int i = 0; i < consumerList.size(); i++) {
        ProcessingContainer container = (ProcessingContainer) consumerList.get(i);
        if (container.getStatus() == Constants.CAS_PROCESSOR_DISABLED) {
          continue; // skip over disabled CasProcessors
        }
        CasProcessor processor = container.getCasProcessor();
        if (processor instanceof CasObjectProcessor) {
          ((CasObjectProcessor) processor).typeSystemInit(cas.getTypeSystem());
        }
        container.releaseCasProcessor(processor);
      }
View Full Code Here

      UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
              "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_start_analysis__FINEST",
              new Object[] { Thread.currentThread().getName() });
    }
    // String lastDocId = "";
    CasProcessor processor = null;
    // This is used to hold an index of the current CasObject
    // int currentIndex = -1;
    boolean doneAlready = false;
    // If there are no CASes in the list, return false since there is nothing else to do
    if (aCasObjectList == null || aCasObjectList[0] == null) {
      if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) {
        UIMAFramework.getLogger(this.getClass()).logrb(Level.SEVERE, this.getClass().getName(),
                "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                "UIMA_CPM_invalid_cas_reference__SEVERE",
                new Object[] { Thread.currentThread().getName() });
      }
      return false;
    }
    Object[] casObjects = null;
    // Determine if the Cas'es contained in the CasList are of type CAS. Samples the first CAS in
    // the list.
    // The list contains CASes of the same type ( either CasData or CAS ). Mixed model not
    // supported.
    boolean isCasObject = aCasObjectList[0] instanceof CAS;
    // String docid = "";
    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
      UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
              "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_entering_pipeline__FINEST",
              new Object[] { Thread.currentThread().getName() });
    }

    ProcessingContainer container = null;
    // *******************************************
    // ** P R O C E S S I N G P I P E L I N E **
    // *******************************************
    // Send Cas Object through the processing pipeline.
    for (int i = 0; processContainers != null && i < processContainers.size(); i++) {
      if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
        UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_retrieve_container__FINEST",
                new Object[] { Thread.currentThread().getName(), String.valueOf(i) });
      }
      container = (ProcessingContainer) processContainers.get(i);
      synchronized (container) {
        // Check to see if the CasProcessor is available for processing
        if (!isProcessorReady(container.getStatus())) {
          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
            UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                    "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_container_not_ready__FINEST",
                    new Object[] { Thread.currentThread().getName(), container.getName() });
          }
          boolean breakTheLoop = (i == (processContainers.size() - 1));
          if (breakTheLoop && isCasObject) {
            releaseCases(aCasObjectList, true, container.getName());
            break;
          }

          // Skip any CasProcessor that is not ready to process
          continue;
        }
      }
      // Check if any of the Cas'es in the set has a required feature structure.
      if (!isCasObject && !container.processCas(aCasObjectList)) {
        if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
          UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                  "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_skip_CAS__FINEST",
                  new Object[] { Thread.currentThread().getName(), container.getName() });
        }
        container.incrementFilteredCount(aCasObjectList.length);
        container.logAbortedCases(aCasObjectList);
        continue;
      }

      long byteCount;
      // Flag controlling do-while loop that facilitates retries. Retries are defined in the
      // CasProcessor configuration.
      boolean retry = false;

      // Retry Loop.
      do {
        if (System.getProperty("SHOW_MEMORY") != null) {
          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
            UIMAFramework.getLogger(this.getClass()).logrb(
                    Level.FINEST,
                    this.getClass().getName(),
                    "process",
                    CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_show_memory__FINEST",
                    new Object[] { Thread.currentThread().getName(),
                        String.valueOf(Runtime.getRuntime().totalMemory() / 1024),
                        String.valueOf(Runtime.getRuntime().freeMemory() / 1024) });
          }
        }

        if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
          UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                  "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                  "UIMA_CPM_checkout_cp_from_container__FINEST",
                  new Object[] { Thread.currentThread().getName(), container.getName() });
        }
        threadState = 2004; // Entering dequeue()

        processor = container.getCasProcessor();
        if (processor == null) {
          if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) {
            UIMAFramework.getLogger(this.getClass()).logrb(Level.SEVERE, this.getClass().getName(),
                    "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_checkout_null_cp_from_container__SEVERE",
                    new Object[] { Thread.currentThread().getName(), container.getName() });
          }
          throw new ResourceProcessException(CpmLocalizedMessage.getLocalizedMessage(
                  CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                  "UIMA_CPM_EXP_invalid_component_reference__WARNING", new Object[] {
                      Thread.currentThread().getName(), "CasProcessor", "NULL" }), null);
        }
        // Check to see if the CasProcessor is available for processing
        // Container may have been disabled by another thread, so first check
        if (!isProcessorReady(container.getStatus())) {
          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
            UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                    "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_container_not_ready__FINEST",
                    new Object[] { Thread.currentThread().getName(), container.getName() });
          }
          if (container.getStatus() == Constants.CAS_PROCESSOR_KILLED) {
            container.releaseCasProcessor(processor);
            // Another thread has initiated CPM Abort. That Thread has already notified
            // the application of the Abort. Here we just return as the CPM has been
            // killed most likely due to excessive errors.
            return false;
          }

          // Skip any CasProcessor that is not ready to process
          break;
        }

        if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
          UIMAFramework.getLogger(this.getClass()).logrb(
                  Level.FINEST,
                  this.getClass().getName(),
                  "process",
                  CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                  "UIMA_CPM_checkedout_cp_from_container__FINEST",
                  new Object[] { Thread.currentThread().getName(), container.getName(),
                      processor.getClass().getName() });
        }
        try {
          if (processor instanceof CasDataProcessor) {
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_cas_data_processor__FINEST",
                      new Object[] { Thread.currentThread().getName(), container.getName(),
                          processor.getClass().getName() });
            }
            pTrTemp.startEvent(container.getName(), "Process", "");
            if (isCasObject == true) {
              CasData[] casDataObjects = new CasData[aCasObjectList.length];
              for (int casIndex = 0; casIndex < aCasObjectList.length; casIndex++) {
                casDataObjects[casIndex] = mConverter
                        .casContainerToCasData((CAS) aCasObjectList[casIndex]);
                if ((CAS) aCasObjectList[casIndex] != null) {
                  ((CAS) aCasObjectList[casIndex]).reset();
                }
              }

              casCache = (CAS[]) aCasObjectList;

              aCasObjectList = casDataObjects;
            }
            isCasObject = false;
            byteCount = 0;
            if (!retry) {

              for (int casIndex = 0; casIndex < aCasObjectList.length; casIndex++) {
                byteCount = getBytes(aCasObjectList[casIndex]);
                container.addBytesIn(byteCount);
              }
            }
            casObjects = aCasObjectList;
            long pStart = System.currentTimeMillis();
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_call_process__FINEST",
                      new Object[] { Thread.currentThread().getName(), container.getName(),
                          processor.getClass().getName() });

              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_casObjects_class__FINEST",
                      new Object[] { Thread.currentThread().getName(),
                          casObjects.getClass().getName() });
            }
            if (!(casObjects instanceof CasData[])) {
              if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
                UIMAFramework.getLogger(this.getClass()).logrb(
                        Level.FINEST,
                        this.getClass().getName(),
                        "process",
                        CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                        "UIMA_CPM_expected_casdata__FINEST",
                        new Object[] { Thread.currentThread().getName(),
                            casObjects.getClass().getName() });

              }
            }

            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_call_process__FINEST",
                      new Object[] { Thread.currentThread().getName(), container.getName(),
                          processor.getClass().getName() });
            }
            casObjects = ((CasDataProcessor) processor).process((CasData[]) casObjects);
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_call_process_completed__FINEST",
                      new Object[] { Thread.currentThread().getName(), container.getName(),
                          processor.getClass().getName() });
            }
            long pEnd = System.currentTimeMillis();
            container.incrementTotalTime((pEnd - pStart));
            if (casObjects != null) {
              if (processor instanceof CasDataConsumer) {
                container.addBytesOut(byteCount);
              } else {
                aCasObjectList = casObjects;
                if (!retry) {

                  for (int casIndex = 0; casIndex < aCasObjectList.length; casIndex++) {
                    byteCount = getBytes(aCasObjectList[casIndex]);
                    container.addBytesOut(byteCount);
                  }
                }
              }
            }
            pTrTemp.endEvent(container.getName(), "Process", "success");
          } else if (processor instanceof CasObjectProcessor) {
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_casobject_processor__FINEST",
                      new Object[] { Thread.currentThread().getName(), container.getName(),
                          processor.getClass().getName() });

              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_show_memory__FINEST",
                      new Object[] { Thread.currentThread().getName(),
                          String.valueOf(Runtime.getRuntime().totalMemory() / 1024),
                          String.valueOf(Runtime.getRuntime().freeMemory() / 1024) });
            }
            casList = new CAS[aCasObjectList.length];
            for (int casIndex = 0; casIndex < aCasObjectList.length; casIndex++) {
              if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
                UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
                        this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                        "UIMA_CPM_initialize_cas__FINEST",
                        new Object[] { Thread.currentThread().getName(), container.getName() });
              }
              if (aCasObjectList[casIndex] == null) {
                if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) {
                  UIMAFramework.getLogger(this.getClass()).logrb(
                          Level.SEVERE,
                          this.getClass().getName(),
                          "process",
                          CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                          "UIMA_CPM_casobjectlist_is_null__SEVERE",
                          new Object[] { Thread.currentThread().getName(), container.getName(),
                              String.valueOf(casIndex) });
                }
                break;
              }
              if (isCasObject == false) {
                // The following may be true if the CollectionReader is CasData based and this is
                // the first CasObject based annotator in the chain.
                if (casCache == null || casCache[casIndex] == null) {
                  casList[casIndex] = null;

                  while (casList[casIndex] == null) {
                    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
                      UIMAFramework.getLogger(this.getClass())
                              .logrb(
                                      Level.FINEST,
                                      this.getClass().getName(),
                                      "process",
                                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                                      "UIMA_CPM_get_cas_from_pool__FINEST",
                                      new Object[] { Thread.currentThread().getName(),
                                          container.getName() });
                    }
                    // Retrieve a Cas from Cas Pool. Wait max 10 millis for an instance
                    casList[casIndex] = casPool.getCas(0);
                    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
                      UIMAFramework.getLogger(this.getClass())
                              .logrb(
                                      Level.FINEST,
                                      this.getClass().getName(),
                                      "process",
                                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                                      "UIMA_CPM_got_cas_from_pool__FINEST",
                                      new Object[] { Thread.currentThread().getName(),
                                          container.getName() });
                    }
                  }
                  if (casList[casIndex] != null) {
                    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
                      UIMAFramework.getLogger(this.getClass())
                              .logrb(
                                      Level.FINEST,
                                      this.getClass().getName(),
                                      "process",
                                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                                      "UIMA_CPM_call_cas_reset__FINEST",
                                      new Object[] { Thread.currentThread().getName(),
                                          container.getName() });
                    }
                    casList[casIndex].reset();
                  }
                } else {
                  casList[casIndex] = casCache[casIndex];
                  casList[casIndex].reset();
                  if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
                    UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
                            this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                            "UIMA_CPM_nullify_cas__FINEST",
                            new Object[] { Thread.currentThread().getName(), container.getName() });
                  }
                  // Cas is used up
                  casCache[casIndex] = null;
                }

                // Convert CasData to CAS
                mConverter.casDataToCasContainer((CasData) aCasObjectList[casIndex],
                        casList[casIndex], true);
              } else {
                casList[casIndex] = (CAS) aCasObjectList[casIndex];
              }
              if (processor instanceof AnalysisEngine) {
                if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {

                  UIMAFramework.getLogger(this.getClass()).logrb(
                          Level.FINEST,
                          this.getClass().getName(),
                          "process",
                          CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                          "UIMA_CPM_call_process__FINEST",
                          new Object[] { Thread.currentThread().getName(), container.getName(),
                              processor.getClass().getName() });

                }
                threadState = 2005;

                pTrTemp.aggregate(((AnalysisEngine) processor).process(casList[casIndex]));
                if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
                  UIMAFramework.getLogger(this.getClass()).logrb(
                          Level.FINEST,
                          this.getClass().getName(),
                          "process",
                          CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                          "UIMA_CPM_call_process_completed__FINEST",
                          new Object[] { Thread.currentThread().getName(), container.getName(),
                              processor.getClass().getName() });
                }
              } else {
                pTrTemp.startEvent(container.getName(), "Process", "");
                threadState = 2006;
                if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
                  UIMAFramework.getLogger(this.getClass()).logrb(
                          Level.FINEST,
                          this.getClass().getName(),
                          "process",
                          CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                          "UIMA_CPM_call_process__FINEST",
                          new Object[] { Thread.currentThread().getName(), container.getName(),
                              processor.getClass().getName() });
                }
                ((CasObjectProcessor) processor).processCas(casList[casIndex]);
                if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
                  UIMAFramework.getLogger(this.getClass()).logrb(
                          Level.FINEST,
                          this.getClass().getName(),
                          "process",
                          CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                          "UIMA_CPM_call_process_completed__FINEST",
                          new Object[] { Thread.currentThread().getName(), container.getName(),
                              processor.getClass().getName() });
                }
                pTrTemp.endEvent(container.getName(), "Process", "success");
              }
            }
            isCasObject = true;
            aCasObjectList = casList;
          }

          // Release the CAS and notify listeners if the end of the
          // pipeline is reached.
          if ((releaseCAS) && (i == (processContainers.size() - 1))) {
            // This flag is used to prevent multiple notifications
            doneAlready = true;
            EntityProcessStatus aEntityProcStatus = new EntityProcessStatusImpl(pTrTemp);
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {

              UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
                      this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_notify_listeners__FINEST",
                      new Object[] { Thread.currentThread().getName() });
            }
            threadState = 2007;

            notifyListeners(aCasObjectList, isCasObject, aEntityProcStatus);
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
                      this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_done_notify_listeners__FINEST",
                      new Object[] { Thread.currentThread().getName() });

              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_releasing_cases__FINEST",
                      new Object[] { Thread.currentThread().getName(), container.getName(),
                          String.valueOf(releaseCAS), String.valueOf(true) });
            }
            if (casCache != null) {
              clearCasCache();
            }
            // Release CAS's.
            if (aCasObjectList instanceof CAS[]) {
              cpm.releaseCASes((CAS[]) aCasObjectList);
            }

            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
                      this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_done_releasing_cases__FINEST",
                      new Object[] { Thread.currentThread().getName(), container.getName() });
            }
          }

          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {

            UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                    "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_pipeline_completed__FINEST",
                    new Object[] { Thread.currentThread().getName() });
          }
          retry = false;
          // On successfull processing reset the restart counter. Restart counter determines how
          // many times to restart Cas Processor on the same CAS
          // Do this conditionally. If the CAS is to be dropped on Exception this restart counter
          // scope extends to the entire collection not just one CAS
          if (!cpm.dropCasOnException()) {
            container.resetRestartCount();
          }
        } catch (Exception e) {
          e.printStackTrace();
          if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) {

            UIMAFramework.getLogger(this.getClass()).logrb(
                    Level.SEVERE,
                    this.getClass().getName(),
                    "process",
                    CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_pipeline_exception__SEVERE",
                    new Object[] { Thread.currentThread().getName(), container.getName(),
                        e.getMessage() });

            UIMAFramework.getLogger(this.getClass()).log(Level.SEVERE,
                    Thread.currentThread().getName(), e);

            UIMAFramework.getLogger(this.getClass()).logrb(
                    Level.FINEST,
                    this.getClass().getName(),
                    "process",
                    CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_pipeline_exception__FINEST",
                    new Object[] { Thread.currentThread().getName(), container.getName(),
                        String.valueOf(container.isPaused()) });
          }

          EntityProcessStatusImpl enProcSt = new EntityProcessStatusImpl(pTrTemp);
          enProcSt.addEventStatus("Process", "Failed", e);
          threadState = 2008;

          notifyListeners(aCasObjectList, isCasObject, enProcSt);
          doneAlready = true;
          threadState = 2009;

          // Check the policy to determine what to do with the CAS on exception. Return the CAS back
          // to the pool
          // and stop the processing chain if required. The policy for what to do with the CAS on
          // exception is
          // defined in the CPE descriptor
          if (cpm.dropCasOnException()) {
            if (casCache != null) {
              clearCasCache();
            }
            if (aCasObjectList instanceof CAS[]) {
              cpm.invalidateCASes((CAS[]) aCasObjectList);
            }
            retry = false; // Dont retry. The CAS has been released
            UIMAFramework.getLogger(this.getClass()).logrb(
                    Level.WARNING,
                    this.getClass().getName(),
                    "process",
                    CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_drop_cas__WARNING",
                    new Object[] { Thread.currentThread().getName(), container.getName(),
                        processor.getClass().getName() });
          } else {
            retry = true; // default on Exception
          }
          // If the container is in pause state dont increment errors since one thread has already
          // done this. While the container is in pause state the CPM is attempting to re-connect
          // to a failed service. Once that is done, the container is going to be resumed. While
          // in pause state ALL threads using the container will be suspended.
          if (processor instanceof CasObjectNetworkCasProcessorImpl && container.isPaused()) {
            threadState = 2010;

            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
                      this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_container_paused_do_retry__FINEST",
                      new Object[] { Thread.currentThread().getName(), container.getName() });
            }

            // Do conditional release of CAS instances. The release occurs only if the CasProcessor
            // is the last one
            // in processing chain. This only releases instances of CAS checked out from the Cas
            // Pool. If not done, the
            // pool gets depleted and no more work will be done.
            releaseCases(casList, (i == (processContainers.size() - 1)), container.getName());

            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
                      this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_container_paused__FINEST",
                      new Object[] { Thread.currentThread().getName(), container.getName() });
            }
            // Release current Cas Processor before continuing with the next Cas Processor in the
            // pipeline
            if (processor != null) {
              container.releaseCasProcessor(processor);
              if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
                UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
                        this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                        "UIMA_CPM_ok_released_cp__FINEST",
                        new Object[] { Thread.currentThread().getName(), container.getName() });
              }
              processor = null;
            }
            try {
              pTrTemp.endEvent(container.getName(), "Process", "failed");
            } catch (Exception exc) {
              // Just ignore out-of-phase endEvent exceptions for now.
            }
            continue;
          }
          if (pauseContainer(container, e, threadId)) // container.isRemote() &&
          // container.isSingleFencedService() &&
          // threadId == null )
          {
            threadState = 2011;

            // Pause the container while the CPM is re-connecting to un-managed service
            // that is shared by all processing threads
            container.pause();
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {

              UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
                      this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_pausing_container__FINEST",
                      new Object[] { Thread.currentThread().getName(), container.getName() });
            }
            threadId = Thread.currentThread().getName();
          }

          if (processor instanceof CasDataProcessor
                  || (processor instanceof CasObjectProcessor && !(processor instanceof AnalysisEngine))) {
            try {
              pTrTemp.endEvent(container.getName(), "Process", "failed");
            } catch (Exception exc) {
              // Just ignore out-of-phase endEvent exceptions for now.
            }
          }
          try {
            // Increments error counter and determines if any threshold have been reached. If
            // the max error rate is reached, the CasProcessor can be configured as follows:
            // - terminates CPM when threshold is reached ( method below throws AbortCPMException)
            // - disables CasProcessor ( method below throws AbortCasProcessorException )
            // - continue, CasProcessor continues to run dispite error
            container.incrementCasProcessorErrors(e);

            container.releaseCasProcessor(processor);
            processor = null;
            if (cpm.dropCasOnException()) {
              // Cas has already been returned to the CAS pool. The policy requires to stop the
              // processing chain for this CAS and
              // to get another CAS for processing.
              return true;
            } else {
              container.incrementRetryCount(1);
              continue;
            }
          } // check if the exception should terminate the CPM
          catch (KillPipelineException ex) {
            try {
              handleKillPipeline(container);
              processor = null;
            } catch (Exception innerE) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.WARNING,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_exception_on_pipeline_kill__WARNING",
                      new Object[] { Thread.currentThread().getName(), container.getName(),
                          innerE.getMessage() });
            }
            // finally
            // {
            // // Throw Original Exception - Killing Pipeline
            // throw ex;
            // }
            throw ex;
          } catch (AbortCPMException ex) {
            try {
              handleAbortCPM(container, processor);
            } catch (Exception innerE) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.WARNING,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_exception_on_cpm_kill__WARNING",
                      new Object[] { Thread.currentThread().getName(), container.getName(),
                          innerE.getMessage() });
            }
            // finally
            // {
            // throw new AbortCPMException("Aborting CPM. CasProcessor::" + container.getName() + "
            // Configured to Abort the CPM.");
            // }
            throw ex;
          } // check if the CasProcessor is to be disabled due to excessive errors
          catch (AbortCasProcessorException ex) {
            try {
              handleAbortCasProcessor(container, processor);
              if (cpm.dropCasOnException()) {
                // Cas has already been returned to the CAS pool. The policy requires to stop the
                // processing chain for this CAS and
                // to get another CAS for processing.
                return true;
              } else {
                // Do conditional release of CAS instances. The release occurs only if the
                // CasProcessor is the last one
                // in processing chain. This only releases instances of CAS checked out from the Cas
                // Pool. If not done, the
                // pool gets depleted and no more work will be done.
                releaseCases(casList, (i == (processContainers.size() - 1)), container.getName());
              }
            } catch (ResourceProcessException rpe) {
              throw rpe;
            } catch (Exception rpe) {
              throw new ResourceProcessException(rpe);
            }

            break; // CasProcessor disabled move on to the next one
          } // check if need to redeploy the CasProcessor
          catch (ServiceConnectionException ex) {
            pTrTemp.startEvent(container.getName(), "Process", "");
            try {
              threadState = 2012;

              handleServiceException(container, processor, pTrTemp, ex);
              // processor = null;
              if (cpm.dropCasOnException()) {
                return true;
              } else {
                // Increment number of restarts
                container.incrementRestartCount(1);
                pTrTemp.endEvent(container.getName(), "Process", "success");
                continue; // retry the same CAS'es
              }
            } catch (ResourceProcessException rpe) {
              pTrTemp.endEvent(container.getName(), "Process", "failure");
              throw rpe;
            } catch (ResourceConfigurationException rpe) {
              if (rpe.getCause() != null && rpe.getCause() instanceof KillPipelineException) {
                try {
                  handleKillPipeline(container);
                  processor = null;
                } catch (Exception excep) {
                  // Just log the exception. We are killing the pipeline
                  if (UIMAFramework.getLogger().isLoggable(Level.WARNING)) {
                    UIMAFramework.getLogger(this.getClass()).logrb(
                            Level.WARNING,
                            this.getClass().getName(),
                            "process",
                            CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                            "UIMA_CPM_exception_on_pipeline_kill__WARNING",
                            new Object[] { Thread.currentThread().getName(), container.getName(),
                                excep.getMessage() });
                  }
                }
              }
              pTrTemp.endEvent(container.getName(), "Process", "failure");
              throw new ResourceProcessException(rpe.getCause());
            } catch (Exception rpe) {
              pTrTemp.endEvent(container.getName(), "Process", "failure");
              throw new ResourceProcessException(rpe);
            }
          } catch (SkipCasException ex) {
            try {
              // Release current Cas Processor before continuing with the next Cas Processor in the
              // pipeline
              if (processor != null) {
                container.releaseCasProcessor(processor);
              }

              handleSkipCasProcessor(container, aCasObjectList,
                      (i == (processContainers.size() - 1)));
            } catch (Exception sEx) {
              throw new ResourceProcessException(sEx);
            }
            processor = null;
            if (cpm.dropCasOnException()) {
              return true;
            } else {
              break;
            }
          } catch (Exception ex) {
            if (UIMAFramework.getLogger().isLoggable(Level.FINER)) {
              UIMAFramework.getLogger(this.getClass()).logrb(Level.FINER,
                      this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_exception__FINER",
                      new Object[] { Thread.currentThread().getName(), ex.getMessage() });
              ex.printStackTrace();
            }

          }
          // CAS may have already been dropped (released) due to dropCasOnException policy defined
          // in the CPE Descriptor
          if (!cpm.dropCasOnException()) {
            // Do conditional release of CAS instances. The release occurs only if the CasProcessor
            // is the last one
            // in processing chain. This only releases instances of CAS checked out from the Cas
            // Pool. If not done, the
            // pool gets depleted and no more work will be done.
            releaseCases(casList, (i == (processContainers.size() - 1)), container.getName());
            container.incrementRetryCount(1);
          }
        } // catch

        // Let the container take action if the end-of-batch marker has been reached.
        // End-of-batch marker is defined in the cpm configuration for every CasProcessor.
        // This marker is defined in the <checkpoint> section of the CasProcessor Definition
        // and corresponds to the attribute "batch". If end-of-batch marker is reached the container
        // invokes batchProcessComplete() on the CasProcessor
        if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {

          UIMAFramework.getLogger(this.getClass()).logrb(
                  Level.FINEST,
                  this.getClass().getName(),
                  "process",
                  CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                  "UIMA_CPM_end_of_batch__FINEST",
                  new Object[] { Thread.currentThread().getName(), container.getName(),
                      processor.getClass().getName() });
        }

        doEndOfBatchProcessing(container, processor, pTrTemp, aCasObjectList);
        processor = null;
      } while (retry); // retry loop

      if (processor != null) {
        String processorClassName = processor.getClass().getName();
        UIMAFramework.getLogger(this.getClass()).logrb(
                Level.FINEST,
                this.getClass().getName(),
                "process",
                CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                "UIMA_CPM_release_cp__FINEST",
                new Object[] { Thread.currentThread().getName(), container.getName(),
                    processor.getClass().getName(), String.valueOf(casCache == null) });

        container.releaseCasProcessor(processor);
        processor = null;
        if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
          UIMAFramework.getLogger(this.getClass()).logrb(
View Full Code Here

      UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
              "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_start_analysis__FINEST",
              new Object[] { Thread.currentThread().getName() });
    }
    // String lastDocId = "";
    CasProcessor processor = null;
    // This is used to hold an index of the current CasObject
    boolean doneAlready = false;
    // If there are no CASes in the list, return false since there is nothing else to do
    if (aCasObjectList == null || aCasObjectList[0] == null) {
      if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) {
        UIMAFramework.getLogger(this.getClass()).logrb(Level.SEVERE, this.getClass().getName(),
                "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                "UIMA_CPM_invalid_cas_reference__SEVERE",
                new Object[] { Thread.currentThread().getName() });
      }
      return false;
    }
    Object[] casObjects = null;
    // Determine if the Cas'es contained in the CasList are of type CAS. Samples the first CAS in
    // the list.
    // The list contains CASes of the same type ( either CasData or CAS ). Mixed model not
    // supported.
    boolean isCasObject = aCasObjectList[0] instanceof CAS;
    // String docid = "";
    if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
      UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
              "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_entering_pipeline__FINEST",
              new Object[] { Thread.currentThread().getName() });
    }

    ProcessingContainer container = null;
    String containerName = "";
    // *******************************************
    // ** P R O C E S S I N G P I P E L I N E **
    // *******************************************
    // Send Cas Object through the processing pipeline.
    for (int i = 0; processContainers != null && i < processContainers.size(); i++) {
      if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
        UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_retrieve_container__FINEST",
                new Object[] { Thread.currentThread().getName(), String.valueOf(i) });
      }
      // Retrieve the container. Container manages one or more instances of CAS Processor
      container = (ProcessingContainer) processContainers.get(i);
      // container can be disabled in multi-processing pipeline configurations. The container is
      // disabled
      // when one of the processing threads is in the process of restarting/reconnecting to a shared
      // fenced service. Shared, meaning that all processing pipelines use the same service for
      // invocations.
      // Container must be disabled to prevent concurrent restarts.
      if (containerDisabled(container) || filterOutTheCAS(container, isCasObject, aCasObjectList)) {
        continue;
      }
      containerName = container.getName();

      // Flag controlling do-while loop that facilitates retries. Retries are defined in the
      // CasProcessor configuration.
      boolean retry = false;
      do // Retry
      {

        try {
          if (System.getProperty("SHOW_MEMORY") != null) {
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_show_memory__FINEST",
                      new Object[] { Thread.currentThread().getName(),
                          String.valueOf(Runtime.getRuntime().totalMemory() / 1024),
                          String.valueOf(Runtime.getRuntime().freeMemory() / 1024) });
            }
          }

          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
            UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                    "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_checkout_cp_from_container__FINEST",
                    new Object[] { Thread.currentThread().getName(), containerName });
          }
          threadState = 2004;
          t1 = System.currentTimeMillis();
          // Get the CasProcessor from the pool managed by the container
          processor = container.getCasProcessor();
          timer01 += (System.currentTimeMillis() - t1);
          timer06 = ((ProcessingContainer_Impl) container).getFetchTime();
          if (processor == null) {
            if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) {
              UIMAFramework.getLogger(this.getClass()).logrb(Level.SEVERE,
                      this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_checkout_null_cp_from_container__SEVERE",
                      new Object[] { Thread.currentThread().getName(), containerName });
            }
            throw new ResourceProcessException(CpmLocalizedMessage.getLocalizedMessage(
                    CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_EXP_invalid_component_reference__WARNING", new Object[] {
                        Thread.currentThread().getName(), "CasProcessor", "NULL" }), null);
          }
          // Check to see if the CasProcessor is available for processing
          // The CasProcessor may have been disabled due to excessive errors and error policy
          // defined
          // in the CPE descriptor.
          if (!isProcessorReady(container.getStatus())) {
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
                      this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_container_not_ready__FINEST",
                      new Object[] { Thread.currentThread().getName(), containerName });
            }
            if (container.getStatus() == Constants.CAS_PROCESSOR_KILLED) {
              container.releaseCasProcessor(processor);
              // Another thread has initiated CPM Abort. That Thread has already notified
              // the application of the Abort. Here we just return as the CPM has been
              // killed most likely due to excessive errors.
              return false;
            }

            // Skip any CasProcessor that is not ready to process
            break;
          }

          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
            UIMAFramework.getLogger(this.getClass()).logrb(
                    Level.FINEST,
                    this.getClass().getName(),
                    "process",
                    CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_checkedout_cp_from_container__FINEST",
                    new Object[] { Thread.currentThread().getName(), containerName,
                        processor.getClass().getName() });
          }
          t1 = System.currentTimeMillis();
          // ************************* P E R F O R M A N A L Y S I S *************************
          if (processor instanceof CasDataProcessor) {
            invokeCasDataCasProcessor(container, processor, aCasObjectList, pTrTemp, isCasObject,
                    retry);
            isCasObject = false;
          } else if (processor instanceof CasObjectProcessor) {
            invokeCasObjectCasProcessor(container, processor, aCasObjectList, pTrTemp, isCasObject);
            isCasObject = true;
          }
          timer02 += (System.currentTimeMillis() - t1);
          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
            UIMAFramework.getLogger(this.getClass()).logrb(
                    Level.FINEST,
                    this.getClass().getName(),
                    "process",
                    CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                    "UIMA_CPM_analysis_successfull__FINEST",
                    new Object[] { Thread.currentThread().getName(), containerName,
                        processor.getClass().getName() });
          }
          retry = false;
          // On successfull processing reset the restart counter. Restart counter determines how
          // many times to restart Cas Processor on the same CAS
          // Do this conditionally. If the CAS is to be dropped on Exception this restart counter
          // scope extends to the entire collection not just one CAS
          if (!cpm.dropCasOnException()) {
            container.resetRestartCount();
          }
        } catch (Exception e) {
          retry = handleErrors(e, container, processor, pTrTemp, aCasObjectList, isCasObject);
          if (cpm.dropCasOnException()) {
            retry = false; // override
            return false; // Dont pass the CAS to the CasConsumer. CAS has been dropped
          }
        } finally {
          if (retry == false) {
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_end_of_batch__FINEST",
                      new Object[] { Thread.currentThread().getName(), containerName,
                          processor.getClass().getName() });
            }
            if (isProcessorReady(container.getStatus())) {
              t1 = System.currentTimeMillis();

              // Let the container take action if the end-of-batch marker has been reached.
              // End-of-batch marker is defined in the cpm configuration for every CasProcessor.
              // This marker is defined in the <checkpoint> section of the CasProcessor Definition
              // and corresponds to the attribute "batch". If end-of-batch marker is reached the
              // container
              // invokes batchProcessComplete() on the CasProcessor
              doEndOfBatch(container, processor, pTrTemp, aCasObjectList.length);
              timer03 += (System.currentTimeMillis() - t1);
            }
          } else {
            container.incrementRetryCount(1);
          }
          // Release current Cas Processor before continuing with the next Cas Processor in the
          // pipeline
          if (processor != null) {
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_release_cp__FINEST",
                      new Object[] { Thread.currentThread().getName(), containerName,
                          processor.getClass().getName(), String.valueOf(casCache == null) });
            }
            t1 = System.currentTimeMillis();
            doReleaseCasProcessor(container, processor);
            timer04 += (System.currentTimeMillis() - t1);
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_ok_release_cp__FINEST",
                      new Object[] { Thread.currentThread().getName(), containerName,
                          processor.getClass().getName(), String.valueOf(casCache == null) });
            }
            processor = null;
          }

        }
View Full Code Here

      String previous = ""; // hold the previous name of the Cas Processor

      // Check the list of CP instances to check if its parallelizable
      for (int j = 0; j < cp_instance_list.size(); j++) {
        CasProcessor cp = (CasProcessor) cp_instance_list.get(j);
        String name = cp.getProcessingResourceMetaData().getName();
        // Check if the CP is parallelizable
        boolean parallizable = isParallizable(cp, name);

        // If Cas Processor is not parallizable and we have not yet hit a parallizable component
        // place the Cas Processor in a pipeline that supports single instance components
View Full Code Here

        UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                "UIMA_CPM_checkout_cp_from_container__FINEST",
                new Object[] { Thread.currentThread().getName(), container.getName() });
      }
      CasProcessor processor = container.getCasProcessor();
      try {
        if (processor instanceof AnalysisEngineImplBase) {
          //Integrated AEs already have added their metadata to the CasManager during
          //their initialization, so we don't need to do it again.
          //(Exception: when running from "old" CPM interface - where AEs are created outside
          // and passed in, the AE may not share a ResourceManager with the CPE.  In that case
          // we DO need to register its metadata.)
          if (((AnalysisEngine)processor).getResourceManager() == this.cpeFactory.getResourceManager())
            continue;       
        }
        ProcessingResourceMetaData md = processor.getProcessingResourceMetaData();
 
        if (md != null) {
          manager.addMetaData(md);
        }
      }
      finally {
        container.releaseCasProcessor(processor);
      }
    }
    for (int i = 0; i < consumerList.size(); i++) {
      ProcessingContainer container = (ProcessingContainer) consumerList.get(i);
      if (container.getStatus() == Constants.CAS_PROCESSOR_DISABLED) {
        continue; // skip over disabled CasProcessors
      }

      if (UIMAFramework.getLogger().isLoggable(Level.FINE)) {
        UIMAFramework.getLogger(this.getClass()).logrb(Level.FINE, this.getClass().getName(),
                "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                "UIMA_CPM_checkout_cp_from_container__FINEST",
                new Object[] { Thread.currentThread().getName(), container.getName() });
      }

      CasProcessor processor = container.getCasProcessor();
      try {
        if (processor instanceof AnalysisEngineImplBase) {
          //(Exception: when running from "old" CPM interface - where AEs are created outside
          // and passed in, the AE may not share a ResourceManager with the CPE.  In that case
          // we DO need to register its metadata.)
          if (((AnalysisEngine)processor).getResourceManager() == this.cpeFactory.getResourceManager())
            continue;        
        }
        ProcessingResourceMetaData md = processor.getProcessingResourceMetaData();
 
        if (md != null) {
          manager.addMetaData(md);
        }
      }
View Full Code Here

      for (int i = 0; i < annotatorList.size(); i++) {
        ProcessingContainer container = (ProcessingContainer) annotatorList.get(i);
        if (container.getStatus() == Constants.CAS_PROCESSOR_DISABLED) {
          continue; // skip over disabled CasProcessors
        }
        CasProcessor processor = container.getCasProcessor();
        if (processor instanceof CasObjectProcessor) {
          ((CasObjectProcessor) processor).typeSystemInit(cas.getTypeSystem());
        }
        container.releaseCasProcessor(processor);
      }
      for (int i = 0; i < consumerList.size(); i++) {
        ProcessingContainer container = (ProcessingContainer) consumerList.get(i);
        if (container.getStatus() == Constants.CAS_PROCESSOR_DISABLED) {
          continue; // skip over disabled CasProcessors
        }
        CasProcessor processor = container.getCasProcessor();
        if (processor instanceof CasObjectProcessor) {
          ((CasObjectProcessor) processor).typeSystemInit(cas.getTypeSystem());
        }
        container.releaseCasProcessor(processor);
      }
View Full Code Here

   * @return - ProcessingContainer containing pool of CasProcessors
   */
  public ProcessingContainer deployCasProcessor(List aCasProcessorList, boolean redeploy)
          throws ResourceConfigurationException {
    String name = null;
    CasProcessor casProcessor = null;
    CasProcessorConfiguration casProcessorConfig = null;
    ProcessingContainer processingContainer = null;
    String deployModel = null;

    try {
      for (int i = 0; i < aCasProcessorList.size(); i++) {
        casProcessor = (CasProcessor) aCasProcessorList.get(i);
        // Container may have already been instantiated. This will be the case if the CPM is
        // configured for concurrent
        // processing ( more than one processing pipeline). There is only one container per
        // CasProcessor type.
        // So each instance of the same CasProcessor will be associated with a single container.
        // Inside the
        // container instances are pooled. When deploying the very first CasProcessor of each type,
        // the
        // container will be created and initialized. Any subsequent deployments of this
        // CasProcessor will
        // simply use it, and will be added to this container's instance pool.
        if (processingContainer == null) {
          ProcessingResourceMetaData metaData = casProcessor.getProcessingResourceMetaData();

          CpeCasProcessor cpeCasProcessor = (CpeCasProcessor) cpeFactory.casProcessorConfigMap
                  .get(metaData.getName());
          if (engine != null) {
            boolean parallelizable = engine.isParallizable(casProcessor, metaData.getName());
View Full Code Here

      if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
        UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_redeploying_cp__FINEST",
                new Object[] { Thread.currentThread().getName(), name });
      }
      CasProcessor casProcessor = produceIntegratedCasProcessor(casProcessorConfig.getDescriptor());
      casProcessorPool.addCasProcessor(casProcessor);
    } catch (ResourceConfigurationException e) {
      e.printStackTrace();
      throw e;
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.uima.collection.base_cpm.CasProcessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.