Example #1
0
  @Override
  public void run() {
    logger.info(this + " starting scoreboard worker thread...");

    // Run as long as the scoreboard is not done or the dropoff queue still contains entries
    while (running || !dropOffQ.isEmpty()) {
      if (!dropOffQ.isEmpty()) {

        // Queue swap (dropOffQ with processingQ)
        synchronized (swapDropoffQueueLock) {
          List<OperationExecution> temp = processingQ;
          processingQ = dropOffQ;
          dropOffQ = temp;
        }

        // Process all entries in the working queue
        while (!processingQ.isEmpty()) {
          OperationExecution result = processingQ.remove(0);
          TraceLabels traceLabel = result.getTraceLabel();

          // Process this operation by its label
          switch (traceLabel) {
            case STEADY_STATE_TRACE_LABEL:
              processSteadyStateResult(result);
              break;
            case LATE_LABEL:
              processLateStateResult(result);
              break;
            default:
              // Not processed
              break;
          }
        }
      } else {
        // Wait some time, until the dropOffQ fills up
        try {
          Thread.sleep(1000);
        } catch (InterruptedException tie) {
          logger.info(this + " worker thread interrupted.");
        }
      }
    }

    // Debugging
    logger.debug(this + " drop off queue size (should be 0): " + dropOffQ.size());
    logger.debug(this + " processing queue size (should be 0): " + processingQ.size());
    logger.debug(this + " worker thread finished!");
  }