SteamWar/BungeeCore
Archiviert
13
2

Auto core count detection

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2021-09-16 17:12:22 +02:00
Ursprung 85fe4ba264
Commit d73c0ea7ea
2 geänderte Dateien mit 28 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -90,8 +90,8 @@ public class BungeeCore extends Plugin {
new BrandListener();
new Node.LocalNode();
new Node.RemoteNode("lx", 8);
new Node.RemoteNode("az", 10);
new Node.RemoteNode("lx");
new Node.RemoteNode("az");
commands.put("/tp", null);
commands.put("/bc", null);

Datei anzeigen

@ -171,10 +171,34 @@ public abstract class Node {
private final int cores;
private final String remote;
public RemoteNode(String remote, int cores) {
public RemoteNode(String remote) {
super();
this.cores = cores;
this.remote = remote;
//Determin core count
Process process;
try {
process = new ProcessBuilder("ssh", remote, "nproc").start();
if(!process.waitFor(5, TimeUnit.SECONDS))
throw new IOException("Timeout of " + remote + " on init");
} catch (IOException e) {
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not initialize " + remote);
cores = 1;
return;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
cores = 1;
return;
}
int c;
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
c = Integer.parseInt(bufferedReader.readLine());
} catch (IOException e) {
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not read cores of" + remote, e);
c = 1;
}
cores = c;
}
@Override