mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUACAMOLE-102: Make getConnectionWeight return int, clean up compare code.
This commit is contained in:
committed by
Nick Couchman
parent
aa4c134922
commit
f77c50730d
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user