class WaitingOutOfStateHandler extends OutOfStateHandlerImp {

  @Override
  public void handleOutOfState(StateManagedComponent component) throws OutOfStateException {
    long start = new Date().getTime();
    
    while(!component.retrieveComponentState().equals(this.getCorrectState().getComponentState())) {
      long now = new Date().getTime();
      if (now - start > maxWaitTimeMs())
        break;
      else {
        LifecycleHelper.waitQuietly(intervalToCheckMs());
      }
    }
    if(!component.retrieveComponentState().equals(this.getCorrectState().getComponentState()))
      throw new OutOfStateException("Expected state: " + this.getCorrectState().getClass().getSimpleName() + " but got " + component.retrieveComponentState().getClass().getSimpleName());
  }

  public  WaitingOutOfStateHandler();

}