This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new aef523ba0 [SEDONA-638] Submit telemetry asynchronously without
blocking the initialization of SedonaContext (#1541)
aef523ba0 is described below
commit aef523ba0c94530b68a08983acbf8f9731529110
Author: Kristin Cowalcijk <[email protected]>
AuthorDate: Tue Aug 6 01:18:15 2024 +0800
[SEDONA-638] Submit telemetry asynchronously without blocking the
initialization of SedonaContext (#1541)
---
.../sedona/common/utils/TelemetryCollector.java | 60 +++++++++++++++-------
1 file changed, 41 insertions(+), 19 deletions(-)
diff --git
a/common/src/main/java/org/apache/sedona/common/utils/TelemetryCollector.java
b/common/src/main/java/org/apache/sedona/common/utils/TelemetryCollector.java
index 2e920aa81..b0864b0e5 100644
---
a/common/src/main/java/org/apache/sedona/common/utils/TelemetryCollector.java
+++
b/common/src/main/java/org/apache/sedona/common/utils/TelemetryCollector.java
@@ -21,14 +21,18 @@ package org.apache.sedona.common.utils;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
+import java.util.concurrent.atomic.AtomicBoolean;
public class TelemetryCollector {
private static final String BASE_URL =
"https://sedona.gateway.scarf.sh/packages/";
+ private static final AtomicBoolean telemetrySubmitted = new
AtomicBoolean(false);
public static String send(String engineName, String language) {
- HttpURLConnection conn = null;
- String telemetrySubmitted = "";
+ String telemetrySubmitUrl = "";
+ if (!telemetrySubmitted.compareAndSet(false, true)) {
+ return telemetrySubmitUrl;
+ }
try {
String arch =
URLEncoder.encode(System.getProperty("os.arch").replaceAll(" ", "_"), "UTF-8");
String os = URLEncoder.encode(System.getProperty("os.name").replaceAll("
", "_"), "UTF-8");
@@ -36,7 +40,7 @@ public class TelemetryCollector {
URLEncoder.encode(System.getProperty("java.version").replaceAll(" ",
"_"), "UTF-8");
// Construct URL
- telemetrySubmitted =
+ telemetrySubmitUrl =
BASE_URL + language + "/" + engineName + "/" + arch + "/" + os + "/"
+ jvm;
// Check for user opt-out
@@ -47,26 +51,44 @@ public class TelemetryCollector {
&& System.getProperty("SCARF_NO_ANALYTICS").equals("true")
|| System.getProperty("DO_NOT_TRACK") != null
&& System.getProperty("DO_NOT_TRACK").equals("true")) {
- return telemetrySubmitted;
+ return telemetrySubmitUrl;
}
- // Send GET request
- URL url = new URL(telemetrySubmitted);
- conn = (HttpURLConnection) url.openConnection();
- conn.setRequestMethod("GET");
- conn.connect();
- int responseCode = conn.getResponseCode();
- // Optionally check the response for successful execution
- if (responseCode != 200) {
- // Silent handling, no output or log
- }
+ Thread telemetrySubmitThread = createThread(telemetrySubmitUrl);
+ telemetrySubmitThread.start();
} catch (Exception e) {
// Silent catch block
- } finally {
- if (conn != null) {
- conn.disconnect();
- }
}
- return telemetrySubmitted;
+ return telemetrySubmitUrl;
+ }
+
+ private static Thread createThread(String telemetrySubmitUrl) {
+ Thread telemetrySubmitThread =
+ new Thread("telemetry-submit-thread") {
+ @Override
+ public void run() {
+ HttpURLConnection conn = null;
+ try {
+ // Send GET request
+ URL url = new URL(telemetrySubmitUrl);
+ conn = (HttpURLConnection) url.openConnection();
+ conn.setRequestMethod("GET");
+ conn.connect();
+ int responseCode = conn.getResponseCode();
+ // Optionally check the response for successful execution
+ if (responseCode != 200) {
+ // Silent handling, no output or log
+ }
+ } catch (Exception e) {
+ // Silent catch block
+ } finally {
+ if (conn != null) {
+ conn.disconnect();
+ }
+ }
+ }
+ };
+ telemetrySubmitThread.setDaemon(true);
+ return telemetrySubmitThread;
}
}