Future<T> future = submit(task);
return future.get();
}
catch (InterruptedException e)
{
throw new ServerScopedRuntimeException("Task execution was interrupted: " + task, e);
}
catch (ExecutionException e)
{
Throwable cause = e.getCause();
if (cause instanceof RuntimeException)
{
throw (RuntimeException) cause;
}
else if (cause instanceof Exception)
{
throw new ServerScopedRuntimeException("Failed to execute user task: " + task, cause);
}
else if (cause instanceof Error)
{
throw (Error) cause;
}
else
{
throw new ServerScopedRuntimeException("Failed to execute user task: " + task, cause);
}
}
}