if (workType == DO) {
// wait for completion
try {
worker.waitForCompletion();
} catch (InterruptedException e) {
WorkException workException = new WorkException("Work submission thread was interrupted", e);
workException.setErrorCode(INTERNAL);
throw workException;
}
// if work threw an exception, rethrow it
WorkException workCompletedException = worker.getWorkException();
if (workCompletedException != null) {
throw workCompletedException;
}
} else if (workType == START) {
// wait for work to start
try {
worker.waitForStart();
} catch (InterruptedException e) {
WorkException workException = new WorkException("Work submission thread was interrupted", e);
workException.setErrorCode(INTERNAL);
throw workException;
}
// if work threw a rejection exception, rethrow it (it is the exception for timeout)
WorkException workCompletedException = worker.getWorkException();
if (workCompletedException instanceof WorkRejectedException) {
throw workCompletedException;
}
}