diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Config.java b/sdk-java/src/main/java/ly/count/sdk/java/Config.java index 783022c0..51709a6a 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Config.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Config.java @@ -22,136 +22,6 @@ * Countly configuration object. */ public class Config { - /** - * Logging level for {@link Log} module - */ - public enum LoggingLevel { - VERBOSE(0), - DEBUG(1), - INFO(2), - WARN(3), - ERROR(4), - OFF(5); - - private final int level; - - LoggingLevel(int level) { - this.level = level; - } - - public int getLevel() { - return level; - } - - public boolean prints(LoggingLevel l) { - return level <= l.level; - } - } - - public enum DeviceIdStrategy { - UUID(0), - CUSTOM_ID(10); - - private final int index; - - DeviceIdStrategy(int level) { - this.index = level; - } - - public int getIndex() { - return index; - } - - public static DeviceIdStrategy fromIndex(int index) { - if (index == UUID.index) { - return UUID; - } - if (index == CUSTOM_ID.index) { - return CUSTOM_ID; - } - return null; - } - } - - public enum Feature { - Events(CoreFeature.Events.getIndex()), - Sessions(CoreFeature.Sessions.getIndex()), - Views(CoreFeature.Views.getIndex()), - CrashReporting(CoreFeature.CrashReporting.getIndex()), - Location(CoreFeature.Location.getIndex()), - UserProfiles(CoreFeature.UserProfiles.getIndex()), - Feedback(CoreFeature.Feedback.getIndex()), - RemoteConfig(CoreFeature.RemoteConfig.getIndex()); - // StarRating(1 << 12), - // PerformanceMonitoring(1 << 14); - - private final int index; - - Feature(int index) { - this.index = index; - } - - public int getIndex() { - return index; - } - - public static Config.Feature byIndex(int index) { - if (index == Events.index) { - return Events; - } else if (index == Sessions.index) { - return Sessions; - } else if (index == Views.index) { - return Views; - } else if (index == CrashReporting.index) { - return CrashReporting; - } else if (index == Location.index) { - return Location; - } else if (index == UserProfiles.index) { - return UserProfiles; - } else if (index == RemoteConfig.index) { - return RemoteConfig; - } else if (index == Feedback.index) { - return Feedback; - } else { - return null; - } - } - } - - /** - * Holder class for various ids met - * adata and id itself. Final, unmodifiable. - */ - public static final class DID { - public static final int STRATEGY_UUID = 0; - public static final int STRATEGY_CUSTOM = 10; - public int strategy; - public String id; - - public DID(int strategy, String id) { - this.strategy = strategy; - this.id = id; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof DID)) { - return false; - } - DID did = (DID) obj; - return did.strategy == strategy && Objects.equals(did.id, id); - } - - @Override - public int hashCode() { - return id.hashCode(); - } - - @Override - public String toString() { - return "DID " + id + " ( " + strategy + ")"; - } - } protected Log configLog; @@ -360,26 +230,7 @@ public String toString() { */ protected boolean unhandledCrashReportingEnabled = true; - /** - * Get the maximum amount of breadcrumbs. Default is 100. - * - * @param maxBreadcrumbCount the maximum amount of breadcrumbs - * @return {@code this} instance for method chaining - */ - public Config setMaxBreadcrumbCount(int maxBreadcrumbCount) { - this.maxBreadcrumbCount = maxBreadcrumbCount; - return this; - } - - /** - * Disable automatic crash reporting for unhandled exceptions. - * - * @return {@code this} instance for method chaining - */ - public Config disableUnhandledCrashReporting() { - this.unhandledCrashReportingEnabled = false; - return this; - } + public ConfigViews views = new ConfigViews(this); protected String location = null; protected String ip = null; @@ -425,6 +276,27 @@ public Config(String serverURL, String serverAppKey, File sdkStorageRootDirector this.sdkStorageRootDirectory = sdkStorageRootDirectory; } + /** + * Get the maximum amount of breadcrumbs. Default is 100. + * + * @param maxBreadcrumbCount the maximum amount of breadcrumbs + * @return {@code this} instance for method chaining + */ + public Config setMaxBreadcrumbCount(int maxBreadcrumbCount) { + this.maxBreadcrumbCount = maxBreadcrumbCount; + return this; + } + + /** + * Disable automatic crash reporting for unhandled exceptions. + * + * @return {@code this} instance for method chaining + */ + public Config disableUnhandledCrashReporting() { + this.unhandledCrashReportingEnabled = false; + return this; + } + /** * Whether to allow fallback from unavailable device id strategy to Countly OpenUDID derivative. * @@ -1458,5 +1330,134 @@ public Config disableLocation() { return this; } - public ConfigViews views = new ConfigViews(this); + /** + * Logging level for {@link Log} module + */ + public enum LoggingLevel { + VERBOSE(0), + DEBUG(1), + INFO(2), + WARN(3), + ERROR(4), + OFF(5); + + private final int level; + + LoggingLevel(int level) { + this.level = level; + } + + public int getLevel() { + return level; + } + + public boolean prints(LoggingLevel l) { + return level <= l.level; + } + } + + public enum DeviceIdStrategy { + UUID(0), + CUSTOM_ID(10); + + private final int index; + + DeviceIdStrategy(int level) { + this.index = level; + } + + public int getIndex() { + return index; + } + + public static DeviceIdStrategy fromIndex(int index) { + if (index == UUID.index) { + return UUID; + } + if (index == CUSTOM_ID.index) { + return CUSTOM_ID; + } + return null; + } + } + + public enum Feature { + Events(CoreFeature.Events.getIndex()), + Sessions(CoreFeature.Sessions.getIndex()), + Views(CoreFeature.Views.getIndex()), + CrashReporting(CoreFeature.CrashReporting.getIndex()), + Location(CoreFeature.Location.getIndex()), + UserProfiles(CoreFeature.UserProfiles.getIndex()), + Feedback(CoreFeature.Feedback.getIndex()), + RemoteConfig(CoreFeature.RemoteConfig.getIndex()); + // StarRating(1 << 12), + // PerformanceMonitoring(1 << 14); + + private final int index; + + Feature(int index) { + this.index = index; + } + + public int getIndex() { + return index; + } + + public static Config.Feature byIndex(int index) { + if (index == Events.index) { + return Events; + } else if (index == Sessions.index) { + return Sessions; + } else if (index == Views.index) { + return Views; + } else if (index == CrashReporting.index) { + return CrashReporting; + } else if (index == Location.index) { + return Location; + } else if (index == UserProfiles.index) { + return UserProfiles; + } else if (index == RemoteConfig.index) { + return RemoteConfig; + } else if (index == Feedback.index) { + return Feedback; + } else { + return null; + } + } + } + + /** + * Holder class for various ids met + * adata and id itself. Final, unmodifiable. + */ + public static final class DID { + public static final int STRATEGY_UUID = 0; + public static final int STRATEGY_CUSTOM = 10; + public int strategy; + public String id; + + public DID(int strategy, String id) { + this.strategy = strategy; + this.id = id; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof DID)) { + return false; + } + DID did = (DID) obj; + return did.strategy == strategy && Objects.equals(did.id, id); + } + + @Override + public int hashCode() { + return id.hashCode(); + } + + @Override + public String toString() { + return "DID " + id + " ( " + strategy + ")"; + } + } } diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Countly.java b/sdk-java/src/main/java/ly/count/sdk/java/Countly.java index c1dbbab4..e044a13f 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Countly.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Countly.java @@ -35,6 +35,8 @@ public class Countly implements Usage { public static final Device device = Device.dev; private static final Countly cly = SingletonHolder.INSTANCE; + protected SDKCore sdk; + protected Log L; private static class SingletonHolder { private static final Countly INSTANCE = new Countly(); @@ -49,9 +51,6 @@ private static void empty() { } } - protected SDKCore sdk; - protected Log L; - protected Countly(SDKCore sdk, final Log logger) { L = logger; this.sdk = sdk; diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigViews.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigViews.java index 6886181b..62ba6263 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigViews.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ConfigViews.java @@ -5,13 +5,12 @@ public class ConfigViews { private final Config config; + protected Map globalViewSegmentation = null; public ConfigViews(Config config) { this.config = config; } - protected Map globalViewSegmentation = null; - /** * @param segmentation segmentation values that will be added for all recorded views (manual and automatic) * @return Returns the same config object for convenient linking diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java index baf5279b..30278712 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java @@ -28,8 +28,11 @@ public class Device { private String orientation; private Boolean online; private Boolean muted; - private Log L; + protected static final Double NS_IN_SECOND = 1_000_000_000.0d; + protected static final Double NS_IN_MS = 1_000_000.0d; + protected static final Double MS_IN_SECOND = 1000d; + protected static final Long BYTES_IN_MB = 1024L * 1024; private final Map metricOverride = new ConcurrentHashMap<>(); @@ -44,10 +47,6 @@ public void setLog(Log L) { /** * One second in nanoseconds */ - protected static final Double NS_IN_SECOND = 1_000_000_000.0d; - protected static final Double NS_IN_MS = 1_000_000.0d; - protected static final Double MS_IN_SECOND = 1000d; - protected static final Long BYTES_IN_MB = 1024L * 1024; /** * Get operation system name diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java index 978fbc0e..211628f5 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java @@ -33,6 +33,19 @@ class EventImpl implements Event, JSONable { final Log L; + protected static final String SEGMENTATION_KEY = "segmentation"; + protected static final String KEY_KEY = "key"; + protected static final String COUNT_KEY = "count"; + protected static final String SUM_KEY = "sum"; + protected static final String DUR_KEY = "dur"; + protected static final String TIMESTAMP_KEY = "timestamp"; + protected static final String DAY_OF_WEEK = "dow"; + protected static final String HOUR = "hour"; + protected static final String ID_KEY = "id"; + protected static final String PV_ID_KEY = "pvid"; + protected static final String CV_ID_KEY = "cvid"; + protected static final String PE_ID_KEY = "peid"; + public interface EventRecorder { void recordEvent(Event event); } @@ -240,19 +253,6 @@ public boolean equals(Object obj) { return true; } - protected static final String SEGMENTATION_KEY = "segmentation"; - protected static final String KEY_KEY = "key"; - protected static final String COUNT_KEY = "count"; - protected static final String SUM_KEY = "sum"; - protected static final String DUR_KEY = "dur"; - protected static final String TIMESTAMP_KEY = "timestamp"; - protected static final String DAY_OF_WEEK = "dow"; - protected static final String HOUR = "hour"; - protected static final String ID_KEY = "id"; - protected static final String PV_ID_KEY = "pvid"; - protected static final String CV_ID_KEY = "cvid"; - protected static final String PE_ID_KEY = "peid"; - /** * Serialize to JSON format according to Countly server requirements * diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java index abced9ad..36683c06 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ImmediateRequestMaker.java @@ -10,6 +10,9 @@ */ class ImmediateRequestMaker implements ImmediateRequestI { + private InternalImmediateRequestCallback callback; + private Log L; + @Override public void doWork(String requestData, String customEndpoint, Transport cp, boolean requestShouldBeDelayed, boolean networkingIsEnabled, InternalImmediateRequestCallback callback, Log log) { CompletableFuture.supplyAsync(() -> doInBackground(requestData, customEndpoint, cp, requestShouldBeDelayed, networkingIsEnabled, callback, log)) @@ -23,9 +26,6 @@ protected interface InternalImmediateRequestCallback { void callback(JSONObject checkResponse); } - private InternalImmediateRequestCallback callback; - private Log L; - /** * params fields: * 0 - requestData diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java index dbc410e1..7e39ecfe 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java @@ -21,6 +21,8 @@ public class ModuleDeviceIdCore extends ModuleBase { * Tasks instance for async execution */ private Tasks tasks; + private static final Map generators = new ConcurrentHashMap<>(); + protected DeviceId deviceIdInterface; private static final class UUIDGenerator implements DeviceIdGenerator { @@ -44,10 +46,6 @@ public String generate(InternalConfig config) { } } - private static final Map generators = new ConcurrentHashMap<>(); - - protected DeviceId deviceIdInterface; - @Override public void init(InternalConfig config) throws IllegalArgumentException { super.init(config); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java index ee5a3859..b912c567 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java @@ -6,26 +6,37 @@ import java.util.Map; import java.util.Queue; import java.util.TreeMap; -import javax.annotation.Nonnull; import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import ly.count.sdk.java.Config; public class SDKCore { protected static SDKCore instance; - protected final SDKStorage sdkStorage; private UserImpl user; - public InternalConfig config; protected Networking networking; protected Queue requestQueueMemory = null; - protected final Object lockBRQStorage = new Object(); - private CountlyTimer countlyTimer; + protected Log L = null; + protected static ModuleBase testDummyModule = null;//set during testing when trying to check the SDK's lifecycle + /** + * Currently enabled features with consents + */ + protected int consents = 0; + + /** + * Selected by config map of module mappings + */ + private static final Map> moduleMappings = new ConcurrentHashMap<>(); + + // TreeMap to keep modules sorted by their feature indexes + protected final Map modules; + public enum Signal { DID(1), Crash(2), @@ -49,9 +60,6 @@ public SDKCore() { sdkStorage = new SDKStorage(); } - protected Log L = null; - protected static ModuleBase testDummyModule = null;//set during testing when trying to check the SDK's lifecycle - protected static void registerDefaultModuleMappings() { moduleMappings.put(CoreFeature.DeviceId, ModuleDeviceIdCore.class); moduleMappings.put(CoreFeature.Requests, ModuleRequests.class); @@ -67,19 +75,6 @@ protected static void registerDefaultModuleMappings() { moduleMappings.put(CoreFeature.Location, ModuleLocation.class); } - /** - * Currently enabled features with consents - */ - protected int consents = 0; - - /** - * Selected by config map of module mappings - */ - private static final Map> moduleMappings = new ConcurrentHashMap<>(); - - // TreeMap to keep modules sorted by their feature indexes - protected final Map modules; - /** * Check if consent has been given for a feature * diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Tasks.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Tasks.java index 86767e93..9d165970 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Tasks.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Tasks.java @@ -17,8 +17,17 @@ public class Tasks { public static final Long ID_STRICT = 0L; public static final Long ID_LIST = -1L; - final Log L; + /** + * Service which runs {@link Callable}s + */ + private final ExecutorService executor; + private Long running = null; + + /** + * Map of {@link Future}s for {@link Callable}s not yet resolved + */ + private final Map pending; public static abstract class Task implements Callable { Long id; @@ -34,17 +43,6 @@ public interface Callback { void call(T param) throws Exception; } - /** - * Service which runs {@link Callable}s - */ - private final ExecutorService executor; - private Long running = null; - - /** - * Map of {@link Future}s for {@link Callable}s not yet resolved - */ - private final Map pending; - public Tasks(final String name, Log L) { this.L = L; executor = Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, name));