From ed6df4eec1524cecf129f613c17b763d75b2e2e8 Mon Sep 17 00:00:00 2001 From: gsd Date: Sat, 25 Feb 2023 21:09:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B5=D1=81=D0=BB=D0=B8=20=D0=BA=D0=B0=D0=B6?= =?UTF-8?q?=D0=B4=D1=8B=D0=B9=20=D1=80=D0=B0=D0=B7=20=D1=81=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=B0=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BF=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D1=87=D0=BA=D0=B8,=20=D1=82=D0=BE=20=D0=BF=D0=B0=D0=BC=D1=8F?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B1=D1=83=D0=B4=D0=B5=D1=82=20=D0=B7=D0=B0?= =?UTF-8?q?=D1=81=D1=80=D0=B0=D0=BD=D0=B0=20io.netty.util.internal.shaded.?= =?UTF-8?q?org.jctools.queues.MpscUnboundedArrayQueue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/app/entities/Stats.java | 13 +----- .../java/app/entities/server/BaseServer.java | 41 +++++++++++++++++++ src/main/java/app/entities/server/Server.java | 15 +++---- 3 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 src/main/java/app/entities/server/BaseServer.java diff --git a/src/main/java/app/entities/Stats.java b/src/main/java/app/entities/Stats.java index ef586f3..3bc48f7 100644 --- a/src/main/java/app/entities/Stats.java +++ b/src/main/java/app/entities/Stats.java @@ -79,7 +79,7 @@ public class Stats { public void RefreshServerA2SData(String server_name) { //try (SourceQueryClient sourceQueryClient = context.getBean(SourceQueryClient.class)) { - try (SourceQueryClient sourceQueryClient = GetSourceQueryClient()) { + try (SourceQueryClient sourceQueryClient = getServers().get(server_name).GetSourceQueryClient()) { sourceQueryClient.getInfo(getServers().get(server_name).getInetAddress()).whenComplete((info, error) -> { if (!sourceQueryClient.getExecutor().isShutdown()) sourceQueryClient.getExecutor().shutdown(); if (error != null) { @@ -98,7 +98,7 @@ public class Stats { //If player count > 0 make base player request //////////////////////////////////////////////////////////////////////// //try (SourceQueryClient sourceQueryClient = context.getBean(SourceQueryClient.class)) { - try (SourceQueryClient sourceQueryClient = GetSourceQueryClient()) { + try (SourceQueryClient sourceQueryClient = getServers().get(server_name).GetSourceQueryClient()) { sourceQueryClient.getPlayers(getServers().get(server_name).getInetAddress()).whenComplete((players, error) -> { if (!sourceQueryClient.getExecutor().isShutdown()) sourceQueryClient.getExecutor().shutdown(); if (error != null) return; @@ -116,13 +116,4 @@ public class Stats { } } - @JsonIgnore - public SourceQueryClient GetSourceQueryClient() { - ExecutorService customExecutor = Executors.newCachedThreadPool(); - SourceQueryOptions options = SourceQueryOptions.builder() - .option(FailsafeOptions.FAILSAFE_RATELIMIT_TYPE, RateLimitType.BURST) - .option(GeneralOptions.THREAD_EXECUTOR_SERVICE, customExecutor) - .build(); - return new SourceQueryClient(options); - } } diff --git a/src/main/java/app/entities/server/BaseServer.java b/src/main/java/app/entities/server/BaseServer.java new file mode 100644 index 0000000..37d58bc --- /dev/null +++ b/src/main/java/app/entities/server/BaseServer.java @@ -0,0 +1,41 @@ +package app.entities.server; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.ibasco.agql.core.enums.RateLimitType; +import com.ibasco.agql.core.util.FailsafeOptions; +import com.ibasco.agql.core.util.GeneralOptions; +import com.ibasco.agql.protocols.valve.source.query.SourceQueryClient; +import com.ibasco.agql.protocols.valve.source.query.SourceQueryOptions; +import com.ibasco.agql.protocols.valve.source.query.rcon.SourceRconClient; +import com.ibasco.agql.protocols.valve.source.query.rcon.SourceRconOptions; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public abstract class BaseServer { + @JsonIgnore + private ExecutorService executorServices_query; + @JsonIgnore + private ExecutorService executorServices_rcon; + + @JsonIgnore + public SourceRconClient GetSourceRconClient() { + if (executorServices_rcon == null) executorServices_rcon = Executors.newCachedThreadPool(); + SourceRconOptions options = SourceRconOptions.builder() + .option(FailsafeOptions.FAILSAFE_RATELIMIT_TYPE, RateLimitType.SMOOTH) + .option(GeneralOptions.THREAD_EXECUTOR_SERVICE, executorServices_rcon) + .build(); + return new SourceRconClient(options); + } + + + @JsonIgnore + public SourceQueryClient GetSourceQueryClient() { + if (executorServices_query == null) executorServices_query = Executors.newCachedThreadPool(); + SourceQueryOptions options = SourceQueryOptions.builder() + .option(FailsafeOptions.FAILSAFE_RATELIMIT_TYPE, RateLimitType.SMOOTH) + .option(GeneralOptions.THREAD_EXECUTOR_SERVICE, executorServices_query) + .build(); + return new SourceQueryClient(options); + } +} diff --git a/src/main/java/app/entities/server/Server.java b/src/main/java/app/entities/server/Server.java index 7198fab..6db08a0 100644 --- a/src/main/java/app/entities/server/Server.java +++ b/src/main/java/app/entities/server/Server.java @@ -6,7 +6,11 @@ import app.entities.server.players.RCONPlayer; import app.entities.server.players.SourcePlayer; import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.ibasco.agql.core.enums.RateLimitType; +import com.ibasco.agql.core.util.FailsafeOptions; import com.ibasco.agql.core.util.GeneralOptions; +import com.ibasco.agql.protocols.valve.source.query.SourceQueryClient; +import com.ibasco.agql.protocols.valve.source.query.SourceQueryOptions; import com.ibasco.agql.protocols.valve.source.query.info.SourceQueryInfoResponse; import com.ibasco.agql.protocols.valve.source.query.players.SourceQueryPlayerResponse; import com.ibasco.agql.protocols.valve.source.query.rcon.SourceRconClient; @@ -27,7 +31,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @Data -public class Server { +public class Server extends BaseServer { String name; String description; String address; @@ -129,15 +133,6 @@ public class Server { return ""; } } - @JsonIgnore - public SourceRconClient GetSourceRconClient() { - ExecutorService customExecutor = Executors.newCachedThreadPool(); - SourceRconOptions options = SourceRconOptions.builder() - //.option(FailsafeOptions.FAILSAFE_RATELIMIT_TYPE, RateLimitType.BURST) - .option(GeneralOptions.THREAD_EXECUTOR_SERVICE, customExecutor) - .build(); - return new SourceRconClient(options); - } public void SetDownStatus() { setStatus(false);