public void waitUntilEndCondition() throws InterruptedException {
      ReconfigureOnChangeTaskTest.this.addInfo(
          "Entering " + this.getClass() + ".waitUntilEndCondition()", this);

      int changeCount = 0;
      ReconfigureOnChangeTask lastRoct = null;
      CountDownLatch countDownLatch = null;

      while (changeCount < changeCountLimit) {
        ReconfigureOnChangeTask roct =
            (ReconfigureOnChangeTask) loggerContext.getObject(RECONFIGURE_ON_CHANGE_TASK);
        if (lastRoct != roct && roct != null) {
          lastRoct = roct;
          countDownLatch = new CountDownLatch(1);
          roct.addListener(new ChangeDetectedListener(countDownLatch));
        } else if (countDownLatch != null) {
          countDownLatch.await();
          countDownLatch = null;
          changeCount++;
        }
        Thread.yield();
      }
      ReconfigureOnChangeTaskTest.this.addInfo(
          "*****Exiting " + this.getClass() + ".waitUntilEndCondition()", this);
    }
  private CountDownLatch waitForReconfigurationToBeDone(ReconfigureOnChangeTask oldTask)
      throws InterruptedException {
    ReconfigureOnChangeTask roct = oldTask;
    while (roct == oldTask) {
      roct = getRegisteredReconfigureTask();
      Thread.yield();
    }

    CountDownLatch countDownLatch = new CountDownLatch(1);
    roct.addListener(new ReconfigurationDoneListener(countDownLatch));
    return countDownLatch;
  }
  private ReconfigureOnChangeTask waitForReconfigureOnChangeTaskToRun()
      throws InterruptedException {
    ReconfigureOnChangeTask roct = null;
    while (roct == null) {
      roct = getRegisteredReconfigureTask();
      Thread.yield();
    }

    CountDownLatch countDownLatch = new CountDownLatch(1);
    roct.addListener(new RunMethodInvokedListener(countDownLatch));
    countDownLatch.await();
    return roct;
  }