mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-1101: Manage active connection records using sets rather than lists.
This commit is contained in:
@@ -26,6 +26,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -367,6 +368,7 @@ public class ConnectionService extends DirectoryObjectService<ModeledConnection,
|
||||
|
||||
// Get currently-active connections
|
||||
List<ConnectionRecord> records = new ArrayList<ConnectionRecord>(socketService.getActiveConnections(connection));
|
||||
Collections.reverse(records);
|
||||
|
||||
// Add past connections from model objects
|
||||
for (ConnectionRecordModel model : models)
|
||||
|
@@ -268,7 +268,7 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConnectionRecord> getActiveConnections(Connection connection) {
|
||||
public Collection<ConnectionRecord> getActiveConnections(Connection connection) {
|
||||
return activeConnections.get(connection.getIdentifier());
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConnectionRecord> getActiveConnections(ConnectionGroup connectionGroup) {
|
||||
public Collection<ConnectionRecord> getActiveConnections(ConnectionGroup connectionGroup) {
|
||||
|
||||
// If not a balancing group, assume no connections
|
||||
if (connectionGroup.getType() != ConnectionGroup.Type.BALANCING)
|
||||
|
@@ -22,11 +22,12 @@
|
||||
|
||||
package org.glyptodon.guacamole.auth.jdbc.socket;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
||||
|
||||
|
||||
@@ -43,8 +44,8 @@ public class ActiveConnectionMultimap {
|
||||
/**
|
||||
* All active connections to a connection having a given identifier.
|
||||
*/
|
||||
private final Map<String, LinkedList<ConnectionRecord>> records =
|
||||
new HashMap<String, LinkedList<ConnectionRecord>>();
|
||||
private final Map<String, Set<ConnectionRecord>> records =
|
||||
new HashMap<String, Set<ConnectionRecord>>();
|
||||
|
||||
/**
|
||||
* Stores the given connection record in the list of active connections
|
||||
@@ -60,14 +61,14 @@ public class ActiveConnectionMultimap {
|
||||
synchronized (records) {
|
||||
|
||||
// Get set of active connection records, creating if necessary
|
||||
LinkedList<ConnectionRecord> connections = records.get(identifier);
|
||||
Set<ConnectionRecord> connections = records.get(identifier);
|
||||
if (connections == null) {
|
||||
connections = new LinkedList<ConnectionRecord>();
|
||||
connections = Collections.newSetFromMap(new LinkedHashMap<ConnectionRecord, Boolean>());
|
||||
records.put(identifier, connections);
|
||||
}
|
||||
|
||||
// Add active connection
|
||||
connections.addFirst(record);
|
||||
connections.add(record);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -86,7 +87,7 @@ public class ActiveConnectionMultimap {
|
||||
synchronized (records) {
|
||||
|
||||
// Get set of active connection records
|
||||
LinkedList<ConnectionRecord> connections = records.get(identifier);
|
||||
Set<ConnectionRecord> connections = records.get(identifier);
|
||||
assert(connections != null);
|
||||
|
||||
// Remove old record
|
||||
@@ -100,25 +101,26 @@ public class ActiveConnectionMultimap {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current list of active connection records associated with
|
||||
* the object having the given identifier. The list will be sorted in
|
||||
* ascending order of connection age. If there are no such connections, an
|
||||
* empty list is returned.
|
||||
* Returns a collection of active connection records associated with the
|
||||
* object having the given identifier. The collection will be sorted in
|
||||
* insertion order. If there are no such connections, an empty collection is
|
||||
* returned.
|
||||
*
|
||||
* @param identifier
|
||||
* The identifier of the object to check.
|
||||
*
|
||||
* @return
|
||||
* An immutable list of records associated with the object having the
|
||||
* given identifier, or an empty list if there are no such records.
|
||||
* An immutable collection of records associated with the object having
|
||||
* the given identifier, or an empty collection if there are no such
|
||||
* records.
|
||||
*/
|
||||
public List<ConnectionRecord> get(String identifier) {
|
||||
public Collection<ConnectionRecord> get(String identifier) {
|
||||
synchronized (records) {
|
||||
|
||||
// Get set of active connection records
|
||||
LinkedList<ConnectionRecord> connections = records.get(identifier);
|
||||
Collection<ConnectionRecord> connections = records.get(identifier);
|
||||
if (connections != null)
|
||||
return Collections.unmodifiableList(connections);
|
||||
return Collections.unmodifiableCollection(connections);
|
||||
|
||||
return Collections.EMPTY_LIST;
|
||||
|
||||
|
@@ -22,7 +22,7 @@
|
||||
|
||||
package org.glyptodon.guacamole.auth.jdbc.socket;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||
import org.glyptodon.guacamole.auth.jdbc.connection.ModeledConnection;
|
||||
import org.glyptodon.guacamole.auth.jdbc.connectiongroup.ModeledConnectionGroup;
|
||||
@@ -72,18 +72,19 @@ public interface GuacamoleSocketService {
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns a list containing connection records representing all currently-
|
||||
* active connections using the given connection. These records will have
|
||||
* usernames and start dates, but no end date.
|
||||
* Returns a connection containing connection records representing all
|
||||
* currently-active connections using the given connection. These records
|
||||
* will have usernames and start dates, but no end date, and will be
|
||||
* sorted in ascending order by start date.
|
||||
*
|
||||
* @param connection
|
||||
* The connection to check.
|
||||
*
|
||||
* @return
|
||||
* A list containing connection records representing all currently-
|
||||
* active connections.
|
||||
* A connection containing connection records representing all
|
||||
* currently-active connections.
|
||||
*/
|
||||
public List<ConnectionRecord> getActiveConnections(Connection connection);
|
||||
public Collection<ConnectionRecord> getActiveConnections(Connection connection);
|
||||
|
||||
/**
|
||||
* Creates a socket for the given user which connects to the given
|
||||
@@ -116,17 +117,18 @@ public interface GuacamoleSocketService {
|
||||
throws GuacamoleException;
|
||||
|
||||
/**
|
||||
* Returns a list containing connection records representing all currently-
|
||||
* active connections using the given connection group. These records will
|
||||
* have usernames and start dates, but no end date.
|
||||
* Returns a collection containing connection records representing all
|
||||
* currently-active connections using the given connection group. These
|
||||
* records will have usernames and start dates, but no end date, and will
|
||||
* be sorted in ascending order by start date.
|
||||
*
|
||||
* @param connectionGroup
|
||||
* The connection group to check.
|
||||
*
|
||||
* @return
|
||||
* A list containing connection records representing all currently-
|
||||
* active connections.
|
||||
* A collection containing connection records representing all
|
||||
* currently-active connections.
|
||||
*/
|
||||
public List<ConnectionRecord> getActiveConnections(ConnectionGroup connectionGroup);
|
||||
public Collection<ConnectionRecord> getActiveConnections(ConnectionGroup connectionGroup);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user