GUACAMOLE-102: Clean up and simplify WLC sorting code.
Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/f2285272 Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/f2285272 Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/f2285272 Branch: refs/heads/master Commit: f22852721c12d38716aec8aad001f0986b31223c Parents: 56f6c4b Author: Nick Couchman <vn...@apache.org> Authored: Wed May 31 21:39:16 2017 -0400 Committer: Nick Couchman <nick.couch...@yahoo.com> Committed: Mon Jun 5 15:34:21 2017 -0400 ---------------------------------------------------------------------- .../RestrictedGuacamoleTunnelService.java | 27 ++++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/f2285272/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java ---------------------------------------------------------------------- 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 590648c..744d2e8 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;