@Override
public void run() {
String previousTaskId = null;
while (queueTasks.size() > 0) {
Task task = queueTasks.remove(0);
runCount++;
fireBefore(task);
if (this.cancelToken.isCanceled()) {
task.cancel();
}
run(task);
// TODO exception, tratar
fireAfter(task);
Application.getMessageManager().publish(
false,
new TaskExecutionMessage(false, getTaskSession(), task,
previousTaskId));
previousTaskId = task.getId();
Collection<Task> discardedTasks = new ArrayList<Task>();
if (task.getStatus().equals(TaskStatus.ERROR)) {
for (Task otherTask : queueTasks) {
otherTask.registerStatus(TaskStatus.DISCARDED);
discardedTasks.add(otherTask);
}
queueTasks.clear();
runCount += discardedTasks.size();
for (Task discardedTask : discardedTasks) {
fireBefore(discardedTask);
fireAfter(discardedTask);
Application.getMessageManager().publish(
false,
new TaskEventMessage(discardedTask, getTaskSession(),
TaskEventType.DISCARDED));
Application.getMessageManager().publish(
false,
new TaskExecutionMessage(false, getTaskSession(), discardedTask,
previousTaskId));
previousTaskId = discardedTask.getId();
}
}
Runnable runnable = buildRunnable(task, discardedTasks);
if (runnable == null) {
return;
}
if (Application.getTaskManager().invokeTaskMethodsOnEDT()) {
if (task.isWaitForEDT()) {
try {
SwingUtilities.invokeAndWait(runnable);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {