SteamWar/BungeeCore
Archiviert
13
2

Prefer local node

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2021-09-17 07:56:26 +02:00
Ursprung 4d563983f8
Commit 265fa45371

Datei anzeigen

@ -39,8 +39,11 @@ public abstract class Node {
public static Node local = null; public static Node local = null;
public static Node getNode() { public static Node getNode() {
Node node = null; Node node = local;
double minLoad = Double.POSITIVE_INFINITY; double minLoad = local.getLoad();
if(minLoad < 0.5)
return local;
synchronized (nodes) { synchronized (nodes) {
Iterator<Node> it = nodes.iterator(); Iterator<Node> it = nodes.iterator();
while(it.hasNext()) { while(it.hasNext()) {
@ -59,17 +62,12 @@ public abstract class Node {
} }
public static void forEach(Consumer<Node> consumer) { public static void forEach(Consumer<Node> consumer) {
consumer.accept(local);
synchronized (nodes) { synchronized (nodes) {
nodes.forEach(consumer); nodes.forEach(consumer);
} }
} }
protected Node() {
synchronized (nodes) {
nodes.add(this);
}
}
public abstract ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams); public abstract ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams);
public abstract void execute(String... command); public abstract void execute(String... command);
public abstract String getName(); public abstract String getName();
@ -120,7 +118,6 @@ public abstract class Node {
private final int cores; private final int cores;
public LocalNode() { public LocalNode() {
super();
this.cores = Runtime.getRuntime().availableProcessors(); this.cores = Runtime.getRuntime().availableProcessors();
local = this; local = this;
} }
@ -172,7 +169,6 @@ public abstract class Node {
private final String remote; private final String remote;
public RemoteNode(String remote) { public RemoteNode(String remote) {
super();
this.remote = remote; this.remote = remote;
//Determin core count //Determin core count
@ -199,6 +195,10 @@ public abstract class Node {
c = 1; c = 1;
} }
cores = c; cores = c;
synchronized (nodes) {
nodes.add(this);
}
} }
@Override @Override