Skip to content

Commit

Permalink
Merge branch 'staging' into codacy_map_corefeature
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray authored Jan 18, 2024
2 parents 4bbc504 + 2562fb1 commit 1b350a3
Show file tree
Hide file tree
Showing 29 changed files with 197 additions and 218 deletions.
71 changes: 32 additions & 39 deletions app-java/src/main/java/ly/count/java/demo/BackendModeExample.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ly.count.java.demo;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import ly.count.sdk.java.Config;
import ly.count.sdk.java.Countly;
Expand All @@ -14,7 +14,7 @@ public class BackendModeExample {
final static String COUNTLY_SERVER_URL = "https://xxx.server.ly/";

private static void recordUserDetailAndProperties() {
Map<String, Object> userDetail = new HashMap<>();
Map<String, Object> userDetail = new ConcurrentHashMap<>();
userDetail.put("name", "Full Name");
userDetail.put("username", "username1");
userDetail.put("email", "[email protected]");
Expand All @@ -32,7 +32,7 @@ private static void recordUserDetailAndProperties() {
}

private static void recordView() {
Map<String, Object> segmentation = new HashMap<>();
Map<String, Object> segmentation = new ConcurrentHashMap<>();
segmentation.put("visit", "1");
segmentation.put("segment", "Windows");
segmentation.put("start", "1");
Expand All @@ -41,23 +41,20 @@ private static void recordView() {
}

private static void recordEvent() {
Map<String, Object> segment = new HashMap<String, Object>() {{
put("Time Spent", 60);
put("Retry Attempts", 60);
}};

Map<String, Object> segment = new ConcurrentHashMap<>();
segment.put("Time Spent", 60);
segment.put("Retry Attempts", 60);
Countly.instance().backendM().recordEvent(DEVICE_ID, "Event Key", 1, 0.1, 5.0, segment, null);
}

private static void recordExceptionWithThrowableAndSegmentation() {
Map<String, Object> segmentation = new HashMap<String, Object>() {{
put("login page", "authenticate request");
}};
Map<String, String> crashDetails = new HashMap<String, String>() {{
put("_os", "Windows 11");
put("_os_version", "11.202");
put("_logs", "main page");
}};
Map<String, Object> segmentation = new ConcurrentHashMap<>();
segmentation.put("logout page", "authenticate request");

Map<String, String> crashDetails = new ConcurrentHashMap<>();
crashDetails.put("_os", "Windows 10");
crashDetails.put("_os_version", "10.202");
crashDetails.put("_logs", "logout page");
try {
int a = 10 / 0;
} catch (Exception e) {
Expand All @@ -66,15 +63,13 @@ private static void recordExceptionWithThrowableAndSegmentation() {
}

private static void recordExceptionWithMessageAndSegmentation() {
Map<String, Object> segmentation = new HashMap<String, Object>() {{
put("login page", "authenticate request");
}};

Map<String, String> crashDetails = new HashMap<String, String>() {{
put("_os", "Windows 11");
put("_os_version", "11.202");
put("_logs", "main page");
}};
Map<String, Object> segmentation = new ConcurrentHashMap<>();
segmentation.put("login page", "authenticate request");

Map<String, String> crashDetails = new ConcurrentHashMap<>();
crashDetails.put("_os", "Windows 11");
crashDetails.put("_os_version", "11.202");
crashDetails.put("_logs", "main page");
try {
int a = 10 / 0;
} catch (Exception e) {
Expand All @@ -83,7 +78,7 @@ private static void recordExceptionWithMessageAndSegmentation() {
}

private static void recordDirectRequest() {
Map<String, String> requestData = new HashMap<>();
Map<String, String> requestData = new ConcurrentHashMap<>();
requestData.put("device_id", "id");
requestData.put("timestamp", "1646640780130");
requestData.put("end_session", "1");
Expand All @@ -92,18 +87,16 @@ private static void recordDirectRequest() {
}

private static void startSession() {
Map<String, String> metrics = new HashMap<String, String>() {{
put("_os", "Android");
put("_os_version", "10");
put("_app_version", "1.2");
}};

Map<String, String> location = new HashMap<String, String>() {{
put("ip_address", "192.168.1.1");
put("city", "Lahore");
put("country_code", "PK");
put("location", "31.5204,74.3587");
}};
Map<String, String> metrics = new ConcurrentHashMap<>();
metrics.put("_os", "Windows");
metrics.put("_os_version", "10");
metrics.put("_app_version", "1.2");

Map<String, String> location = new ConcurrentHashMap<>();
location.put("ip_address", "IP_ADDR");
location.put("city", "Lahore");
location.put("country_code", "PK");
location.put("location", "31.5204,74.3587");

Countly.instance().backendM().sessionBegin(DEVICE_ID, metrics, location, null);
}
Expand Down Expand Up @@ -312,7 +305,7 @@ public static void main(String[] args) throws Exception {
String[] sdkStorageRootPath = { System.getProperty("user.home"), "__COUNTLY", "java_test" };
File sdkStorageRootDirectory = new File(String.join(File.separator, sdkStorageRootPath));

if ((!(sdkStorageRootDirectory.exists() && sdkStorageRootDirectory.isDirectory())) && !sdkStorageRootDirectory.mkdirs()) {
if (!(sdkStorageRootDirectory.exists() && sdkStorageRootDirectory.isDirectory()) && !sdkStorageRootDirectory.mkdirs()) {
DemoUtils.println("Directory creation failed");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ly.count.java.demo;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap;
import ly.count.sdk.java.Config;
import ly.count.sdk.java.Countly;
import ly.count.sdk.java.internal.Device;
Expand Down Expand Up @@ -50,27 +50,23 @@ static void performLargeRequestQueueSizeTest() {
DemoUtils.printf("Adding %d requests(events) into request Queue%n", batchSize);
for (int i = 1; i < batchSize; ++i) {

Map<String, Object> segment = new HashMap<String, Object>() {{
put("Time Spent", 60);
put("Retry Attempts", 60);
}};
Map<String, Object> segment = new ConcurrentHashMap<>();
segment.put("Time Spent", 60);
segment.put("Retry Attempts", 60);

Countly.backendMode().recordEvent(DEVICE_ID, "Event Key " + i, 1, 0.1, 5.0, segment, null);
}

DemoUtils.printf("Adding %d requests(crash) into request Queue%n", batchSize);
for (int i = 1; i < batchSize; ++i) {

Map<String, Object> segmentation = new HashMap<String, Object>() {{
put("login page", "authenticate request");
}};

Map<String, String> crashDetails = new HashMap<String, String>() {{
put("_os", "Windows 11");
put("_os_version", "11.202");
put("_logs", "main page");
}};
Map<String, Object> segmentation = new ConcurrentHashMap<>();
segmentation.put("signup page", "authenticate request");

Map<String, String> crashDetails = new ConcurrentHashMap<>();
crashDetails.put("_os", "Windows 8");
crashDetails.put("_os_version", "8.202");
crashDetails.put("_logs", "main page");
Countly.backendMode().recordException(DEVICE_ID, "Message: " + i, "stack traces " + 1, segmentation, crashDetails,
null);
}
Expand All @@ -79,7 +75,7 @@ static void performLargeRequestQueueSizeTest() {
for (int i = 1; i < batchSize; ++i) {

// User detail
Map<String, Object> userDetail = new HashMap<>();
Map<String, Object> userDetail = new ConcurrentHashMap<>();
userDetail.put("name", "Full Name");
userDetail.put("username", "username1");
userDetail.put("email", "[email protected]");
Expand All @@ -98,19 +94,16 @@ static void performLargeRequestQueueSizeTest() {

DemoUtils.printf("Adding %d requests(sessions) into request Queue%n", batchSize);
for (int i = 1; i < batchSize; ++i) {
Map<String, String> metrics = new HashMap<String, String>() {{
put("_os", "Android");
put("_os_version", "10");
put("_app_version", "1.2");
}};

Map<String, String> location = new HashMap<String, String>() {{
put("ip_address", "192.168.1.1");
put("city", "Lahore");
put("country_code", "PK");
put("location", "31.5204,74.3587");
}};

Map<String, String> metrics = new ConcurrentHashMap<>();
metrics.put("_os", "MacOs");
metrics.put("_os_version", "13");
metrics.put("_app_version", "1.3");

Map<String, String> location = new ConcurrentHashMap<>();
location.put("ip_address", "IP_ADDR");
location.put("city", "Lahore");
location.put("country_code", "PK");
location.put("location", "31.5204,74.3587");
Countly.backendMode().sessionBegin(DEVICE_ID, metrics, location, null);
}

Expand All @@ -131,10 +124,9 @@ static void performLargeEventQueueTest() {
DemoUtils.printf("Adding %d events into event Queue against deviceID = %s%n", 1_000_00, "device-id-" + d);
for (int i = 1; i <= noOfEvents; ++i) {

Map<String, Object> segment = new HashMap<String, Object>() {{
put("Time Spent", 60);
put("Retry Attempts", 60);
}};
Map<String, Object> segment = new ConcurrentHashMap<>();
segment.put("Time Spent", 60);
segment.put("Retry Attempts", 60);

Countly.backendMode().recordEvent("device-id-" + d, "Event Key " + i, 1, 0.1, 5.0, segment, null);
}
Expand All @@ -159,10 +151,9 @@ static void recordBulkDataAndSendToServer() throws InterruptedException {
Thread.sleep(secondsToSleep * 1000);
} else {
if (remaining > 0) {
Map<String, Object> segment = new HashMap<String, Object>() {{
put("Time Spent", 60);
put("Retry Attempts", 60);
}};
Map<String, Object> segment = new ConcurrentHashMap<>();
segment.put("Time Spent", 60);
segment.put("Retry Attempts", 60);

Countly.backendMode().recordEvent("device-id", "Event Key " + remaining, 1, 0.1, 5.0, segment, null);
--remaining;
Expand Down Expand Up @@ -199,13 +190,13 @@ public static void main(String[] args) throws Exception {
case 2:
performLargeEventQueueTest();
running = false;
DemoUtils.printf("Time spent: %dms%n", (System.currentTimeMillis() - startTime));
DemoUtils.printf("Time spent: %dms%n", System.currentTimeMillis() - startTime);
break;
case 3:
startTime = System.currentTimeMillis();
recordBulkDataAndSendToServer();
running = false;
DemoUtils.printf("Time spent: %dms%n", (System.currentTimeMillis() - startTime));
DemoUtils.printf("Time spent: %dms%n", System.currentTimeMillis() - startTime);
break;
default:
break;
Expand Down
8 changes: 4 additions & 4 deletions sdk-java/src/main/java/ly/count/sdk/java/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import ly.count.sdk.java.internal.CoreFeature;
import ly.count.sdk.java.internal.Log;
import ly.count.sdk.java.internal.LogCallback;
Expand Down Expand Up @@ -138,7 +138,7 @@ public boolean equals(Object obj) {
return false;
}
DID did = (DID) obj;
return did.strategy == strategy && (Objects.equals(did.id, id));
return did.strategy == strategy && Objects.equals(did.id, id);
}

@Override
Expand Down Expand Up @@ -214,7 +214,7 @@ public String toString() {
*/
protected boolean enableBackendMode = false;

protected final Map<String, String> metricOverride = new HashMap<>();
protected final Map<String, String> metricOverride = new ConcurrentHashMap<>();

/**
* Salt string for parameter tampering protection
Expand Down Expand Up @@ -379,7 +379,7 @@ public Config disableUnhandledCrashReporting() {
this.unhandledCrashReportingEnabled = false;
return this;
}

protected String location = null;
protected String ip = null;
protected String city = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import ly.count.sdk.java.Crash;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -150,7 +151,7 @@ public Map<String, String> getSegments() {
return null;
}
JSONObject object = this.data.getJSONObject("_custom");
Map<String, String> map = new HashMap<>();
Map<String, String> map = new ConcurrentHashMap<>();
Iterator<String> iterator = object.keys();
while (iterator.hasNext()) {
String key = iterator.next();
Expand Down
8 changes: 4 additions & 4 deletions sdk-java/src/main/java/ly/count/sdk/java/internal/Device.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package ly.count.sdk.java.internal;

import com.sun.management.OperatingSystemMXBean;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Class encapsulating most of device-specific logic: metrics, info, etc.
Expand All @@ -31,7 +31,7 @@ public class Device {

private Log L;

private final Map<String, String> metricOverride = new HashMap<>();
private final Map<String, String> metricOverride = new ConcurrentHashMap<>();

protected Device() {
dev = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ public boolean equals(Object obj) {
if (count != event.count) {
return false;
}
if ((sum != null && !sum.equals(event.sum) || (event.sum != null && !event.sum.equals(sum)))) {
if (sum != null && !sum.equals(event.sum) || (event.sum != null && !event.sum.equals(sum))) {
return false;
}
if ((duration != null && !duration.equals(event.duration) || (event.duration != null && !event.duration.equals(duration)))) {
if (duration != null && !duration.equals(event.duration) || (event.duration != null && !event.duration.equals(duration))) {
return false;
}
if ((segmentation != null && !segmentation.equals(event.segmentation) || (event.segmentation != null && !event.segmentation.equals(segmentation)))) {
if (segmentation != null && !segmentation.equals(event.segmentation) || (event.segmentation != null && !event.segmentation.equals(segmentation))) {
return false;
}
return true;
Expand Down
Loading

0 comments on commit 1b350a3

Please sign in to comment.