mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-830: Add concurrency limitations to connection and connection group model objects.
This commit is contained in:
@@ -41,7 +41,21 @@ public class ConnectionModel extends GroupedObjectModel {
|
||||
* The name of the protocol to use when connecting to this connection.
|
||||
*/
|
||||
private String protocol;
|
||||
|
||||
|
||||
/**
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection concurrently, zero if no restriction applies, or null if the
|
||||
* default restrictions should be applied.
|
||||
*/
|
||||
private Integer maxConnections;
|
||||
|
||||
/**
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection concurrently by any one user, zero if no restriction applies,
|
||||
* or null if the default restrictions should be applied.
|
||||
*/
|
||||
private Integer maxConnectionsPerUser;
|
||||
|
||||
/**
|
||||
* Creates a new, empty connection.
|
||||
*/
|
||||
@@ -89,6 +103,58 @@ public class ConnectionModel extends GroupedObjectModel {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of connections that can be established to
|
||||
* this connection concurrently.
|
||||
*
|
||||
* @return
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection concurrently, zero if no restriction applies, or null if
|
||||
* the default restrictions should be applied.
|
||||
*/
|
||||
public Integer getMaxConnections() {
|
||||
return maxConnections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum number of connections that can be established to this
|
||||
* connection concurrently.
|
||||
*
|
||||
* @param maxConnections
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection concurrently, zero if no restriction applies, or null if
|
||||
* the default restrictions should be applied.
|
||||
*/
|
||||
public void setMaxConnections(Integer maxConnections) {
|
||||
this.maxConnections = maxConnections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of connections that can be established to
|
||||
* this connection concurrently by any one user.
|
||||
*
|
||||
* @return
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection concurrently by any one user, zero if no restriction
|
||||
* applies, or null if the default restrictions should be applied.
|
||||
*/
|
||||
public Integer getMaxConnectionsPerUser() {
|
||||
return maxConnectionsPerUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum number of connections that can be established to this
|
||||
* connection concurrently by any one user.
|
||||
*
|
||||
* @param maxConnectionsPerUser
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection concurrently by any one user, zero if no restriction
|
||||
* applies, or null if the default restrictions should be applied.
|
||||
*/
|
||||
public void setMaxConnectionsPerUser(Integer maxConnectionsPerUser) {
|
||||
this.maxConnectionsPerUser = maxConnectionsPerUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
|
||||
|
@@ -42,7 +42,21 @@ public class ConnectionGroupModel extends GroupedObjectModel {
|
||||
* The type of this connection group, such as organizational or balancing.
|
||||
*/
|
||||
private ConnectionGroup.Type type;
|
||||
|
||||
|
||||
/**
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection group concurrently, zero if no restriction applies, or
|
||||
* null if the default restrictions should be applied.
|
||||
*/
|
||||
private Integer maxConnections;
|
||||
|
||||
/**
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection group concurrently by any one user, zero if no restriction
|
||||
* applies, or null if the default restrictions should be applied.
|
||||
*/
|
||||
private Integer maxConnectionsPerUser;
|
||||
|
||||
/**
|
||||
* Creates a new, empty connection group.
|
||||
*/
|
||||
@@ -91,6 +105,60 @@ public class ConnectionGroupModel extends GroupedObjectModel {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of connections that can be established to
|
||||
* this connection group concurrently.
|
||||
*
|
||||
* @return
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection group concurrently, zero if no restriction applies, or
|
||||
* null if the default restrictions should be applied.
|
||||
*/
|
||||
public Integer getMaxConnections() {
|
||||
return maxConnections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum number of connections that can be established to this
|
||||
* connection group concurrently.
|
||||
*
|
||||
* @param maxConnections
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection group concurrently, zero if no restriction applies, or
|
||||
* null if the default restrictions should be applied.
|
||||
*/
|
||||
public void setMaxConnections(Integer maxConnections) {
|
||||
this.maxConnections = maxConnections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of connections that can be established to
|
||||
* this connection group concurrently by any one user.
|
||||
*
|
||||
* @return
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection group concurrently by any one user, zero if no
|
||||
* restriction applies, or null if the default restrictions should be
|
||||
* applied.
|
||||
*/
|
||||
public Integer getMaxConnectionsPerUser() {
|
||||
return maxConnectionsPerUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum number of connections that can be established to this
|
||||
* connection group concurrently by any one user.
|
||||
*
|
||||
* @param maxConnectionsPerUser
|
||||
* The maximum number of connections that can be established to this
|
||||
* connection group concurrently by any one user, zero if no
|
||||
* restriction applies, or null if the default restrictions should be
|
||||
* applied.
|
||||
*/
|
||||
public void setMaxConnectionsPerUser(Integer maxConnectionsPerUser) {
|
||||
this.maxConnectionsPerUser = maxConnectionsPerUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
|
||||
|
@@ -200,14 +200,23 @@ public class ConfigurableGuacamoleTunnelService
|
||||
// Return the first unreserved connection
|
||||
for (ModeledConnection connection : sortedConnections) {
|
||||
|
||||
// Determine per-user limits on this connection
|
||||
Integer connectionMaxConnectionsPerUser = connection.getModel().getMaxConnectionsPerUser();
|
||||
if (connectionMaxConnectionsPerUser == null)
|
||||
connectionMaxConnectionsPerUser = connectionDefaultMaxConnectionsPerUser;
|
||||
|
||||
// Determine overall limits on this connection
|
||||
Integer connectionMaxConnections = connection.getModel().getMaxConnections();
|
||||
if (connectionMaxConnections == null)
|
||||
connectionMaxConnections = connectionDefaultMaxConnections;
|
||||
|
||||
// Attempt to aquire connection according to per-user limits
|
||||
Seat seat = new Seat(username, connection.getIdentifier());
|
||||
if (tryAdd(activeSeats, seat,
|
||||
connectionDefaultMaxConnectionsPerUser)) {
|
||||
if (tryAdd(activeSeats, seat, connectionMaxConnectionsPerUser)) {
|
||||
|
||||
// Attempt to aquire connection according to overall limits
|
||||
if (tryAdd(activeConnections, connection.getIdentifier(),
|
||||
connectionDefaultMaxConnections))
|
||||
connectionMaxConnections))
|
||||
return connection;
|
||||
|
||||
// Acquire failed - retry with next connection
|
||||
@@ -243,14 +252,24 @@ public class ConfigurableGuacamoleTunnelService
|
||||
// Get username
|
||||
String username = user.getUser().getIdentifier();
|
||||
|
||||
// Determine per-user limits on this connection group
|
||||
Integer connectionGroupMaxConnectionsPerUser = connectionGroup.getModel().getMaxConnectionsPerUser();
|
||||
if (connectionGroupMaxConnectionsPerUser == null)
|
||||
connectionGroupMaxConnectionsPerUser = connectionGroupDefaultMaxConnectionsPerUser;
|
||||
|
||||
// Determine overall limits on this connection group
|
||||
Integer connectionGroupMaxConnections = connectionGroup.getModel().getMaxConnections();
|
||||
if (connectionGroupMaxConnections == null)
|
||||
connectionGroupMaxConnections = connectionGroupDefaultMaxConnections;
|
||||
|
||||
// Attempt to aquire connection group according to per-user limits
|
||||
Seat seat = new Seat(username, connectionGroup.getIdentifier());
|
||||
if (tryAdd(activeGroupSeats, seat,
|
||||
connectionGroupDefaultMaxConnectionsPerUser)) {
|
||||
connectionGroupMaxConnectionsPerUser)) {
|
||||
|
||||
// Attempt to aquire connection group according to overall limits
|
||||
if (tryAdd(activeGroups, connectionGroup.getIdentifier(),
|
||||
connectionGroupDefaultMaxConnections))
|
||||
connectionGroupMaxConnections))
|
||||
return;
|
||||
|
||||
// Acquire failed
|
||||
|
Reference in New Issue
Block a user