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