From 79130e96fcf166c5c3d6d874d1e77a25c7f7cb84 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 23 Feb 2015 13:04:25 -0800 Subject: [PATCH] GUAC-1100: Add getActiveConnections() function to Connectable. --- .../guacamole/net/auth/Connectable.java | 9 ++++ .../net/auth/simple/SimpleConnection.java | 5 +++ .../auth/simple/SimpleConnectionGroup.java | 5 +++ .../basic/rest/connection/APIConnection.java | 43 ++++++++----------- .../rest/connection/APIConnectionWrapper.java | 17 +++++++- .../connectiongroup/APIConnectionGroup.java | 28 ++++++++++++ .../APIConnectionGroupWrapper.java | 7 ++- .../app/groupList/types/GroupListItem.js | 13 +++--- .../webapp/app/home/templates/connection.html | 6 +-- .../app/manage/templates/connection.html | 6 +-- .../main/webapp/app/rest/types/Connection.js | 8 ++-- .../webapp/app/rest/types/ConnectionGroup.js | 9 ++++ 12 files changed, 112 insertions(+), 44 deletions(-) diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connectable.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connectable.java index 6ce62c916..61d2ebfd9 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connectable.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Connectable.java @@ -51,4 +51,13 @@ public interface Connectable { public GuacamoleSocket connect(GuacamoleClientInformation info) throws GuacamoleException; + /** + * Returns the number of active connections associated with this object. + * Implementations may simply return 0 if this value is not tracked. + * + * @return + * The number of active connections associated with this object. + */ + public int getActiveConnections(); + } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java index 5065ef5d7..fe5070097 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnection.java @@ -78,6 +78,11 @@ public class SimpleConnection extends AbstractConnection { } + @Override + public int getActiveConnections() { + return 0; + } + @Override public GuacamoleSocket connect(GuacamoleClientInformation info) throws GuacamoleException { diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionGroup.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionGroup.java index eb197d01a..71e73433e 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionGroup.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionGroup.java @@ -86,6 +86,11 @@ public class SimpleConnectionGroup extends AbstractConnectionGroup { } + @Override + public int getActiveConnections() { + return 0; + } + @Override public Set getConnectionIdentifiers() { return connectionIdentifiers; diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnection.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnection.java index 7eda11740..5b8da3f75 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnection.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnection.java @@ -22,13 +22,10 @@ package org.glyptodon.guacamole.net.basic.rest.connection; -import java.util.List; import java.util.Map; import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.net.auth.Connection; -import org.glyptodon.guacamole.net.auth.ConnectionRecord; -import org.glyptodon.guacamole.net.basic.rest.connectiongroup.APIConnectionGroup; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; /** @@ -65,9 +62,9 @@ public class APIConnection { private Map parameters; /** - * The count of currently active users for this connection. + * The count of currently active connections using this connection. */ - private int activeUsers; + private int activeConnections; /** * Create an empty APIConnection. @@ -85,23 +82,12 @@ public class APIConnection { public APIConnection(Connection connection) throws GuacamoleException { - // Set identifying information + // Set connection information this.name = connection.getName(); this.identifier = connection.getIdentifier(); - - // Set proper parent identifier, using root identifier if needed this.parentIdentifier = connection.getParentIdentifier(); - if (this.parentIdentifier == null) - this.parentIdentifier = APIConnectionGroup.ROOT_IDENTIFIER; + this.activeConnections = connection.getActiveConnections(); - // Set the number of currently active users - this.activeUsers = 0; - - for (ConnectionRecord history : connection.getHistory()) { - if (history.isActive()) - this.activeUsers++; - } - // Set protocol from configuration GuacamoleConfiguration configuration = connection.getConfiguration(); this.protocol = configuration.getProtocol(); @@ -190,19 +176,24 @@ public class APIConnection { } /** - * Returns the number of currently active users for this connection. - * @return The number of currently active users for this connection. + * Returns the number of currently active connections using this + * connection. + * + * @return + * The number of currently active usages of this connection. */ - public int getActiveUsers() { - return activeUsers; + public int getActiveConnections() { + return activeConnections; } /** - * Set the number of currently active users for this connection. - * @param activeUsers The number of currently active users for this connection. + * Set the number of currently active connections using this connection. + * + * @param activeConnections + * The number of currently active usages of this connection. */ - public void setActiveUsers(int activeUsers) { - this.activeUsers = activeUsers; + public void setActiveUsers(int activeConnections) { + this.activeConnections = activeConnections; } } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java index 94bb5c0ed..33fe5047f 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnectionWrapper.java @@ -40,8 +40,18 @@ import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; */ public class APIConnectionWrapper implements Connection { + /** + * The wrapped APIConnection. + */ private final APIConnection apiConnection; - + + /** + * Creates a new APIConnectionWrapper which wraps the given APIConnection + * as a Connection. + * + * @param apiConnection + * The APIConnection to wrap. + */ public APIConnectionWrapper(APIConnection apiConnection) { this.apiConnection = apiConnection; } @@ -76,6 +86,11 @@ public class APIConnectionWrapper implements Connection { apiConnection.setParentIdentifier(parentIdentifier); } + @Override + public int getActiveConnections() { + return apiConnection.getActiveConnections(); + } + @Override public GuacamoleConfiguration getConfiguration() { diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroup.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroup.java index 45ca049e7..b980983b5 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroup.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroup.java @@ -61,6 +61,11 @@ public class APIConnectionGroup { */ private Type type; + /** + * The count of currently active connections using this connection group. + */ + private int activeConnections; + /** * All child connection groups. If children are not being queried, this may * be omitted. @@ -91,6 +96,7 @@ public class APIConnectionGroup { this.name = connectionGroup.getName(); this.type = connectionGroup.getType(); + this.activeConnections = connectionGroup.getActiveConnections(); } @@ -206,4 +212,26 @@ public class APIConnectionGroup { this.childConnections = childConnections; } + /** + * Returns the number of currently active connections using this + * connection group. + * + * @return + * The number of currently active usages of this connection group. + */ + public int getActiveConnections() { + return activeConnections; + } + + /** + * Set the number of currently active connections using this connection + * group. + * + * @param activeConnections + * The number of currently active usages of this connection group. + */ + public void setActiveUsers(int activeConnections) { + this.activeConnections = activeConnections; + } + } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroupWrapper.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroupWrapper.java index a726ca169..9007e75dd 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroupWrapper.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/APIConnectionGroupWrapper.java @@ -25,9 +25,7 @@ package org.glyptodon.guacamole.net.basic.rest.connectiongroup; import java.util.Set; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.net.GuacamoleSocket; -import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.ConnectionGroup; -import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.protocol.GuacamoleClientInformation; /** @@ -92,6 +90,11 @@ public class APIConnectionGroupWrapper implements ConnectionGroup { return apiConnectionGroup.getType(); } + @Override + public int getActiveConnections() { + return apiConnectionGroup.getActiveConnections(); + } + @Override public Set getConnectionIdentifiers() { throw new UnsupportedOperationException("Operation not supported."); diff --git a/guacamole/src/main/webapp/app/groupList/types/GroupListItem.js b/guacamole/src/main/webapp/app/groupList/types/GroupListItem.js index 3f5260359..a13e0f98f 100644 --- a/guacamole/src/main/webapp/app/groupList/types/GroupListItem.js +++ b/guacamole/src/main/webapp/app/groupList/types/GroupListItem.js @@ -102,12 +102,12 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio this.isExpanded = template.isExpanded; /** - * The number of currently active users for this connection. This field - * has no meaning for a connection group, and may be null or undefined. + * The number of currently active users for this connection or + * connection group, if known. * * @type Number */ - this.activeUsers = template.activeUsers; + this.activeConnections = template.activeConnections; /** * The connection or connection group whose data is exposed within @@ -143,8 +143,8 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio isConnection : true, isConnectionGroup : false, - // Count of currently active users - activeUsers : connection.activeUsers, + // Count of currently active connections using this connection + activeConnections : connection.activeConnections, // Wrapped item wrappedItem : connection @@ -198,6 +198,9 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio // Already-converted children children : children, + // Count of currently active connection groups using this connection + activeConnections : connectionGroup.activeConnections, + // Wrapped item wrappedItem : connectionGroup diff --git a/guacamole/src/main/webapp/app/home/templates/connection.html b/guacamole/src/main/webapp/app/home/templates/connection.html index 6e8bfcc28..4e91fd62d 100644 --- a/guacamole/src/main/webapp/app/home/templates/connection.html +++ b/guacamole/src/main/webapp/app/home/templates/connection.html @@ -21,7 +21,7 @@ THE SOFTWARE. --> -
+
@@ -32,8 +32,8 @@ {{item.name}} - - {{'HOME.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.activeUsers}'}} + + {{'HOME.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.activeConnections}'}}
diff --git a/guacamole/src/main/webapp/app/manage/templates/connection.html b/guacamole/src/main/webapp/app/manage/templates/connection.html index a1daded4e..2b65ee7d6 100644 --- a/guacamole/src/main/webapp/app/manage/templates/connection.html +++ b/guacamole/src/main/webapp/app/manage/templates/connection.html @@ -21,7 +21,7 @@ THE SOFTWARE. --> -
+
@@ -32,8 +32,8 @@ {{item.name}} - - {{'MANAGE.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.activeUsers}'}} + + {{'MANAGE.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.activeConnections}'}}
diff --git a/guacamole/src/main/webapp/app/rest/types/Connection.js b/guacamole/src/main/webapp/app/rest/types/Connection.js index 1a0459d7a..3c3efb87a 100644 --- a/guacamole/src/main/webapp/app/rest/types/Connection.js +++ b/guacamole/src/main/webapp/app/rest/types/Connection.js @@ -81,13 +81,13 @@ angular.module('rest').factory('Connection', [function defineConnection() { this.parameters = template.parameters; /** - * The count of currently active users for this connection. This field - * will be returned from the REST API during a get operation, - * but may not be set when doing an update or create operation. + * The count of currently active connections using this connection. + * This field will be returned from the REST API during a get + * operation, but manually setting this field will have no effect. * * @type Number */ - this.activeUsers = template.activeUsers; + this.activeConnections = template.activeConnections; }; diff --git a/guacamole/src/main/webapp/app/rest/types/ConnectionGroup.js b/guacamole/src/main/webapp/app/rest/types/ConnectionGroup.js index 89e53c6eb..cdb3fe232 100644 --- a/guacamole/src/main/webapp/app/rest/types/ConnectionGroup.js +++ b/guacamole/src/main/webapp/app/rest/types/ConnectionGroup.js @@ -91,6 +91,15 @@ angular.module('rest').factory('ConnectionGroup', [function defineConnectionGrou */ this.childConnectionGroups = template.childConnectionGroups; + /** + * The count of currently active connections using this connection + * group. This field will be returned from the REST API during a get + * operation, but manually setting this field will have no effect. + * + * @type Number + */ + this.activeConnections = template.activeConnections; + }; /**