de.intarsys.tools.concurrent.TaskSequence Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of isrt Show documentation
Show all versions of isrt Show documentation
The basic runtime tools and interfaces for intarsys components.
/*
* intarsys consulting GmbH
* all rights reserved
*
*/
package de.intarsys.tools.concurrent;
import java.util.ArrayList;
import java.util.List;
/**
* experimental
*/
public class TaskSequence extends AbstractFutureTask {
private List tasks = new ArrayList();
private String labelPrefix;
private Runnable currentTask = null;
public TaskSequence(String labelPrefix) {
super();
// setWorkTotal(0);
this.labelPrefix = labelPrefix;
}
public void addTask(Runnable task, int percent) {
tasks.add(new TaskStep(this, task, percent));
// setWorkTotal(getWorkTotal() + percent);
}
@Override
protected R compute() throws Exception {
try {
R result = null;
for (Runnable task : tasks) {
synchronized (this) {
currentTask = task;
}
task.run();
if (isCancelled()) {
return null;
}
}
return result;
} finally {
synchronized (this) {
currentTask = null;
}
}
}
protected String getLabelPrefix() {
return labelPrefix;
}
protected String getLabelSuffix() {
Runnable tempTask;
synchronized (this) {
tempTask = currentTask;
}
return "";
}
public void setLabelPrefix(String labelPrefix) {
this.labelPrefix = labelPrefix;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy