public String waitForTask()

in src/main/java/com/vmware/vim25/mo/Task.java [158:204]


    public String waitForTask(int runningDelayInMillSecond, int queuedDelayInMillSecond) throws RuntimeFault, RemoteException, InterruptedException {
        TaskInfoState tState = null;
        int tries = 0;
        int maxTries = 3;
        Exception getInfoException = null;

        while ((tState == null) || tState.equals(TaskInfoState.running) || tState.equals(TaskInfoState.queued)) {
            tState = null;
            getInfoException = null;
            tries = 0;
            // under load getTaskInfo may return null when there really is valid task info, so we try 3 times to get it.
            while (tState == null) {
                tries++;
                if (tries > maxTries) {
                    if (getInfoException == null) {
                        throw new NullPointerException();
                    }
                    else if (getInfoException instanceof RuntimeFault) {
                        throw (RuntimeFault) getInfoException;
                    }
                    else if (getInfoException instanceof RemoteException) {
                        throw (RemoteException) getInfoException;
                    }
                    else {
                        throw new RuntimeException(getInfoException);
                    }
                }

                try {
                    tState = getTaskInfo().getState();
                }
                catch (Exception e) {
                    //silently catch 3 exceptions
                    getInfoException = e;
                }
            }

            // sleep for a specified time based on task state.
            if (tState.equals(TaskInfoState.running)) {
                Thread.sleep(runningDelayInMillSecond);
            }
            else {
                Thread.sleep(queuedDelayInMillSecond);
            }
        }
        return tState.toString();
    }