}
throw catchedException;
}
private VcObject waitForCompletionIntenal() throws Exception {
Task task = getManagedObject();
StatsType oldSrc = Profiler.pushInc(StatsType.VC_TASK_WAIT, getType());
long lastWaitStartedNanos ;
long waitFinishedNanos = System.nanoTime();
state = task.getInfo().getState();
while (state != State.success) {
boolean normalWaitCompletion = false; // wait() not interrupted.
switch (state) {
case success:
break;
case error:
completionTimeNanos = waitFinishedNanos;
logTaskError(task);
assistBadTaskCompletion();
throw task.getInfo().getError();
case queued:
case running:
lastWaitStartedNanos = System.nanoTime();
try {
/* Wait for a completion notification from VcEventListener. */
isWaiting = true;
wait(TimeUnit.NANOSECONDS.toMillis(getWaitIntervalNanos()));
normalWaitCompletion = true;
} catch (InterruptedException e) {
/* Continue after checks. */
} finally {
isWaiting = false;
waitFinishedNanos = System.nanoTime();
lastWaitTimeNanos = waitFinishedNanos - lastWaitStartedNanos;
totalWaitTimeNanos += lastWaitTimeNanos;
}
break;
default:
AuAssert.check(false);
}
/*
* TODO: taskInfo reload might not be always necessary. If the task has
* no result, callers likely care only about success/error state which
* could be obtained from Event Listener without talking to VC.
*/
state = task.getInfo().getState();
verifyWaitCompletion(normalWaitCompletion);
}
AuAssert.check(taskCompleted());
logger.debug("task " + type + "completed");
completionTimeNanos = waitFinishedNanos;
assistBadTaskCompletion();
if (!(type.getTargetClass() == Void.class)) {
taskResult = task.getInfo().getResult();
if (taskResult instanceof ManagedObjectReference) {
if (type == TaskType.Snapshot) {
VcVirtualMachineImpl vm = (VcVirtualMachineImpl)parent;
vm.update();
result = vm.getSnapshot((ManagedObjectReference)taskResult);