Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,31 @@
* is too costly. The monitor will accept any number of calls to
* {@link #worked()}, and will scale the actual reported work appropriately
* so that the progress never quite completes.
* <p>Note, this monitor will only report progress if the thread calling it is the same as the thread that created it.</p>
*/
public class InfiniteProgress {
private final int MAX_TICKS = 172; // will be reached after ~ 1 Billion #worked()
private int worked;
private int nextTickAfter = 4;
private int workReported;
private final IProgressMonitor monitor;
private final Thread myThread;

protected InfiniteProgress(IProgressMonitor monitor) {
this.monitor = monitor;
myThread = Thread.currentThread();
}

public void beginTask(String name) {
monitor.beginTask(name, MAX_TICKS);
if (myThread == Thread.currentThread()) {
monitor.beginTask(name, MAX_TICKS);
}
}

public synchronized void subTask(String name) {
monitor.subTask(name);
if (myThread == Thread.currentThread()) {
monitor.subTask(name);
}
}

public synchronized void worked() {
Expand All @@ -49,7 +56,9 @@ public synchronized void worked() {
nextTickAfter = 1 + (int) (nextTickAfter * 1.1f);
if (workReported < MAX_TICKS) {
workReported++;
monitor.worked(1);
if (myThread == Thread.currentThread()) {
monitor.worked(1);
}
}
}
}
Expand Down
Loading