}
public void waitForProcessEnd(final String processInstanceId, int timeoutInMilliseconds) throws Exception {
Stopwatch stopwatch = new Stopwatch().start();
while (isProcessNotEnded(processInstanceId)) {
if (stopwatch.elapsedMillis() > timeoutInMilliseconds) {
throw new TimeoutException(String.format("Process %s not ended in %d milliseconds.",
processInstanceId, timeoutInMilliseconds));
}
LOG.info(String.format("Process instance %s not ended. Waiting 1s.", processInstanceId));
TimeUnit.SECONDS.sleep(1);