guacamole-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mjum...@apache.org
Subject [02/28] incubator-guacamole-client git commit: GUACAMOLE-102: Make getConnectionWeight return int, clean up compare code.
Date Wed, 07 Jun 2017 00:32:22 GMT
GUACAMOLE-102: Make getConnectionWeight return int, clean up compare 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/f77c5073
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/f77c5073
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/f77c5073

Branch: refs/heads/master
Commit: f77c50730d09e4d02eff887d82a01ab84fd3ff09
Parents: aa4c134
Author: Nick Couchman <vnick@apache.org>
Authored: Fri Jun 2 20:05:15 2017 -0400
Committer: Nick Couchman <nick.couchman@yahoo.com>
Committed: Mon Jun 5 15:34:21 2017 -0400

----------------------------------------------------------------------
 .../auth/jdbc/connection/ConnectionModel.java       | 12 +++++++-----
 .../auth/jdbc/connection/ModeledConnection.java     |  2 +-
 .../tunnel/RestrictedGuacamoleTunnelService.java    | 16 ++++------------
 3 files changed, 12 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/f77c5073/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java
b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java
index 69ef4c3..2da37a7 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java
@@ -184,16 +184,18 @@ public class ConnectionModel extends ChildObjectModel {
 
     /**
      * Returns the connection weight used in calculating the
-     * WRR algorithm.
+     * weighted algorithms.
      *
      * @return
-     *     The connection weight.  Null indicates no weight has been set,
-     *     -1 indicates that the system is unavailable.
+     *     The connection weight as an int.  If the weight is
+     *     null a default weight of 1 is returned.  Zero and
+     *     negative numbers are used to indicate the system is
+     *     unavailable.
      */
-    public Integer getConnectionWeight() {
+    public int getConnectionWeight() {
         if (connectionWeight == null)
             return 1;
-        return connectionWeight;
+        return connectionWeight.intValue();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/f77c5073/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java
b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java
index 414a8a4..67bd793 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java
@@ -418,7 +418,7 @@ public class ModeledConnection extends ModeledChildDirectoryObject<ConnectionMod
      *     The weight of the connection.
      *  
      */
-    public Integer getConnectionWeight() {
+    public int getConnectionWeight() {
 
         // Return the connection weight
         return getModel().getConnectionWeight();

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/f77c5073/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 56d2f5b..bee5dd3 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
@@ -23,7 +23,6 @@ import com.google.common.collect.ConcurrentHashMultiset;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.Comparator;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -188,15 +187,8 @@ public class RestrictedGuacamoleTunnelService
             @Override
             public int compare(ModeledConnection a, ModeledConnection b) {
 
-                // Get connection weight for the two systems being compared.            
   
-                int weightA = a.getConnectionWeight().intValue();
-                int weightB = b.getConnectionWeight().intValue();
-
-                // 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;
-
-                return (connsA * weightB) - (connsB * weightA);
+                return ((getActiveConnections(a).size() + 1) * b.getConnectionWeight() -
+                        (getActiveConnections(b).size() + 1) * a.getConnectionWeight());
 
             }
 
@@ -209,8 +201,8 @@ public class RestrictedGuacamoleTunnelService
         for (ModeledConnection connection : sortedConnections) {
 
             // If connection weight is zero or negative, this host is disabled and should
not be used.
-            if (connection.getConnectionWeight() != null && connection.getConnectionWeight().intValue()
< 1) {
-                logger.warn("Weight for {} is non-null and < 1, connection will be skipped.",
connection.getName());
+            if (connection.getConnectionWeight() < 1) {
+                logger.warn("Weight for {} is < 1, connection will be skipped.", connection.getName());
                 continue;
             }
 


Mime
View raw message