persist network plugin state

Summary:
This saved the state of the network plugin even when switching between plugins using persistedState.
A bug in the Android implementation didn't clear the events that were already sent to the desktop.

Reviewed By: jknoxville

Differential Revision: D8752098

fbshipit-source-id: 152ec5da83958ad8124686f780d39983cbce563f
This commit is contained in:
Daniel Büchele
2018-07-10 02:22:18 -07:00
committed by Facebook Github Bot
parent f5dcaf02a4
commit c239fcac01
6 changed files with 144 additions and 132 deletions

View File

@@ -49,9 +49,10 @@ public abstract class BufferingSonarPlugin implements SonarPlugin {
if (mEventQueue == null) {
mEventQueue = new RingBuffer<>(BUFFER_SIZE);
}
mEventQueue.enqueue(new CachedSonarEvent(method, sonarObject));
if (mConnection != null) {
mConnection.send(method, sonarObject);
} else {
mEventQueue.enqueue(new CachedSonarEvent(method, sonarObject));
}
}
@@ -60,6 +61,7 @@ public abstract class BufferingSonarPlugin implements SonarPlugin {
for (CachedSonarEvent cachedSonarEvent : mEventQueue.asList()) {
mConnection.send(cachedSonarEvent.method, cachedSonarEvent.sonarObject);
}
mEventQueue.clear();
}
}

View File

@@ -25,6 +25,10 @@ final class RingBuffer<T> {
mBuffer.add(item);
}
void clear() {
mBuffer.clear();
}
List<T> asList() {
return mBuffer;
}