Parcourir la source

Prevent excessive getLogger() calls from markAsDirty() (#11664)

Fixes #10339
tags/8.9.0.beta2
Leif Åstrand il y a 4 ans
Parent
révision
ea91075254
1 fichiers modifiés avec 24 ajouts et 15 suppressions
  1. 24
    15
      server/src/main/java/com/vaadin/ui/ConnectorTracker.java

+ 24
- 15
server/src/main/java/com/vaadin/ui/ConnectorTracker.java Voir le fichier

* *
*/ */
public class ConnectorTracker implements Serializable { public class ConnectorTracker implements Serializable {
/**
* Cache whether FINE messages are loggable. This is done to avoid
* excessively calling getLogger() which might be slightly slow in some
* specific environments. Please note that we're not caching the logger
* instance itself because of
* https://github.com/vaadin/framework/issues/2092.
*/
private static final boolean fineLogging = getLogger()
.isLoggable(Level.FINE);


private final Map<String, ClientConnector> connectorIdToConnector = new HashMap<>(); private final Map<String, ClientConnector> connectorIdToConnector = new HashMap<>();
private final Set<ClientConnector> dirtyConnectors = new HashSet<>(); private final Set<ClientConnector> dirtyConnectors = new HashSet<>();
if (previouslyRegistered == null) { if (previouslyRegistered == null) {
connectorIdToConnector.put(connectorId, connector); connectorIdToConnector.put(connectorId, connector);
uninitializedConnectors.add(connector); uninitializedConnectors.add(connector);
if (getLogger().isLoggable(Level.FINE)) {
if (fineLogging) {
getLogger().log(Level.FINE, "Registered {0} ({1})", getLogger().log(Level.FINE, "Registered {0} ({1})",
new Object[] { connector.getClass().getSimpleName(), new Object[] { connector.getClass().getSimpleName(),
connectorId }); connectorId });
} else if (unregisteredConnectors.add(connector)) { } else if (unregisteredConnectors.add(connector)) {
// Client side knows about the connector, track it for a while if it // Client side knows about the connector, track it for a while if it
// becomes reattached // becomes reattached
if (getLogger().isLoggable(Level.FINE)) {
if (fineLogging) {
getLogger().log(Level.FINE, "Unregistered {0} ({1})", getLogger().log(Level.FINE, "Unregistered {0} ({1})",
new Object[] { connector.getClass().getSimpleName(), new Object[] { connector.getClass().getSimpleName(),
connectorId }); connectorId });
assert isRemovalSentToClient(connector) : "Connector " assert isRemovalSentToClient(connector) : "Connector "
+ connector + " (id = " + connector.getConnectorId() + connector + " (id = " + connector.getConnectorId()
+ ") is no longer visible to the client, but no corresponding hierarchy change was sent."; + ") is no longer visible to the client, but no corresponding hierarchy change was sent.";
if (getLogger().isLoggable(Level.FINE)) {
if (fineLogging) {
getLogger().log(Level.FINE, getLogger().log(Level.FINE,
"cleanConnectorMap removed state for {0} as it is not visible", "cleanConnectorMap removed state for {0} as it is not visible",
getConnectorAndParentInfo(connector)); getConnectorAndParentInfo(connector));
"A connector should not be marked as dirty while a response is being written."); "A connector should not be marked as dirty while a response is being written.");
} }


if (getLogger().isLoggable(Level.FINE)) {
if (!isDirty(connector)) {
getLogger().log(Level.FINE, "{0} is now dirty",
getConnectorAndParentInfo(connector));
}
if (fineLogging && !isDirty(connector)) {
getLogger().log(Level.FINE, "{0} is now dirty",
getConnectorAndParentInfo(connector));
} }


if (!isDirty(connector)) { if (!isDirty(connector)) {
* The connector that should be marked clean. * The connector that should be marked clean.
*/ */
public void markClean(ClientConnector connector) { public void markClean(ClientConnector connector) {
if (getLogger().isLoggable(Level.FINE)) {
if (dirtyConnectors.contains(connector)) {
getLogger().log(Level.FINE, "{0} is no longer dirty",
getConnectorAndParentInfo(connector));
}
if (fineLogging && dirtyConnectors.contains(connector)) {
getLogger().log(Level.FINE, "{0} is no longer dirty",
getConnectorAndParentInfo(connector));
} }


dirtyConnectors.remove(connector); dirtyConnectors.remove(connector);
*/ */
public void markAllConnectorsDirty() { public void markAllConnectorsDirty() {
markConnectorsDirtyRecursively(uI); markConnectorsDirtyRecursively(uI);
getLogger().fine("All connectors are now dirty");
if (fineLogging) {
getLogger().fine("All connectors are now dirty");
}
} }


/** /**
*/ */
public void markAllConnectorsClean() { public void markAllConnectorsClean() {
dirtyConnectors.clear(); dirtyConnectors.clear();
getLogger().fine("All connectors are now clean");
if (fineLogging) {
getLogger().fine("All connectors are now clean");
}
} }


/** /**

Chargement…
Annuler
Enregistrer