Skip to content

Commit

Permalink
feat: rename event impl queeu to event queue
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray committed Sep 27, 2023
1 parent 75b687a commit a96e839
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import java.util.Collection;
import java.util.List;

public class EventImplQueue {
public class EventQueue {

static final String DELIMITER = ":::";
private final Log L;
private final InternalConfig config;
final List<EventImpl> eventQueueMemoryCache;

protected EventImplQueue(Log logger, InternalConfig config) {
protected EventQueue(Log logger, InternalConfig config) {
L = logger;
this.config = config;
eventQueueMemoryCache = new ArrayList<>(config.getEventsBufferSize());
Expand All @@ -25,7 +25,7 @@ protected int eqSize() {
}

void addEvent(final EventImpl event) {
L.d("[EventImplQueue] Adding event: " + event.key);
L.d("[EventQueue] Adding event: " + event.key);
if (eventQueueMemoryCache.size() < config.getEventsBufferSize()) {
eventQueueMemoryCache.add(event);
writeEventQueueToStorage();
Expand All @@ -38,15 +38,15 @@ void addEvent(final EventImpl event) {
void writeEventQueueToStorage() {
final String eventQueue = joinEvents(eventQueueMemoryCache);

L.d("[EventImplQueue] Setting event data: " + eventQueue);
L.d("[EventQueue] Setting event data: " + eventQueue);
SDKCore.instance.sdkStorage.storeEventQueue(eventQueue);
}

/**
* Restores events from disk
*/
void restore() {
L.d("[EventImplQueue] Restoring events from disk");
L.d("[EventQueue] Restoring events from disk");
eventQueueMemoryCache.clear();

final String[] array = getEvents();
Expand All @@ -67,14 +67,14 @@ private String joinEvents(final Collection<EventImpl> collection) {
for (EventImpl e : collection) {
strings.add(e.toJSON(L));
}
return Utils.join(strings, EventImplQueue.DELIMITER);
return Utils.join(strings, EventQueue.DELIMITER);
}

/**
* Returns an unsorted array of the current stored event JSON strings.
*/
private synchronized String[] getEvents() {
L.d("[EventImplQueue] Getting events from disk");
L.d("[EventQueue] Getting events from disk");
final String joinedEventsStr = SDKCore.instance.sdkStorage.readEventQueue();
return joinedEventsStr.isEmpty() ? new String[0] : joinedEventsStr.split(DELIMITER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class ModuleEvents extends ModuleBase {

protected CtxCore ctx = null;
protected EventImplQueue eventQueue = null;
protected EventQueue eventQueue = null;
final Map<String, EventImpl> timedEvents = new HashMap<>();
private ScheduledExecutorService executor = null;
protected Events eventsInterface = null;
Expand All @@ -22,7 +22,7 @@ public class ModuleEvents extends ModuleBase {
public void init(InternalConfig config, Log logger) {
super.init(config, logger);
L.d("[ModuleEvents] init: config = " + config);
eventQueue = new EventImplQueue(L, config);
eventQueue = new EventQueue(L, config);
eventQueue.restore();
eventsInterface = new Events();
}
Expand Down
16 changes: 4 additions & 12 deletions sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package ly.count.sdk.java.internal;

import ly.count.sdk.java.Config;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.*;
import java.util.stream.Stream;
import ly.count.sdk.java.Config;

import static ly.count.sdk.java.internal.SDKStorage.EVENT_QUEUE_FILE_NAME;
import static ly.count.sdk.java.internal.SDKStorage.FILE_NAME_PREFIX;
import static ly.count.sdk.java.internal.SDKStorage.FILE_NAME_SEPARATOR;
import static ly.count.sdk.java.internal.SDKStorage.*;

public class TestUtils {
static String SERVER_URL = "https://test.count.ly";
Expand Down Expand Up @@ -105,7 +97,7 @@ protected static List<EventImpl> getCurrentEventQueue(File targetFolder, Log log
//do nothing
}

Arrays.stream(fileContent.split(EventImplQueue.DELIMITER)).forEach(s -> {
Arrays.stream(fileContent.split(EventQueue.DELIMITER)).forEach(s -> {
final EventImpl event = EventImpl.fromJSON(s, (ev) -> {
}, logger);
if (event != null) {
Expand Down

0 comments on commit a96e839

Please sign in to comment.