Browse Source

если каждый раз создавать поточки, то память будет засрана io.netty.util.internal.shaded.org.jctools.queues.MpscUnboundedArrayQueue

master
gsd 2 years ago
parent
commit
ed6df4eec1
  1. 13
      src/main/java/app/entities/Stats.java
  2. 41
      src/main/java/app/entities/server/BaseServer.java
  3. 15
      src/main/java/app/entities/server/Server.java

13
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);
}
}

41
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);
}
}

15
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);

Loading…
Cancel
Save