Skip to content

Commit

Permalink
use non critical io pool executor for telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Dec 7, 2024
1 parent 7adb977 commit 6155852
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.teamlapen.vampirism.REFERENCE;
import de.teamlapen.vampirism.config.VampirismConfig;
import net.minecraft.Util;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.ModList;
Expand All @@ -18,6 +19,7 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -35,6 +37,7 @@ public static void execute() {

private static void send() {
try {
HttpClient build = HttpClient.newBuilder().executor(Util.ioPool()).connectTimeout(Duration.ofSeconds(5)).build();
StringBuilder builder = new StringBuilder();
builder.append(REFERENCE.SETTINGS_API);
builder.append("/telemetry/basic");
Expand All @@ -48,8 +51,8 @@ private static void send() {
builder.append("?");
builder.append(params.entrySet().stream().map(s -> s.getKey() + "=" + URLEncoder.encode(s.getValue(), StandardCharsets.UTF_8)).collect(Collectors.joining("&")));

HttpClient.newHttpClient().send(HttpRequest.newBuilder().uri(new URI(builder.toString())).build(), HttpResponse.BodyHandlers.ofString());
} catch (URISyntaxException | IOException | InterruptedException e) {
build.sendAsync(HttpRequest.newBuilder().uri(new URI(builder.toString())).build(), HttpResponse.BodyHandlers.ofString());
} catch (URISyntaxException e) {
LOGGER.error("Failed to send telemetry data", e);
}
}
Expand Down

0 comments on commit 6155852

Please sign in to comment.