Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch breadcrumb store to ConcurrentLinkedQueue #98

Merged
merged 1 commit into from
Jan 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/main/java/com/bugsnag/android/Breadcrumbs.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

class Breadcrumbs implements JsonStream.Streamable {
private static class Breadcrumb {
Expand All @@ -20,7 +20,7 @@ private static class Breadcrumb {
}

private static final int DEFAULT_MAX_SIZE = 20;
private final List<Breadcrumb> store = new LinkedList<Breadcrumb>();
private final Queue<Breadcrumb> store = new ConcurrentLinkedQueue<>();
private int maxSize = DEFAULT_MAX_SIZE;

public void toStream(@NonNull JsonStream writer) throws IOException {
Expand All @@ -38,9 +38,9 @@ public void toStream(@NonNull JsonStream writer) throws IOException {

void add(@NonNull String message) {
if (store.size() >= maxSize) {
store.remove(0);
// Remove oldest breadcrumb
store.poll();
}

store.add(new Breadcrumb(message));
}

Expand All @@ -52,7 +52,10 @@ void setSize(int size) {
if (size > store.size()) {
this.maxSize = size;
} else {
store.subList(0, store.size() - size).clear();
// Remove oldest breadcrumbs until reaching the required size
while (store.size() > size) {
store.poll();
}
}
}
}