class SequenceResponseGuard {

    public void waitForResponses(final WilmaHttpRequest stubbedRequest, final WilmaSequence actualSequence) throws InterruptedException {
        String wilmaLoggerId = stubbedRequest.getWilmaMessageId();
        boolean allResponsesArrived = actualSequence.checkIfAllResponsesArrived(wilmaLoggerId);
        int timeWaited = 0;
        getProperties();
        int waitInterval = properties.getWaitInterval();
        int timeout = properties.getTimeout();
        while (!allResponsesArrived) {
            Thread.sleep(waitInterval);
            timeWaited += waitInterval;
            if (timeWaited > timeout) {
                throw new ResponseTimeoutException(TIMEOUT_ERROR_MESSAGE);
            }
            allResponsesArrived = actualSequence.checkIfAllResponsesArrived(wilmaLoggerId);
        }

    }

}