Browse Source

exit is config

master
gsd 10 months ago
parent
commit
805d09044c
  1. 18
      src/main/java/app/controllers/StatsController.java
  2. 12
      src/main/java/app/services/io/readers/ServersReader.java

18
src/main/java/app/controllers/StatsController.java

@ -1,11 +1,12 @@
package app.controllers;
import app.annotations.enums.CollectStages;
import app.annotations.interfaces.BurstUpdatePlayers;
import app.annotations.interfaces.CollectStatistic;
import app.annotations.interfaces.*;
import app.entities.Stats;
import app.services.ExternalServices;
import app.services.io.readers.ServersReader;
import app.updates.OnlineUpdater;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -25,12 +26,14 @@ public class StatsController {
private ExternalServices externalServices;
private OnlineUpdater onlineUpdater;
private HashMap<Integer, HashMap<List<OnlineUpdater.StatsOfPeakOfDay>, Long>> cache = new HashMap<>();
private ServersReader serversReader;
@Autowired
public StatsController(Stats stats, ExternalServices externalServices, OnlineUpdater onlineUpdater){
public StatsController(Stats stats, ExternalServices externalServices, OnlineUpdater onlineUpdater, ServersReader serversReader){
this.stats = stats;
this.externalServices = externalServices;
this.onlineUpdater = onlineUpdater;
this.serversReader = serversReader;
}
@GetMapping
@ -61,4 +64,13 @@ public class StatsController {
return new ResponseEntity<>(cache.get(limit).keySet().stream().findFirst().orElse(null), HttpStatus.OK);
}
@GetMapping("/reload")
@CheckWebAccess
@CheckPermitionFlag(flag = "z")
@WaitAfterNext(order = "reload_config")
@CollectStatistic(stage = CollectStages.COMBINED)
public ResponseEntity<Boolean> reloadConfig(HttpServletRequest request) {
return new ResponseEntity<>(serversReader.call(false), HttpStatus.OK);
}
}

12
src/main/java/app/services/io/readers/ServersReader.java

@ -20,16 +20,24 @@ public class ServersReader extends BaseReader {
public ServersReader(Stats stats, List<IFileLoader> fileLoaders) {
super(fileLoaders);
this.stats = stats;
call(true);
}
public boolean call(boolean exit) {
try {
logger.info("Try load base server configuration");
Iterator<Map.Entry<String, JsonNode>> iterator = loadConfiguration().fields();
while (iterator.hasNext()) {
Map.Entry<String, JsonNode> server = iterator.next();
stats.getServers().put(server.getKey(), objectMapper.treeToValue(server.getValue(), Server.class));
logger.info("{}\n{}",server.getKey() ,stats.getServers().get(server.getKey()));
}
return true;
} catch (IOException err) {
logger.error("Cannot parse configuration", err);
System.exit(1);
logger.error("Cannot parse configuration, exit enabled: " + (exit?"yes":"no"), err);
if (exit)
System.exit(1);
return false;
}
}

Loading…
Cancel
Save