Package org.apache.uima.util

Examples of org.apache.uima.util.ProcessTrace


            casCache = ((WorkUnit) entity).getCas();
          }
        } else {
          artifact = (Object[]) entity;
        }
        ProcessTrace pT = getProcessTrace();

        Object[] cases = artifact;

        // Check if the artifact is actually an EOFToken. If so, this is
        // marker that indicates end of processing. The assumption is that
View Full Code Here


    // Dequeue first bundle
    artifact = workQueue.dequeue();
    maybeLogFinest("UIMA_CPM_dequeued_artifact__FINEST", workQueue.getName());
    if (artifact != null) {
      try {
        ProcessTrace pT = new ProcessTrace_impl(cpm.getPerformanceTuningSettings());
        if (artifact instanceof Object[]) {
          Object[] oList = (Object[]) artifact;
          // Only consume CASs
          if (oList[0] != null && !(oList[0] instanceof EOFToken)) {
            maybeLogFinest("UIMA_CPM_call_processNext__FINEST");
View Full Code Here

       
        if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
          logFinest("UIMA_CPM_container_status__FINEST",
              container.getName(), String.valueOf(container.getStatus()));
        }
        ProcessTrace pTrTemp = new ProcessTrace_impl(cpm.getPerformanceTuningSettings());
        pTrTemp.startEvent(container.getName(), "End of Batch", "");
        try {
          CasProcessorDeployer deployer = container.getDeployer();

          if (deployer != null) {
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              logFinest("UIMA_CPM_undeploy_cp_instances__FINEST", container.getName(), deployer.getClass().getName());
            }
            deployer.undeploy();
          }
          container.destroy();
        } catch (Exception e) {

          logWarning("UIMA_CPM_exception_during_cp_stop__WARNING", container.getName(), e.getMessage());
        } finally {
          pTrTemp.endEvent(container.getName(), "End of Batch", "");
          if (processingUnitProcessTrace != null) {
            this.processingUnitProcessTrace.aggregate(pTrTemp);
          }
        }
      }
View Full Code Here

  protected void setUp() throws Exception {
    super.setUp();
  }

  public void testStartAndEndEvent() {
    ProcessTrace pt = new ProcessTrace_impl();
    // should be nothing on event list
    Assert.assertTrue(pt.getEvents().isEmpty());
    // start two events
    pt.startEvent("c1", "t1", "testing");
    pt.startEvent("c1", "t2", "testing");
    // should be nothing on event list until both are closed
    Assert.assertTrue(pt.getEvents().isEmpty());
    pt.endEvent("c1", "t2", "success");
    Assert.assertTrue(pt.getEvents().isEmpty());
    pt.endEvent("c1", "t1", "success");
    Assert.assertEquals(1, pt.getEvents().size());

    // start two more events
    pt.startEvent("c2", "t1", "testing");
    pt.startEvent("c2", "t2", "testing");
    // close one and start another
    pt.endEvent("c2", "t2", "testing");
    Assert.assertEquals(1, pt.getEvents().size());
    pt.startEvent("c2", "t3", "testing");
    pt.endEvent("c2", "t3", "testing");
    Assert.assertEquals(1, pt.getEvents().size());
    // start another event and then end the original event
    pt.startEvent("c2", "t4", "testing");
    pt.endEvent("c2", "t1", "success");
    Assert.assertEquals(2, pt.getEvents().size());

    // verify contents of the ProcessTrace
    List<ProcessTraceEvent> evts = pt.getEvents();
    ProcessTraceEvent evt0 = (ProcessTraceEvent) evts.get(0);
    Assert.assertEquals("c1", evt0.getComponentName());
    Assert.assertEquals("t1", evt0.getType());
    Assert.assertEquals("testing", evt0.getDescription());
    Assert.assertEquals("success", evt0.getResultMessage());
View Full Code Here

  /*
   * Test for List getEventsByComponentName(String, boolean)
   */
  public void testGetEventsByComponentName() {
    ProcessTrace pt = new ProcessTrace_impl();
    // create some events
    pt.startEvent("c1", "t1", "testing");
    pt.startEvent("c1", "t2", "testing");
    pt.endEvent("c1", "t2", "success");
    pt.endEvent("c1", "t1", "success");
    pt.startEvent("c2", "t1", "testing");
    pt.startEvent("c2", "t2", "testing");
    pt.endEvent("c2", "t2", "testing");
    pt.startEvent("c2", "t3", "testing");
    pt.endEvent("c2", "t3", "testing");
    pt.startEvent("c2", "t4", "testing");
    pt.endEvent("c2", "t1", "success");

    // get top-level events for component c1
    List<ProcessTraceEvent> c1evts = pt.getEventsByComponentName("c1", false);
    Assert.assertEquals(1, c1evts.size());
    ProcessTraceEvent evt = (ProcessTraceEvent) c1evts.get(0);
    Assert.assertEquals(evt.getType(), "t1");

    // get all events for component c1
    c1evts = pt.getEventsByComponentName("c1", true);
    Assert.assertEquals(2, c1evts.size());
    evt = (ProcessTraceEvent) c1evts.get(1);
    Assert.assertEquals(evt.getType(), "t2");

    // get top-level events for component c2
    List<ProcessTraceEvent> c2evts = pt.getEventsByComponentName("c2", false);
    Assert.assertEquals(1, c2evts.size());
    evt = (ProcessTraceEvent) c2evts.get(0);
    Assert.assertEquals(evt.getType(), "t1");

    // get all events for component c2
    c2evts = pt.getEventsByComponentName("c2", true);
    Assert.assertEquals(4, c2evts.size());
    evt = (ProcessTraceEvent) c2evts.get(3);
    Assert.assertEquals(evt.getType(), "t4");
  }
View Full Code Here

  /*
   * Test for List getEventsByType(String, boolean)
   */
  public void testGetEventsByType() {
    ProcessTrace pt = new ProcessTrace_impl();
    // create some events
    pt.startEvent("c1", "t1", "testing");
    pt.startEvent("c1", "t2", "testing");
    pt.endEvent("c1", "t2", "success");
    pt.endEvent("c1", "t1", "success");
    pt.startEvent("c2", "t1", "testing");
    pt.startEvent("c2", "t2", "testing");
    pt.endEvent("c2", "t2", "testing");
    pt.startEvent("c3", "t1", "testing");
    pt.endEvent("c3", "t1", "testing");
    pt.startEvent("c2", "t3", "testing");
    pt.endEvent("c2", "t1", "success");

    // get top-level events of type t1
    List<ProcessTraceEvent> t1evts = pt.getEventsByType("t1", false);
    Assert.assertEquals(2, t1evts.size());
    ProcessTraceEvent evt = (ProcessTraceEvent) t1evts.get(0);
    Assert.assertEquals(evt.getComponentName(), "c1");
    evt = (ProcessTraceEvent) t1evts.get(1);
    Assert.assertEquals(evt.getComponentName(), "c2");

    // get all events for type t1
    t1evts = pt.getEventsByType("t1", true);
    Assert.assertEquals(3, t1evts.size());
    evt = (ProcessTraceEvent) t1evts.get(2);
    Assert.assertEquals(evt.getComponentName(), "c3");
  }
View Full Code Here

                new Object[] { Thread.currentThread().getName() });
      }
      return;
    }
    isRunning = true;
    ProcessTrace localTrace = new ProcessTrace_impl(cpm.getPerformanceTuningSettings());
    while (cpm.isRunning()) {

      casList = null;
      casObjectList = null;
      synchronized (cpm.lockForPause) {
        if (cpm.isPaused()) {
          try {
            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_cr__FINEST",
                      new Object[] { Thread.currentThread().getName() });
            }
            // Wait until resumed
            cpm.lockForPause.wait();
          } catch (Exception e) {
          }
          if (!cpm.isRunning()) {
            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_resume_cr__FINEST",
                    new Object[] { Thread.currentThread().getName() });
          }
        }
      }

      try {
        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_hasnext__FINEST",
                  new Object[] { Thread.currentThread().getName() });
        }
        threadState = 1004; // Entering hasNext()

        // start the CR event
        localTrace.startEvent(collectionReader.getProcessingResourceMetaData().getName(),
                "Process", "");
        crEventCompleted = false;
        if (collectionReader.hasNext()) {
          localTrace.endEvent(collectionReader.getProcessingResourceMetaData().getName(),
                  "Process", "success");
          crEventCompleted = true;

          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_cr__FINEST",
                    new Object[] { Thread.currentThread().getName() });
          }
          casObjectList = readNext(readerFetchSize);
          if (casObjectList != null) {
            if (casObjectList instanceof CAS[]) {
              boolean releasedCas = false;
              for (int i = 0; i < casObjectList.length && casObjectList[i] != null; i++) {
                ChunkMetadata meta = CPMUtils.getChunkMetadata((CAS) casObjectList[i]);
                if (meta != null) {
                  if (timedoutDocs.containsKey(meta.getDocId())) {
                    notifyListeners(casList[i], new ResourceProcessException(new SkipCasException(
                            "Dropping CAS due chunk Timeout. Doc Id::" + meta.getDocId()
                                    + " Sequence:" + meta.getSequence())));

                    casPool.releaseCas((CAS) casObjectList[i]);
//                    synchronized (casPool) {  // redundant, releaseCas call does this
//                      casPool.notifyAll();
//                    }
                    releasedCas = true;
                  }
                }
              }
              if (releasedCas) {
                continue;
              }
            }
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(
                      Level.FINEST,
                      this.getClass().getName(),
                      "process",
                      CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_place_cas_in_queue__FINEST",
                      new Object[] { Thread.currentThread().getName(),
                          String.valueOf(casObjectList.length) });
            }
            // Prevent processing of new CASes if the CPM has been
            // killed hard. Allow processing of CASes
            // while the CPM is in normal shutdown state.
            // (Moved this code inside if (casObjectList != null)
            // block to avoid NullPointerException. -Adam
            if (cpm.isRunning() == true
                    || (cpm.isRunning() == false && cpm.isHardKilled() == false)) {
              threadState = 1005; // Entering enqueue
              workQueue.enqueue(casObjectList);
//              synchronized (workQueue) { // redundant, enqueue does this
//                workQueue.notifyAll();
//              }
              threadState = 1006; // Done Entering enqueue
              entityCount += casObjectList.length;
              if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
                UIMAFramework.getLogger(this.getClass()).logrb(
                        Level.FINEST,
                        this.getClass().getName(),
                        "process",
                        CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                        "UIMA_CPM_placed_cas_in_queue__FINEST",
                        new Object[] { Thread.currentThread().getName(),
                            String.valueOf(casObjectList.length) });
              }
            } else {
              break; // CPM has been killed
            }
          } else {
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
                      this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
                      "UIMA_CPM_terminate_cr_thread__FINEST",
                      new Object[] { Thread.currentThread().getName() });
            }
            break; // Null should not be returned from getNext
            // unless the CPM is in shutdown mode
          }
        } else {
          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
            UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                    "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_processed_all__FINEST",
                    new Object[] { Thread.currentThread().getName() });
          }
          // Stops the CPM and all of the running threads.
          // cpm.stopIt(); APL - don't stop, just terminate this
          // thread, which CPMEngine has joined on
          break;

        }
        // Check if the CollectionReader retrieved expected number of
        // entities
        if (endOfProcessingReached()) {
          threadState = 1010; // End of processing

          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_processing__FINEST",
                    new Object[] { Thread.currentThread().getName() });
          }
          break;
        }
      } catch (Exception e) {
        // The following conditional is true if hasNext() has failed
        if (!crEventCompleted) {
          localTrace.endEvent(collectionReader.getProcessingResourceMetaData().getName(),
                  "Process", "failure");
        }
        // e.printStackTrace();
        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(), e.getMessage() });

          UIMAFramework.getLogger(this.getClass()).log(Level.FINER, e.getMessage(), e);
        }
        if (casList == null) {
          notifyListeners(null, e);
        } else {
          // Notify Listeners and release CAS's back to the cas pool.
          for (int i = 0; casList != null && i < casList.length; i++) {
            if (casList[i] != null) {
              notifyListeners(casList[i], e);
              casPool.releaseCas(casList[i]);
              casList[i] = null;
//              synchronized (casPool) { // redundant, releaseCas does this
//                casPool.notifyAll();
//              }

            } else {
              notifyListeners(null, e);
            }
            casList = null;
          }

        }
      } finally {
        // Clear all events
        synchronized (globalSharedProcessTrace) {
          globalSharedProcessTrace.aggregate(localTrace);
        }
        localTrace.clear();
      }
      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_cpm_running_status__FINEST",
View Full Code Here

   *          exception to propagate to callback listeners
   */
  private void notifyListeners(CAS aCas, Exception anException) {
    for (int i = 0; callbackListeners != null && i < callbackListeners.size(); i++) {
      StatusCallbackListener statCL = (StatusCallbackListener) callbackListeners.get(i);
      ProcessTrace prTrace = new ProcessTrace_impl(cpm.getPerformanceTuningSettings());
      EntityProcessStatusImpl aEntityProcStatus = new EntityProcessStatusImpl(prTrace);
      aEntityProcStatus.addEventStatus("Collection Reader Failure", "failed", anException);
      // Notify the listener that the Cas has been processed
      CPMEngine.callEntityProcessCompleteWithCAS(statCL, aCas, aEntityProcStatus);
//      statCL.entityProcessComplete(aCas, aEntityProcStatus);
View Full Code Here

        out = new FileOutputStream(fileName);
        synchPointOut = new FileOutputStream(synchPointFileName);
        s = new ObjectOutputStream(out);
        SynchPoint synchPoint = cpm.getSynchPoint();

        ProcessTrace pTrace = cpm.getPerformanceReport();
        CheckpointData targetToSave = null;
        if (pTrace != null) {
          if (synchPoint != null) {
            if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
              UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST,
View Full Code Here

        FileInputStream in = new FileInputStream(file);
        stream = new ObjectInputStream(in);
        if (stream != null) {
          anObject = stream.readObject();
          if (anObject != null && anObject instanceof CheckpointData) {
            ProcessTrace processTrace = ((CheckpointData) anObject).getProcessTrace();
            printStats(processTrace);
          }
        }
      }
      file = new File(synchPointFileName);
View Full Code Here

TOP

Related Classes of org.apache.uima.util.ProcessTrace

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.