Skip to content

Commit d0b4e97

Browse files
committed
change to serialize the session in the report
1 parent fe7c478 commit d0b4e97

3 files changed

Lines changed: 15 additions & 55 deletions

File tree

bugsnag/src/main/java/com/bugsnag/Bugsnag.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -472,16 +472,11 @@ public boolean notify(Report report, Callback reportCallback) {
472472
Session session = sessionTracker.getSession();
473473

474474
if (session != null) {
475-
try {
476-
if (report.getUnhandled()) {
477-
session = session.incrementUnhandledCountAndClone();
478-
} else {
479-
session = session.incrementHandledCountAndClone();
480-
}
481-
} catch (InterruptedException ex) {
482-
// Failed to increment session counts properly
475+
if (report.getUnhandled()) {
476+
session.incrementUnhandledCount();
477+
} else {
478+
session.incrementHandledCount();
483479
}
484-
485480
report.setSession(session);
486481
}
487482

bugsnag/src/main/java/com/bugsnag/Report.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Report {
2323
private String groupingHash;
2424
private Diagnostics diagnostics;
2525
private boolean shouldCancel = false;
26-
private Session session;
26+
private Map<String, Object> sessionMap;
2727
private final List<ThreadState> threadStates;
2828

2929
/**
@@ -131,23 +131,22 @@ public Map<String, Object> getMetaData() {
131131

132132
@Expose
133133
Map<String, Object> getSession() {
134+
return sessionMap;
135+
}
136+
137+
void setSession(Session session) {
134138
if (session == null) {
135-
return null;
139+
sessionMap = null;
136140
}
137-
138-
Map<String, Object> map = new HashMap<String, Object>();
139-
map.put("id", session.getId());
140-
map.put("startedAt", session.getStartedAt());
141+
142+
sessionMap = new HashMap<String, Object>();
143+
sessionMap.put("id", session.getId());
144+
sessionMap.put("startedAt", session.getStartedAt());
141145

142146
Map<String, Object> handledCounts = new HashMap<String, Object>();
143147
handledCounts.put("handled", session.getHandledCount());
144148
handledCounts.put("unhandled", session.getUnhandledCount());
145-
map.put("events", handledCounts);
146-
return map;
147-
}
148-
149-
void setSession(Session session) {
150-
this.session = session;
149+
sessionMap.put("events", handledCounts);
151150
}
152151

153152
/**

bugsnag/src/main/java/com/bugsnag/Session.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
import com.bugsnag.serialization.Expose;
44

55
import java.util.Date;
6-
import java.util.concurrent.Semaphore;
76
import java.util.concurrent.atomic.AtomicInteger;
87

98
class Session {
109

11-
private final Semaphore incrementRequest = new Semaphore(1);
12-
1310
private final String id;
1411
private final Date startedAt;
1512
private final AtomicInteger handledCount;
@@ -22,13 +19,6 @@ class Session {
2219
this.unhandledCount = new AtomicInteger(0);
2320
}
2421

25-
private Session(String id, Date startedAt, int handledCount, int unhandledCount) {
26-
this.id = id;
27-
this.startedAt = startedAt;
28-
this.handledCount = new AtomicInteger(handledCount);
29-
this.unhandledCount = new AtomicInteger(unhandledCount);
30-
}
31-
3222
int getHandledCount() {
3323
return handledCount.get();
3424
}
@@ -37,16 +27,6 @@ void incrementHandledCount() {
3727
this.handledCount.incrementAndGet();
3828
}
3929

40-
Session incrementHandledCountAndClone() throws InterruptedException {
41-
try {
42-
incrementRequest.acquire();
43-
incrementHandledCount();
44-
return cloneSession();
45-
} finally {
46-
incrementRequest.release();
47-
}
48-
}
49-
5030
int getUnhandledCount() {
5131
return unhandledCount.get();
5232
}
@@ -55,20 +35,6 @@ void incrementUnhandledCount() {
5535
this.unhandledCount.incrementAndGet();
5636
}
5737

58-
Session incrementUnhandledCountAndClone() throws InterruptedException {
59-
try {
60-
incrementRequest.acquire();
61-
incrementUnhandledCount();
62-
return cloneSession();
63-
} finally {
64-
incrementRequest.release();
65-
}
66-
}
67-
68-
private Session cloneSession() {
69-
return new Session(id, startedAt, handledCount.get(), unhandledCount.get());
70-
}
71-
7238
String getId() {
7339
return id;
7440
}

0 commit comments

Comments
 (0)