diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/EventQueue.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/EventQueue.java index 654cf0cc3..5eae9d876 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/EventQueue.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/EventQueue.java @@ -26,10 +26,8 @@ protected int eqSize() { void addEvent(final EventImpl event) { L.d("[EventQueue] Adding event: " + event.key); - if (eventQueueMemoryCache.size() < config.getEventsBufferSize()) { - eventQueueMemoryCache.add(event); - writeEventQueueToStorage(); - } + eventQueueMemoryCache.add(event); + writeEventQueueToStorage(); } /** @@ -45,7 +43,7 @@ void writeEventQueueToStorage() { /** * Restores events from disk */ - void restore() { + void restoreFromDisk() { L.d("[EventQueue] Restoring events from disk"); eventQueueMemoryCache.clear(); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleEvents.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleEvents.java index 28c4275f0..2aba19a2c 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleEvents.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleEvents.java @@ -23,7 +23,7 @@ public void init(InternalConfig config, Log logger) { super.init(config, logger); L.d("[ModuleEvents] init: config = " + config); eventQueue = new EventQueue(L, config); - eventQueue.restore(); + eventQueue.restoreFromDisk(); eventsInterface = new Events(); } @@ -104,8 +104,12 @@ protected void recordEventInternal(String key, int count, Double sum, Map= internalConfig.getEventsBufferSize()) { - L.d("[ModuleEvents] addEventToQueue: eventQueue.size >= internalConfig.getEventsBufferSize()"); + checkEventQueueToSend(false); + } + + private void checkEventQueueToSend(boolean forceSend) { + if (forceSend || (eventQueue.eqSize() >= internalConfig.getEventsBufferSize())) { + L.d("[ModuleEvents] addEventToQueue: eventQueue.size >= internalConfig.getEventsBufferSize() || forceSend: " + forceSend); addEventsToRequestQ(); } }