GUAC-1373: Clean up logic surrounding legacy concurrency properties.

This commit is contained in:
Michael Jumper
2015-11-12 11:35:59 -08:00
parent 5cb228391c
commit ea87134879

View File

@@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
* properties specifically for MySQL. * properties specifically for MySQL.
* *
* @author James Muehlner * @author James Muehlner
* @author Michael Jumper
*/ */
public class MySQLEnvironment extends JDBCEnvironment { public class MySQLEnvironment extends JDBCEnvironment {
@@ -50,26 +51,74 @@ public class MySQLEnvironment extends JDBCEnvironment {
*/ */
private static final int DEFAULT_PORT = 3306; private static final int DEFAULT_PORT = 3306;
/**
* The default value for the default maximum number of connections to be
* allowed per user to any one connection. Note that, as long as the
* legacy "disallow duplicate" and "disallow simultaneous" properties are
* still supported, these cannot be constants, as the legacy properties
* dictate the values that should be used in the absence of the correct
* properties.
*/
private int DEFAULT_MAX_CONNECTIONS_PER_USER = 1;
/**
* The default value for the default maximum number of connections to be
* allowed per user to any one connection group. Note that, as long as the
* legacy "disallow duplicate" and "disallow simultaneous" properties are
* still supported, these cannot be constants, as the legacy properties
* dictate the values that should be used in the absence of the correct
* properties.
*/
private int DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER = 1;
/**
* The default value for the default maximum number of connections to be
* allowed to any one connection. Note that, as long as the legacy
* "disallow duplicate" and "disallow simultaneous" properties are still
* supported, these cannot be constants, as the legacy properties dictate
* the values that should be used in the absence of the correct properties.
*/
private int DEFAULT_MAX_CONNECTIONS = 0;
/**
* The default value for the default maximum number of connections to be
* allowed to any one connection group. Note that, as long as the legacy
* "disallow duplicate" and "disallow simultaneous" properties are still
* supported, these cannot be constants, as the legacy properties dictate
* the values that should be used in the absence of the correct properties.
*/
private int DEFAULT_MAX_GROUP_CONNECTIONS = 0;
/** /**
* Constructs a new MySQLEnvironment, providing access to MySQL-specific * Constructs a new MySQLEnvironment, providing access to MySQL-specific
* configuration options. * configuration options.
* *
* @throws GuacamoleException * @throws GuacamoleException
* If an error occurs while setting up the underlying JDBCEnvironment. * If an error occurs while setting up the underlying JDBCEnvironment
* or while parsing legacy MySQL configuration options.
*/ */
public MySQLEnvironment() throws GuacamoleException { public MySQLEnvironment() throws GuacamoleException {
super();
}
/** // Init underlying JDBC environment
* Log a warning about the usage of the deprecated super();
* MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS property, and the appropriate
* replacements for it. // Read legacy concurrency-related property
* Boolean disallowSimultaneous = getProperty(MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS);
* @param disallowSimultaneous Boolean disallowDuplicate = getProperty(MySQLGuacamoleProperties.MYSQL_DISALLOW_DUPLICATE_CONNECTIONS);
* Whether simultaneous connections have been disabled.
*/ // Legacy "simultaneous" property dictates only the maximum number of
private void warnOfSimultaneousPropertyDeprecation(boolean disallowSimultaneous) { // connections per connection
if (disallowSimultaneous != null) {
// Translate legacy property
if (disallowSimultaneous) {
DEFAULT_MAX_CONNECTIONS = 1;
DEFAULT_MAX_GROUP_CONNECTIONS = 0;
}
else {
DEFAULT_MAX_CONNECTIONS = 0;
DEFAULT_MAX_GROUP_CONNECTIONS = 0;
}
// Warn of deprecation // Warn of deprecation
logger.warn("The \"{}\" property is deprecated. Use \"{}\" and \"{}\" instead.", logger.warn("The \"{}\" property is deprecated. Use \"{}\" and \"{}\" instead.",
@@ -80,20 +129,24 @@ public class MySQLEnvironment extends JDBCEnvironment {
// Inform of new equivalent // Inform of new equivalent
logger.info("To achieve the same result of setting \"{}\" to \"{}\", set \"{}\" to \"{}\" and \"{}\" to \"{}\".", logger.info("To achieve the same result of setting \"{}\" to \"{}\", set \"{}\" to \"{}\" and \"{}\" to \"{}\".",
MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS.getName(), disallowSimultaneous, MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS.getName(), disallowSimultaneous,
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS.getName(), disallowSimultaneous ? 1 : 0, MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS.getName(), DEFAULT_MAX_CONNECTIONS,
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS.getName(), 0); MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS.getName(), DEFAULT_MAX_GROUP_CONNECTIONS);
} }
/** // Legacy "duplicate" property dictates whether connections and groups
* Log a warning about the usage of the deprecated // may be used concurrently only by different users
* MYSQL_DISALLOW_DUPLICATE_CONNECTIONS property, and the appropriate if (disallowDuplicate != null) {
* replacements for it.
* // Translate legacy property
* @param disallowDuplicate if (disallowDuplicate) {
* Whether duplicate connections have been disabled. DEFAULT_MAX_CONNECTIONS_PER_USER = 1;
*/ DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER = 1;
private void warnOfDuplicatePropertyDeprecation(boolean disallowDuplicate) { }
else {
DEFAULT_MAX_CONNECTIONS_PER_USER = 0;
DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER = 0;
}
// Warn of deprecation // Warn of deprecation
logger.warn("The \"{}\" property is deprecated. Use \"{}\" and \"{}\" instead.", logger.warn("The \"{}\" property is deprecated. Use \"{}\" and \"{}\" instead.",
@@ -104,138 +157,43 @@ public class MySQLEnvironment extends JDBCEnvironment {
// Inform of new equivalent // Inform of new equivalent
logger.info("To achieve the same result of setting \"{}\" to \"{}\", set \"{}\" to \"{}\" and \"{}\" to \"{}\".", logger.info("To achieve the same result of setting \"{}\" to \"{}\", set \"{}\" to \"{}\" and \"{}\" to \"{}\".",
MySQLGuacamoleProperties.MYSQL_DISALLOW_DUPLICATE_CONNECTIONS.getName(), disallowDuplicate, MySQLGuacamoleProperties.MYSQL_DISALLOW_DUPLICATE_CONNECTIONS.getName(), disallowDuplicate,
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS_PER_USER.getName(), disallowDuplicate ? 1 :0, MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS_PER_USER.getName(), DEFAULT_MAX_CONNECTIONS_PER_USER,
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER.getName(), disallowDuplicate ? 1 :0); MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER.getName(), DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER);
}
} }
@Override @Override
public int getDefaultMaxConnections() throws GuacamoleException { public int getDefaultMaxConnections() throws GuacamoleException {
return getProperty(
// Tunnel service default configuration MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS,
int connectionDefaultMaxConnections; DEFAULT_MAX_CONNECTIONS
);
// Read legacy concurrency-related property
Boolean disallowSimultaneous = getProperty(MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS);
// Legacy "simultaneous" property dictates only the maximum number of
// connections per connection
if (disallowSimultaneous != null) {
// Translate legacy property
if (disallowSimultaneous) {
connectionDefaultMaxConnections = 1;
}
else {
connectionDefaultMaxConnections = 0;
}
// Warn that a different property should be used going forward
warnOfSimultaneousPropertyDeprecation(disallowSimultaneous);
}
// If legacy property is not specified, use new property
else {
connectionDefaultMaxConnections = getProperty(MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS, 0);
}
return connectionDefaultMaxConnections;
} }
@Override @Override
public int getDefaultMaxGroupConnections() throws GuacamoleException { public int getDefaultMaxGroupConnections() throws GuacamoleException {
return getProperty(
int connectionGroupDefaultMaxConnections; MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS,
DEFAULT_MAX_GROUP_CONNECTIONS
// Read legacy concurrency-related property );
Boolean disallowSimultaneous = getProperty(MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS);
// Legacy "simultaneous" property dictates only the maximum number of
// connections per connection
if (disallowSimultaneous != null) {
// Translate legacy property
connectionGroupDefaultMaxConnections = 0;
// Warn that a different property should be used going forward
warnOfSimultaneousPropertyDeprecation(disallowSimultaneous);
}
// If legacy property is not specified, use new property
else {
connectionGroupDefaultMaxConnections = getProperty(MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS, 0);
}
return connectionGroupDefaultMaxConnections;
} }
@Override @Override
public int getDefaultMaxConnectionsPerUser() throws GuacamoleException { public int getDefaultMaxConnectionsPerUser() throws GuacamoleException {
return getProperty(
int connectionDefaultMaxConnectionsPerUser; MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS_PER_USER,
DEFAULT_MAX_CONNECTIONS_PER_USER
// Read legacy concurrency-related properties );
Boolean disallowDuplicate = getProperty(MySQLGuacamoleProperties.MYSQL_DISALLOW_DUPLICATE_CONNECTIONS);
// Legacy "duplicate" property dictates whether connections and groups
// may be used concurrently only by different users
if (disallowDuplicate != null) {
// Translate legacy property
if (disallowDuplicate) {
connectionDefaultMaxConnectionsPerUser = 1;
}
else {
connectionDefaultMaxConnectionsPerUser = 0;
}
// Warn that a different property should be used going forward
warnOfDuplicatePropertyDeprecation(disallowDuplicate);
}
// If legacy property is not specified, use new property
else {
connectionDefaultMaxConnectionsPerUser = getProperty(MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS_PER_USER, 1);
}
return connectionDefaultMaxConnectionsPerUser;
} }
@Override @Override
public int getDefaultMaxGroupConnectionsPerUser() throws GuacamoleException { public int getDefaultMaxGroupConnectionsPerUser() throws GuacamoleException {
return getProperty(
int connectionGroupDefaultMaxConnectionsPerUser; MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER,
DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER
// Read legacy concurrency-related property );
Boolean disallowDuplicate = getProperty(MySQLGuacamoleProperties.MYSQL_DISALLOW_DUPLICATE_CONNECTIONS);
// Legacy "duplicate" property dictates whether connections and groups
// may be used concurrently only by different users
if (disallowDuplicate != null) {
// Translate legacy property
if (disallowDuplicate) {
connectionGroupDefaultMaxConnectionsPerUser = 1;
}
else {
connectionGroupDefaultMaxConnectionsPerUser = 0;
}
// Warn that a different property should be used going forward
warnOfDuplicatePropertyDeprecation(disallowDuplicate);
}
// If legacy property is not specified, use new property
else {
connectionGroupDefaultMaxConnectionsPerUser = getProperty(MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER, 1);
}
return connectionGroupDefaultMaxConnectionsPerUser;
} }
/** /**