-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathTracker.java
More file actions
57 lines (47 loc) · 1.45 KB
/
Tracker.java
File metadata and controls
57 lines (47 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package org.dataloader.orchestration;
import org.dataloader.DataLoader;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
/**
* This needs HEAPS more work - heaps more - I am not sure if its just counts of call backs or what.
* <p>
* This is just POC stuff for now
*/
public class Tracker {
private final AtomicInteger stepCount = new AtomicInteger();
private final Map<DataLoader<?,?>, AtomicInteger> counters = new HashMap<>();
public int getOutstandingLoadCount(DataLoader<?,?> dl) {
synchronized (this) {
return getDLCounter(dl).intValue();
}
}
public int getOutstandingLoadCount() {
int count = 0;
synchronized (this) {
for (AtomicInteger atomicInteger : counters.values()) {
count += atomicInteger.get();
}
}
return count;
}
public int getStepCount() {
return stepCount.get();
}
void incrementStepCount() {
this.stepCount.incrementAndGet();
}
void loadCall(DataLoader<?,?> dl) {
synchronized (this) {
getDLCounter(dl).incrementAndGet();
}
}
void loadCallComplete(DataLoader<?,?> dl) {
synchronized (this) {
getDLCounter(dl).decrementAndGet();
}
}
private AtomicInteger getDLCounter(DataLoader<?, ?> dl) {
return counters.computeIfAbsent(dl, key -> new AtomicInteger());
}
}