code: boolean awaitState(final InternalState expected) {
          synchronized (this) {
              final InternalState initialRequired = this.requiredState;
              for(;;) {
                  final InternalState required = this.requiredState;
                  // Stop in case the server failed to reach the state
                  if(required == InternalState.FAILED) {
                      return false;
                  // Stop in case the required state changed
                  } else if (initialRequired != required) {
                      return false;
                  }
                  final InternalState current = this.internalState;
                  if(expected == current) {
                      return true;
                  }
                  try {
                      wait();
                  } catch(InterruptedException e) {
                      Thread.currentThread().interrupt();
                      return false;
                  }
              }
          }
      }
docs: Await a state.
  
  @param expected the expected state
  @return {@code true} if the state was reached, {@code false} otherwise