Rename task.lastException -> task.exception

This commit is contained in:
huanghongxun
2019-02-25 22:17:30 +08:00
parent 8f2a1030bc
commit eeef76594f
6 changed files with 24 additions and 25 deletions

View File

@@ -91,7 +91,7 @@ public class LibraryDownloadTask extends Task<Void> {
if (!isDependentsSucceeded()) {
// Since FileDownloadTask wraps the actual exception with DownloadException.
// We should extract it letting the error message clearer.
Throwable t = task.getLastException();
Exception t = task.getException();
if (t instanceof DownloadException)
throw new LibraryDownloadException(library, t.getCause());
else

View File

@@ -73,14 +73,14 @@ public abstract class Task<T> {
}
// last exception
private Exception lastException;
private Exception exception;
public Exception getLastException() {
return lastException;
public Exception getException() {
return exception;
}
void setLastException(Exception e) {
lastException = e;
void setException(Exception e) {
exception = e;
}
/**
@@ -595,14 +595,14 @@ public abstract class Task<T> {
@Override
public void execute() throws Exception {
action.execute(isDependentsSucceeded(), Task.this.getLastException());
action.execute(isDependentsSucceeded(), Task.this.getException());
if (!isDependentsSucceeded()) {
setSignificance(TaskSignificance.MINOR);
if (Task.this.getLastException() == null)
if (Task.this.getException() == null)
throw new CancellationException();
else
throw Task.this.getLastException();
throw Task.this.getException();
}
}

View File

@@ -33,7 +33,7 @@ public final class TaskExecutor {
private final Task<?> firstTask;
private final List<TaskListener> taskListeners = new LinkedList<>();
private Exception lastException;
private Exception exception;
private final AtomicInteger totTask = new AtomicInteger(0);
private CompletableFuture<Boolean> future;
@@ -45,8 +45,8 @@ public final class TaskExecutor {
taskListeners.add(taskListener);
}
public Exception getLastException() {
return lastException;
public Exception getException() {
return exception;
}
public TaskExecutor start() {
@@ -148,7 +148,7 @@ public final class TaskExecutor {
boolean isDependentsSucceeded = dependentsException == null;
if (!isDependentsSucceeded && task.isRelyingOnDependents()) {
task.setLastException(dependentsException);
task.setException(dependentsException);
rethrow(dependentsException);
}
@@ -174,7 +174,7 @@ public final class TaskExecutor {
if (!isDependenciesSucceeded && task.isRelyingOnDependencies()) {
Logging.LOG.severe("Subtasks failed for " + task.getName());
task.setLastException(dependenciesException);
task.setException(dependenciesException);
rethrow(dependenciesException);
}
@@ -193,18 +193,18 @@ public final class TaskExecutor {
throw new UncheckedThrowable(throwable);
Exception e = throwable instanceof UncheckedException ? (Exception) throwable.getCause() : (Exception) throwable;
if (e instanceof InterruptedException) {
task.setLastException(e);
task.setException(e);
if (task.getSignificance().shouldLog()) {
Logging.LOG.log(Level.FINE, "Task aborted: " + task.getName());
}
task.onDone().fireEvent(new TaskEvent(this, task, true));
taskListeners.forEach(it -> it.onFailed(task, e));
} else if (e instanceof CancellationException || e instanceof RejectedExecutionException) {
if (task.getLastException() == null)
task.setLastException(e);
if (task.getException() == null)
task.setException(e);
} else {
task.setLastException(e);
lastException = e;
task.setException(e);
exception = e;
if (task.getSignificance().shouldLog()) {
Logging.LOG.log(Level.FINE, "Task failed: " + task.getName(), e);
}