-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Reporter.java
35 lines (29 loc) · 980 Bytes
/
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
package me.nallar.reporting;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;
public class Reporter {
private static final Set<Long> reportedHashes = new ConcurrentSkipListSet<Long>();
private static ReportingThread reportingThread;
static {
reportedHashes.add(0L);
}
public static void report(Throwable e) {
if (reportedHashes.size() > 20 || !reportedHashes.add(hashCode(e))) {
return;
}
getReportingThread().addIssue(e);
}
private static synchronized ReportingThread getReportingThread() {
if (reportingThread == null) {
reportingThread = new ReportingThread();
}
return reportingThread;
}
private static long hashCode(Throwable e) {
if (e == null) {
return 0;
}
StackTraceElement stackTraceElement = e.getStackTrace()[0];
return e.getLocalizedMessage().hashCode() + stackTraceElement.getClassName().hashCode() + stackTraceElement.hashCode() + hashCode(e.getCause());
}
}