-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Reporter.java
43 lines (34 loc) · 1.21 KB
/
Reporter.java
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
package nallar.reporting;
import nallar.tickthreading.minecraft.ThreadManager;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;
public class Reporter {
private static final Set<Long> reportedHashes = new ConcurrentSkipListSet<Long>();
private static final ThreadManager reportingThreadManager = new ThreadManager(1, "nallar error reporting thread");
static {
reportedHashes.add(0L);
}
public static void report(Throwable e) {
if (reportedHashes.size() > 20 || !reportedHashes.add(hashCode(e))) {
return;
}
reportingThreadManager.run(new Report(e));
}
private static long hashCode(Throwable e) {
if (e == null) {
throw new IllegalArgumentException("Throwable can not be null");
}
StackTraceElement stackTraceElement = e.getStackTrace()[0];
return e.getLocalizedMessage().hashCode() + stackTraceElement.getClassName().hashCode() + stackTraceElement.hashCode() + hashCode(e.getCause());
}
private static class Report implements Runnable {
private final Throwable throwable;
public Report(Throwable throwable) {
this.throwable = throwable;
}
@Override
public void run() {
// TODO: Actually report the issue
}
}
}