Skip to content

Commit

Permalink
feat: add force sending
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray committed Sep 27, 2023
1 parent a96e839 commit 71bc4c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand All @@ -45,7 +43,7 @@ void writeEventQueueToStorage() {
/**
* Restores events from disk
*/
void restore() {
void restoreFromDisk() {
L.d("[EventQueue] Restoring events from disk");
eventQueueMemoryCache.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -104,8 +104,12 @@ protected void recordEventInternal(String key, int count, Double sum, Map<String
private void addEventToQueue(EventImpl event) {
L.d("[ModuleEvents] addEventToQueue");
eventQueue.addEvent(event);
if (eventQueue.eqSize() >= 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();
}
}
Expand Down

0 comments on commit 71bc4c2

Please sign in to comment.