aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/ConnectorTracker.java
diff options
context:
space:
mode:
authorFabian Lange <lange.fabian@gmail.com>2014-05-21 14:18:41 +0200
committerVaadin Code Review <review@vaadin.com>2014-05-22 12:48:33 +0000
commit40d35f2bc97ba6516ee5d6cbb7954607c357a698 (patch)
treed4f854eb989b4651165707f2ea93d9d0de7bac13 /server/src/com/vaadin/ui/ConnectorTracker.java
parent8491ea68d32a275bb70998db5f66759265d367b8 (diff)
downloadvaadin-framework-40d35f2bc97ba6516ee5d6cbb7954607c357a698.tar.gz
vaadin-framework-40d35f2bc97ba6516ee5d6cbb7954607c357a698.zip
Optimizes ConnectorTracker.cleanConnectorMap (#13803)
cleanConnectorMap is a hot method. This change improves multiple code paths: 1) The global resource handler is no longer get()ed from the session for each connector (was in two loops). 2) The ConnectorTracker is no longer get()ed from the UI for each connector (was in one loop). 3) values() iterator for ClientConnectors replaces keySet() iterator + get(key) call 4) use getUI() from ClientConnector instead manual method. 5) moved removeUnregisteredConnectors to ease inlining and readability. Change-Id: I25ff5bc32d27d30ecd8d354922ec6e4a02b05921
Diffstat (limited to 'server/src/com/vaadin/ui/ConnectorTracker.java')
-rw-r--r--server/src/com/vaadin/ui/ConnectorTracker.java77
1 files changed, 32 insertions, 45 deletions
diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java
index ce8c452c2c..f7eae0013a 100644
--- a/server/src/com/vaadin/ui/ConnectorTracker.java
+++ b/server/src/com/vaadin/ui/ConnectorTracker.java
@@ -209,15 +209,6 @@ public class ConnectorTracker implements Serializable {
}
}
- private void removeFromGlobalResourceHandler(ClientConnector connector) {
- GlobalResourceHandler globalResourceHandler = uI.getSession()
- .getGlobalResourceHandler(false);
- // Nothing to do if there is no handler
- if (globalResourceHandler != null) {
- globalResourceHandler.unregisterConnector(connector);
- }
- }
-
/**
* Checks whether the given connector has already been initialized in the
* browser. The given connector should be registered with this connector
@@ -289,17 +280,9 @@ public class ConnectorTracker implements Serializable {
* to the application. This should only be called by the framework.
*/
public void cleanConnectorMap() {
- // Remove connectors that have been unregistered
- for (ClientConnector connector : unregisteredConnectors) {
- ClientConnector removedConnector = connectorIdToConnector
- .remove(connector.getConnectorId());
- assert removedConnector == connector;
-
- removeFromGlobalResourceHandler(connector);
- uninitializedConnectors.remove(connector);
- diffStates.remove(connector);
+ if (!unregisteredConnectors.isEmpty()) {
+ removeUnregisteredConnectors();
}
- unregisteredConnectors.clear();
// Do this expensive check only with assertions enabled
assert isHierarchyComplete() : "The connector hierarchy is corrupted. "
@@ -309,12 +292,14 @@ public class ConnectorTracker implements Serializable {
// remove detached components from paintableIdMap so they
// can be GC'ed
- Iterator<String> iterator = connectorIdToConnector.keySet().iterator();
-
+ Iterator<ClientConnector> iterator = connectorIdToConnector.values()
+ .iterator();
+ GlobalResourceHandler globalResourceHandler = uI.getSession()
+ .getGlobalResourceHandler(false);
while (iterator.hasNext()) {
- String connectorId = iterator.next();
- ClientConnector connector = connectorIdToConnector.get(connectorId);
- if (getUIForConnector(connector) != uI) {
+ ClientConnector connector = iterator.next();
+ assert connector != null;
+ if (connector.getUI() != uI) {
// If connector is no longer part of this uI,
// remove it from the map. If it is re-attached to the
// application at some point it will be re-added through
@@ -328,7 +313,9 @@ public class ConnectorTracker implements Serializable {
"cleanConnectorMap unregistered connector {0}. This should have been done when the connector was detached.",
getConnectorAndParentInfo(connector));
- removeFromGlobalResourceHandler(connector);
+ if (globalResourceHandler != null) {
+ globalResourceHandler.unregisterConnector(connector);
+ }
uninitializedConnectors.remove(connector);
diffStates.remove(connector);
iterator.remove();
@@ -349,6 +336,24 @@ public class ConnectorTracker implements Serializable {
cleanStreamVariables();
}
+ private void removeUnregisteredConnectors() {
+ GlobalResourceHandler globalResourceHandler = uI.getSession()
+ .getGlobalResourceHandler(false);
+
+ for (ClientConnector connector : unregisteredConnectors) {
+ ClientConnector removedConnector = connectorIdToConnector
+ .remove(connector.getConnectorId());
+ assert removedConnector == connector;
+
+ if (globalResourceHandler != null) {
+ globalResourceHandler.unregisterConnector(connector);
+ }
+ uninitializedConnectors.remove(connector);
+ diffStates.remove(connector);
+ }
+ unregisteredConnectors.clear();
+ }
+
private boolean isHierarchyComplete() {
boolean noErrors = true;
@@ -393,25 +398,6 @@ public class ConnectorTracker implements Serializable {
}
/**
- * Finds the uI that the connector is attached to.
- *
- * @param connector
- * The connector to lookup
- * @return The uI the connector is attached to or null if it is not attached
- * to any uI.
- */
- private UI getUIForConnector(ClientConnector connector) {
- if (connector == null) {
- return null;
- }
- if (connector instanceof Component) {
- return ((Component) connector).getUI();
- }
-
- return getUIForConnector(connector.getParent());
- }
-
- /**
* Mark the connector as dirty. This should not be done while the response
* is being written.
*
@@ -727,11 +713,12 @@ public class ConnectorTracker implements Serializable {
*/
private void cleanStreamVariables() {
if (pidToNameToStreamVariable != null) {
+ ConnectorTracker connectorTracker = uI.getConnectorTracker();
Iterator<String> iterator = pidToNameToStreamVariable.keySet()
.iterator();
while (iterator.hasNext()) {
String connectorId = iterator.next();
- if (uI.getConnectorTracker().getConnector(connectorId) == null) {
+ if (connectorTracker.getConnector(connectorId) == null) {
// Owner is no longer attached to the session
Map<String, StreamVariable> removed = pidToNameToStreamVariable
.get(connectorId);