コード例 #1
0
  // ----------------------------------------------------------------------------------------------------
  protected synchronized void taskDone(ParserTask task) {

    // Solo hace algo si la tarea finalizada era del trabajo en curso y no una antigua
    if (task.jobID.equals(getCurrentJobID())) {

      // Crea el status
      ParserWorkerStatus pws = new ParserWorkerStatus();
      pws.hotelDataList = task.hotelDataList;

      // Decrementa el numero de tareas en ejecucion
      m_numTasksForJob--;

      // Actua dependiendo de lo que quede
      if (m_numTasksForJob > 0) {

        // **** AVISAR DE QUE SE HA TERMINADO CON UNA DE LAS PAGINAS
        pws.type = PWStatusType.PageEnded;
        m_monitor.processingEnded(false, pws);

      } else if (m_numTasksForJob == 0) {

        // **** AVISAR DE QUE SE HA TERMINADO CON TODAS LAS PAGINAS
        Tracer._info("***** All parsing tasks have ended *********************************");
        pws.type = PWStatusType.AllPagesEnded;
        m_monitor.processingEnded(false, pws);

      } else {
        // No debería salir una cuenta negativa
        String MSG = "Task count for job decremented below zero";
        Tracer._error(MSG);
        m_monitor.processingEnded(true, MSG);
      }
    }
  }
コード例 #2
0
  // ----------------------------------------------------------------------------------------------------
  public synchronized void parseHtmlText(final String baseURL, final String htmlText) {

    // Si es la primera tarea del trabajo, actualiza el contador
    if (m_numTasksForJob == 0) {
      m_numTasksForJob++;
    }

    ParserTask task = new ParserTask();
    task.jobID = getCurrentJobID();
    task.htmlText = htmlText;
    task.baseURL = baseURL;
    try {
      m_tasksQueue.add(task);
      this.notifyAll();
    } catch (Exception ex) {
      Tracer._error("Error putting a new ParserTask in the queue", ex);
    }
  }