From 265fa45371c9c209fc27d2ff658a25aa20f35b22 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Sep 2021 07:56:26 +0200 Subject: [PATCH] Prefer local node Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/Node.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/de/steamwar/bungeecore/Node.java b/src/de/steamwar/bungeecore/Node.java index cb34986..f0afc09 100644 --- a/src/de/steamwar/bungeecore/Node.java +++ b/src/de/steamwar/bungeecore/Node.java @@ -39,8 +39,11 @@ public abstract class Node { public static Node local = null; public static Node getNode() { - Node node = null; - double minLoad = Double.POSITIVE_INFINITY; + Node node = local; + double minLoad = local.getLoad(); + if(minLoad < 0.5) + return local; + synchronized (nodes) { Iterator it = nodes.iterator(); while(it.hasNext()) { @@ -59,17 +62,12 @@ public abstract class Node { } public static void forEach(Consumer consumer) { + consumer.accept(local); synchronized (nodes) { 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 void execute(String... command); public abstract String getName(); @@ -120,7 +118,6 @@ public abstract class Node { private final int cores; public LocalNode() { - super(); this.cores = Runtime.getRuntime().availableProcessors(); local = this; } @@ -172,7 +169,6 @@ public abstract class Node { private final String remote; public RemoteNode(String remote) { - super(); this.remote = remote; //Determin core count @@ -199,6 +195,10 @@ public abstract class Node { c = 1; } cores = c; + + synchronized (nodes) { + nodes.add(this); + } } @Override