Skip to content

Commit

Permalink
feat: changes with map initializers (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray authored Jan 16, 2024
1 parent 73d5862 commit 2799ed3
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 126 deletions.
69 changes: 31 additions & 38 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
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
Loading

0 comments on commit 2799ed3

Please sign in to comment.