From f22852721c12d38716aec8aad001f0986b31223c Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Wed, 31 May 2017 21:39:16 -0400 Subject: [PATCH] GUACAMOLE-102: Clean up and simplify WLC sorting code. --- .../RestrictedGuacamoleTunnelService.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index 590648cb7..744d2e8e9 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -189,28 +189,21 @@ public class RestrictedGuacamoleTunnelService public int compare(ModeledConnection a, ModeledConnection b) { int weightA, weightB; - // Check if weight of a is null, assign 1 if it is. - if (a.getConnectionWeight() == null) - weightA = 1; - // If weight is less than 1, host will be disabled - // but for sorting we set it to 1 to avoid divide - // by 0. - else if (a.getConnectionWeight().intValue() < 1) - weightA = 1; + // Check if weight of a is non-null and retrieve it. + if (a.getConnectionWeight() != null && a.getConnectionWeight().intValue() > 0) + weightA = a.getConnectionWeight().intValue(); + // In all other cases assign 1 for sorting. else - weightA = a.getConnectionWeight().intValue() + 1; + weightA = 1; // Check if weight of b is null, assign 1 if it is. - if (b.getConnectionWeight() == null) - weightB = 1; - // If weight is less than 1, host will be disabled, - // but for sorting we set it to 1 to avoid divide - // by 0. - else if (b.getConnectionWeight().intValue() < 1) - weightB = 1; + if (b.getConnectionWeight() != null && b.getConnectionWeight().intValue() > 0) + weightB = b.getConnectionWeight().intValue(); + // In all other cases assign 1 for sorting. else - weightB = b.getConnectionWeight().intValue() + 1; + weightB = 1; + // Get current active connections, add 1 to both to avoid calculations with 0. int connsA = getActiveConnections(a).size() + 1; int connsB = getActiveConnections(b).size() + 1;