You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by mj...@apache.org on 2017/06/07 00:32:28 UTC
[08/28] incubator-guacamole-client git commit: GUACAMOLE-102: Remove
redundant iterations through connections.
GUACAMOLE-102: Remove redundant iterations through connections.
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/56f6c4bb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/56f6c4bb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/56f6c4bb
Branch: refs/heads/master
Commit: 56f6c4bb2ff93e3af4538d3f8011a89716f292e3
Parents: 075e880
Author: Nick Couchman <vn...@apache.org>
Authored: Wed May 31 20:18:25 2017 -0400
Committer: Nick Couchman <ni...@yahoo.com>
Committed: Mon Jun 5 15:34:21 2017 -0400
----------------------------------------------------------------------
.../RestrictedGuacamoleTunnelService.java | 27 +++++++++++++-------
1 file changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/56f6c4bb/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 49af081..590648c 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
@@ -48,6 +48,11 @@ public class RestrictedGuacamoleTunnelService
extends AbstractGuacamoleTunnelService {
/**
+ * Logger for this class.
+ */
+ private static final Logger logger = LoggerFactory.getLogger(RestrictedGuacamoleTunnelService.class);
+
+ /**
* The environment of the Guacamole server.
*/
@Inject
@@ -176,14 +181,6 @@ public class RestrictedGuacamoleTunnelService
// Get username
String username = user.getIdentifier();
- // Remove connections where weight < 0
- Iterator<ModeledConnection> i = connections.iterator();
- while(i.hasNext()) {
- Integer weight = i.next().getConnectionWeight();
- if (weight != null && weight.intValue() < 0)
- i.remove();
- }
-
// Sort connections in ascending order of usage
ModeledConnection[] sortedConnections = connections.toArray(new ModeledConnection[connections.size()]);
Arrays.sort(sortedConnections, new Comparator<ModeledConnection>() {
@@ -195,12 +192,22 @@ public class RestrictedGuacamoleTunnelService
// 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;
else
weightA = a.getConnectionWeight().intValue() + 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;
else
weightB = b.getConnectionWeight().intValue() + 1;
@@ -220,8 +227,10 @@ 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() < 1)
+ if (connection.getConnectionWeight() != null && connection.getConnectionWeight().intValue() < 1) {
+ logger.warn("Weight for {} is non-null and < 1, connection will be skipped.", connection.getName());
continue;
+ }
// Attempt to aquire connection according to per-user limits
Seat seat = new Seat(username, connection.getIdentifier());