You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.7 KiB
80 lines
2.7 KiB
package app.updates;
|
|
|
|
import app.entities.Stats;
|
|
import jakarta.annotation.PostConstruct;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.core.annotation.Order;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.io.IOException;
|
|
import java.time.Instant;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.concurrent.Callable;
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
|
|
@Component
|
|
public class PlayersUpdater extends BaseUpdater{
|
|
Stats stats;
|
|
|
|
@Value("${backend.updates.a2s}")
|
|
private boolean update = false;
|
|
private int timeout = 60 * 1000;
|
|
private final Logger logger = LoggerFactory.getLogger(PlayersUpdater.class);
|
|
@Autowired
|
|
public PlayersUpdater(Stats stats) {
|
|
this.stats = stats;
|
|
}
|
|
|
|
/*
|
|
public void updateValues() {
|
|
if (update) {
|
|
logger.warn("Updater enabled");
|
|
if (stats.getServers().size()==0) logger.error("Not found servers to update");
|
|
stats.getServers().forEach((server_name, server) -> {
|
|
CreateTaskUpdater(() -> {
|
|
logger.info("Update players from: {} server", server_name);
|
|
server.RefreshServerA2SData();
|
|
stats.getUpdates().merge(server_name, Instant.now().getEpochSecond(), (x, y) -> y);
|
|
return null;
|
|
}, timeout);
|
|
});
|
|
} else {
|
|
logger.warn("A2S Refresh disabled! Enable last timecheck");
|
|
if (stats.getServers().size()==0) logger.error("Not found servers to update");
|
|
stats.getServers().forEach((server_name, server) -> {
|
|
CreateTaskUpdater(() -> {
|
|
logger.info("Update players from: {} server", server_name);
|
|
server.RefreshLastCheck(60);
|
|
return null;
|
|
}, 15000);
|
|
});
|
|
}
|
|
}*/
|
|
|
|
public void burstUpdater() {
|
|
if (!update) return;
|
|
|
|
ExecutorService executor = Executors.newCachedThreadPool();
|
|
List tasks = new ArrayList<>();
|
|
stats.getServers().forEach((server_name, server) -> {
|
|
tasks.add((Callable<Void>) () -> {
|
|
server.RefreshServerA2SData();
|
|
return null;
|
|
});
|
|
});
|
|
|
|
try {
|
|
executor.invokeAll(tasks);
|
|
executor.shutdown();
|
|
} catch (InterruptedException err) {
|
|
logger.error("Cancel burst servers update");
|
|
}
|
|
}
|
|
}
|
|
|