Browse Source

online updater

master
gsd 12 months ago
parent
commit
3f989d77cf
  1. 11
      src/main/java/app/controllers/other/PulseController.java
  2. 11
      src/main/java/app/updates/OnlineUpdater.java

11
src/main/java/app/controllers/other/PulseController.java

@ -1,6 +1,7 @@
package app.controllers.other; package app.controllers.other;
import app.services.db.DBService; import app.services.db.DBService;
import app.updates.OnlineUpdater;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -13,14 +14,22 @@ import org.springframework.web.bind.annotation.RestController;
public class PulseController { public class PulseController {
DBService dbService; DBService dbService;
OnlineUpdater onlineUpdater;
@Autowired @Autowired
public PulseController(DBService dbService) { public PulseController(DBService dbService,
OnlineUpdater onlineUpdater) {
this.dbService = dbService; this.dbService = dbService;
this.onlineUpdater = onlineUpdater;
} }
@GetMapping("/db") @GetMapping("/db")
public ResponseEntity<Long> getDBPulse() { public ResponseEntity<Long> getDBPulse() {
return new ResponseEntity(dbService.getDBServerTime(), HttpStatus.OK); return new ResponseEntity(dbService.getDBServerTime(), HttpStatus.OK);
} }
@GetMapping("/db/diff")
public ResponseEntity<Long> getDiff() {
return new ResponseEntity<>(onlineUpdater.getDifferentReplica(), HttpStatus.OK);
}
} }

11
src/main/java/app/updates/OnlineUpdater.java

@ -20,6 +20,11 @@ public class OnlineUpdater extends BaseUpdater {
@Autowired @Autowired
@Qualifier("jt_rw") @Qualifier("jt_rw")
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@Autowired
@Qualifier("jt_ro")
private JdbcTemplate jdbcTemplate_ro;
private final static int sleep_time = 30 * 1000; private final static int sleep_time = 30 * 1000;
@Autowired @Autowired
@ -45,6 +50,12 @@ public class OnlineUpdater extends BaseUpdater {
return true; return true;
} }
public long getDifferentReplica() {
Long rw = jdbcTemplate.query("SELECT COUNT(*) FROM `servers_online`", (rs, n) -> rs.getLong(1)).get(0);
Long ro = jdbcTemplate.query("SELECT COUNT(*) FROM `servers_online`", (rs, n) -> rs.getLong(1)).get(0);
return Math.abs(rw - ro);
}
//CREATE TABLE `tf2.facti13`.`servers_online` (`id` INT NOT NULL AUTO_INCREMENT , `utime` INT NOT NULL , `player_count` INT NOT NULL , `max_players` INT NOT NULL , `server_id` VARCHAR(32) NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB; //CREATE TABLE `tf2.facti13`.`servers_online` (`id` INT NOT NULL AUTO_INCREMENT , `utime` INT NOT NULL , `player_count` INT NOT NULL , `max_players` INT NOT NULL , `server_id` VARCHAR(32) NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
public class ServerOnline { public class ServerOnline {
private int id; private int id;

Loading…
Cancel
Save