public State waitForStateChange(State state) {
    try {
      synchronized (theLock) {
        if (myState == State.STOPPED) {
          return State.STOPPED;
        }
        while (myState == state) {
          theLock.wait();
        }

        return myState;
      }
    } catch (InterruptedException e) {
      return null;
    }
  }
public State waitForStateChange(State state)