|
12 | 12 | import java.util.Objects; |
13 | 13 | import java.util.Optional; |
14 | 14 | import java.util.Set; |
15 | | -import java.util.concurrent.atomic.AtomicInteger; |
| 15 | +import java.util.concurrent.atomic.AtomicBoolean; |
16 | 16 | import java.util.function.Predicate; |
17 | 17 | import java.util.stream.Collectors; |
18 | 18 |
|
@@ -55,33 +55,45 @@ public enum Target |
55 | 55 | } |
56 | 56 |
|
57 | 57 | /** |
58 | | - * Keeps dirty state of parallel jobs and marks the client file dirty after |
59 | | - * 20 dirty result. Background: marking the client dirty after every job |
60 | | - * sends too many update events to the GUI. |
| 58 | + * Throttles the dirty notification to the user interface. Background: |
| 59 | + * marking the client dirty after every job sends too many update events to |
| 60 | + * the user interface. |
61 | 61 | */ |
62 | 62 | private static class Dirtyable |
63 | 63 | { |
64 | | - private static final int THRESHOLD = 20; |
| 64 | + private static final long TIME_THRESHOLD_MS = 250; |
65 | 65 |
|
66 | 66 | private final Client client; |
67 | | - private AtomicInteger counter; |
| 67 | + private final AtomicBoolean dirtyState = new AtomicBoolean(false); |
| 68 | + private long lastUpdate = System.currentTimeMillis(); |
68 | 69 |
|
69 | 70 | public Dirtyable(Client client) |
70 | 71 | { |
71 | 72 | this.client = client; |
72 | | - this.counter = new AtomicInteger(); |
73 | 73 | } |
74 | 74 |
|
75 | | - public void markDirty() |
| 75 | + public synchronized void markDirty() |
76 | 76 | { |
77 | | - int count = counter.incrementAndGet(); |
78 | | - if (count % THRESHOLD == 0) |
| 77 | + long now = System.currentTimeMillis(); |
| 78 | + if (now - lastUpdate >= TIME_THRESHOLD_MS) |
| 79 | + { |
79 | 80 | client.markDirty(); |
| 81 | + dirtyState.set(false); |
| 82 | + lastUpdate = now; |
| 83 | + } |
| 84 | + else |
| 85 | + { |
| 86 | + dirtyState.set(true); |
| 87 | + } |
80 | 88 | } |
81 | 89 |
|
82 | | - public boolean isDirty() |
| 90 | + public synchronized void flushIfDue() |
83 | 91 | { |
84 | | - return counter.get() % THRESHOLD != 0; |
| 92 | + if (dirtyState.get()) |
| 93 | + { |
| 94 | + client.markDirty(); |
| 95 | + dirtyState.set(false); |
| 96 | + } |
85 | 97 | } |
86 | 98 | } |
87 | 99 |
|
@@ -248,8 +260,7 @@ protected IStatus run(IProgressMonitor monitor) |
248 | 260 | if (!jobs.isEmpty()) |
249 | 261 | runJobs(monitor, jobs); |
250 | 262 |
|
251 | | - if (!monitor.isCanceled() && dirtyable.isDirty()) |
252 | | - getClient().markDirty(); |
| 263 | + dirtyable.flushIfDue(); |
253 | 264 |
|
254 | 265 | if (repeatPeriod > 0) |
255 | 266 | schedule(repeatPeriod); |
|
0 commit comments