From d0647ad6a44d1a0785f29f40bd30412f8592e291 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 20 Mar 2017 06:49:10 -0400 Subject: [PATCH] GUACAMOLE-102: Initial stab at a WLC algorithm. --- .../RestrictedGuacamoleTunnelService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 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 9c0191763..92cdfc6b1 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 @@ -191,9 +191,22 @@ public class RestrictedGuacamoleTunnelService public int compare(ModeledConnection a, ModeledConnection b) { logger.trace("Comparing {} to {}.", a.getName(), b.getName()); - return getActiveConnections(a).size() - - getActiveConnections(b).size(); + int cw = 0; + try { + if(a.getConnectionWeight() > 0 && b.getConnectionWeight() > 0) + cw = (int)(a.getConnectionWeight()/getActiveConnections(a).size() - b.getConnectionWeight()/getActiveConnections(b).size()); + else + cw = getActiveConnections(a).size() - getActiveConnections(b).size(); + + } + catch (GuacamoleException e) { + logger.error("Could not compare connections.", e.getMessage()); + logger.debug("Could not compare connections.", e); + } + + return cw; + } });