Skip to content

Commit

Permalink
feat(session) Change autoCaptured type from AtomicBoolean to volatile…
Browse files Browse the repository at this point in the history
… boolean since it does not use specific atomic method
  • Loading branch information
YYChen01988 committed Apr 16, 2024
1 parent 1c44dd1 commit a96b03a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class Session implements JsonStream.Streamable, UserAware {
private App app;
private Device device;

private final AtomicBoolean autoCaptured = new AtomicBoolean(false);
private volatile boolean autoCaptured = false;
private final AtomicInteger unhandledCount = new AtomicInteger();
private final AtomicInteger handledCount = new AtomicInteger();
private final AtomicBoolean tracked = new AtomicBoolean(false);
Expand All @@ -41,7 +41,7 @@ static Session copySession(Session session) {
session.unhandledCount.get(), session.handledCount.get(), session.notifier,
session.logger, session.getApiKey());
copy.tracked.set(session.tracked.get());
copy.autoCaptured.set(session.isAutoCaptured());
copy.autoCaptured = session.isAutoCaptured();
return copy;
}

Expand All @@ -68,7 +68,7 @@ static Session copySession(Session session) {
this.id = id;
this.startedAt = new Date(startedAt.getTime());
this.user = user;
this.autoCaptured.set(autoCaptured);
this.autoCaptured = autoCaptured;
this.apiKey = apiKey;
}

Expand Down Expand Up @@ -198,16 +198,20 @@ Session incrementUnhandledAndCopy() {
return copySession(this);
}

AtomicBoolean isTracked() {
return tracked;
boolean markTracked() {
return tracked.compareAndSet(false, true);
}

boolean markPaused() {
return isPaused.compareAndSet(true, false);
}

boolean isAutoCaptured() {
return autoCaptured.get();
return autoCaptured;
}

void setAutoCaptured(boolean autoCaptured) {
this.autoCaptured.set(autoCaptured);
this.autoCaptured = autoCaptured;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ boolean resumeSession() {
session = startSession(false);
resumed = false;
} else {
resumed = session.isPaused.compareAndSet(true, false);
resumed = session.markPaused();
}

if (session != null) {
Expand Down Expand Up @@ -191,7 +191,7 @@ private boolean trackSessionIfNeeded(final Session session) {
session.setDevice(client.getDeviceDataCollector().generateDevice());
boolean deliverSession = callbackState.runOnSessionTasks(session, logger);

if (deliverSession && session.isTracked().compareAndSet(false, true)) {
if (deliverSession && session.markTracked()) {
currentSession = session;
notifySessionStartObserver(session);
flushInMemorySession(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ class SessionTest {
assertEquals(startedAt, copy.startedAt)
assertEquals(getUser(), copy.getUser()) // make a shallow copy
assertEquals(isAutoCaptured, copy.isAutoCaptured)
assertEquals(isTracked.get(), copy.isTracked.get())
assertEquals(markTracked(), copy.markTracked())
assertEquals(markPaused(), copy.markPaused())
assertEquals(session.unhandledCount, copy.unhandledCount)
assertEquals(session.handledCount, copy.handledCount)
}
Expand Down

0 comments on commit a96b03a

Please sign in to comment.