GUACAMOLE-102: Correction to WLC algorithm to try to keep ratio no higher than 
configure weights.


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/874b29ba
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/874b29ba
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/874b29ba

Branch: refs/heads/master
Commit: 874b29bae309e198db991035604082eda1f78768
Parents: 25493a8
Author: Nick Couchman <vn...@apache.org>
Authored: Mon Jun 5 21:34:50 2017 -0400
Committer: Nick Couchman <vn...@apache.org>
Committed: Mon Jun 5 21:43:31 2017 -0400

----------------------------------------------------------------------
 .../RestrictedGuacamoleTunnelService.java       | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/874b29ba/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 d4ab8aa..6480ec7 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
@@ -187,8 +187,24 @@ public class RestrictedGuacamoleTunnelService
             @Override
             public int compare(ModeledConnection a, ModeledConnection b) {
 
-                return ((getActiveConnections(a).size() + 1) * 
b.getConnectionWeight() -
-                            (getActiveConnections(b).size() + 1) * 
a.getConnectionWeight());
+                // Active connections
+                int Ca = getActiveConnections(a).size();
+                int Cb = getActiveConnections(b).size();
+
+                // Assigned weight
+                int Wa = a.getConnectionWeight();
+                int Wb = b.getConnectionWeight();
+
+                // Net weight of connections
+                int NWa = Ca * Wb;
+                int NWb = Cb * Wa;
+
+                // If net weights are equal, return difference in weight
+                if (NWa == NWb)
+                    return (Wa - Wb);
+
+                // Return different in net weights
+                return (NWa - NWb);
 
             }
 

Reply via email to