This is an automated email from the ASF dual-hosted git repository. thiagohp pushed a commit to branch better-page-invalidation in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
The following commit(s) were added to refs/heads/better-page-invalidation by this push: new 5b1141dec TAP5-2742: work in progress for page invalidation on message file change 5b1141dec is described below commit 5b1141dec16d012d3206215e55937a424f2836a4 Author: Thiago H. de Paula Figueiredo <thi...@arsmachina.com.br> AuthorDate: Tue Dec 20 19:12:58 2022 -0300 TAP5-2742: work in progress for page invalidation on message file change --- .../internal/services/MessagesSourceImpl.java | 44 ++++++++++++++++----- ...TrackingInfo.java => MessagesTrackingInfo.java} | 46 ++++++++++++++-------- .../internal/services/TemplateTrackingInfo.java | 15 ++++--- .../integration/app1/services/AppModule.java | 2 +- 4 files changed, 76 insertions(+), 31 deletions(-) diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java index 9acd5dfc9..ba4233716 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java @@ -28,6 +28,9 @@ import org.slf4j.Logger; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; /** * A utility class that encapsulates all the logic for reading properties files and assembling {@link Messages} from @@ -44,7 +47,7 @@ import java.util.Map; */ public class MessagesSourceImpl extends InvalidationEventHubImpl implements MessagesSource { - private final URLChangeTracker<TemplateTrackingInfo> tracker; + private final URLChangeTracker<MessagesTrackingInfo> tracker; private final PropertiesFileParser propertiesFileParser; @@ -81,9 +84,29 @@ public class MessagesSourceImpl extends InvalidationEventHubImpl implements Mess public void checkForUpdates() { - if (tracker != null && tracker.containsChanges()) + if (tracker != null) { - invalidate(); + final Set<MessagesTrackingInfo> changedResources = tracker.getChangedResourcesInfo(); + for (MessagesTrackingInfo info : changedResources) + { + // An application-level file was changed, so we need to invalidate everything. + if (info == null) + { + invalidate(); + break; + } + else + { + + + + + } + } + fireInvalidationEvent(changedResources.stream() + .map(ClassNameHolder::getClassName) + .filter(Objects::nonNull) + .collect(Collectors.toList())); } } @@ -151,9 +174,9 @@ public class MessagesSourceImpl extends InvalidationEventHubImpl implements Mess for (Resource localization : F.flow(localizations).reverse()) { - Map<String, String> rawProperties = getRawProperties(localization); + Map<String, String> rawProperties = getRawProperties(localization, bundle); - // Woould be nice to write into the cookedProperties cache here, + // Would be nice to write into the cookedProperties cache here, // but we can't because we don't know the selector part of the MultiKey. previous = extend(previous, rawProperties); @@ -184,13 +207,13 @@ public class MessagesSourceImpl extends InvalidationEventHubImpl implements Mess return result; } - private Map<String, String> getRawProperties(Resource localization) + private Map<String, String> getRawProperties(Resource localization, MessagesBundle bundle) { Map<String, String> result = rawProperties.get(localization); if (result == null) { - result = readProperties(localization); + result = readProperties(localization, bundle); rawProperties.put(localization, result); } @@ -200,15 +223,18 @@ public class MessagesSourceImpl extends InvalidationEventHubImpl implements Mess /** * Creates and returns a new map that contains properties read from the properties file. + * @param bundle */ - private Map<String, String> readProperties(Resource resource) + private Map<String, String> readProperties(Resource resource, MessagesBundle bundle) { if (!resource.exists()) return emptyMap; if (tracker != null) { - tracker.add(resource.toURL()); + MessagesTrackingInfo info = bundle != null ? new MessagesTrackingInfo( + resource.getFile(), bundle.getId(), bundle.getBaseResource().getFile()) : null; + tracker.add(resource.toURL(), info); } try diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateTrackingInfo.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesTrackingInfo.java similarity index 50% copy from tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateTrackingInfo.java copy to tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesTrackingInfo.java index 0f50c3b96..9943b261f 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateTrackingInfo.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesTrackingInfo.java @@ -16,50 +16,64 @@ package org.apache.tapestry5.internal.services; import java.util.Objects; /** - * Class that holds information about a template for tracking. + * Class that holds information about a messages properties file for tracking. */ -final public class TemplateTrackingInfo implements ClassNameHolder +final public class MessagesTrackingInfo implements ClassNameHolder { - public TemplateTrackingInfo(String template, String className) + + private Object bundleId; + private String propertiesFile; + private String className; + + public MessagesTrackingInfo(String propertiesFile, Object bundleId, String className) { super(); - this.template = template; + this.propertiesFile = propertiesFile; this.className = className; + this.bundleId = bundleId; + } + + public Object getBundleId() + { + return bundleId; } - private String template; - private String className; - public String getTemplate() { - return template; + public String getPropertiesFile() + { + return propertiesFile; } public String getClassName() { return className; } - + @Override - public int hashCode() { - return Objects.hash(className, template); + public int hashCode() + { + return Objects.hash(bundleId, className, propertiesFile); } @Override public boolean equals(Object obj) { - if (this == obj) { + if (this == obj) + { return true; } - if (!(obj instanceof TemplateTrackingInfo)) { + if (!(obj instanceof MessagesTrackingInfo)) + { return false; } - TemplateTrackingInfo other = (TemplateTrackingInfo) obj; - return Objects.equals(className, other.className) && Objects.equals(template, other.template); + MessagesTrackingInfo other = (MessagesTrackingInfo) obj; + return Objects.equals(bundleId, other.bundleId) && Objects.equals(className, other.className) && Objects.equals(propertiesFile, other.propertiesFile); } @Override public String toString() { - return "TemplateTrackingInfo [template=" + template + ", className=" + className + "]"; + return "MessagesTrackingInfo [className=" + className + ", bundleId=" + bundleId + ", propertiesFile=" + propertiesFile + "]"; } + } \ No newline at end of file diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateTrackingInfo.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateTrackingInfo.java index 0f50c3b96..d750af02a 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateTrackingInfo.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/TemplateTrackingInfo.java @@ -20,16 +20,19 @@ import java.util.Objects; */ final public class TemplateTrackingInfo implements ClassNameHolder { + + private String template; + private String className; + public TemplateTrackingInfo(String template, String className) { super(); this.template = template; this.className = className; } - private String template; - private String className; - public String getTemplate() { + public String getTemplate() + { return template; } @@ -39,7 +42,8 @@ final public class TemplateTrackingInfo implements ClassNameHolder } @Override - public int hashCode() { + public int hashCode() + { return Objects.hash(className, template); } @@ -49,7 +53,8 @@ final public class TemplateTrackingInfo implements ClassNameHolder if (this == obj) { return true; } - if (!(obj instanceof TemplateTrackingInfo)) { + if (!(obj instanceof TemplateTrackingInfo)) + { return false; } TemplateTrackingInfo other = (TemplateTrackingInfo) obj; diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java index 5f57836bf..ecb207c5f 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java @@ -139,7 +139,7 @@ public class AppModule { long elapsed = System.nanoTime() - startTime; - log.info(String.format("Request time: %5.2f s -- %s", elapsed * 10E-10d, request.getPath())); +// log.info(String.format("Request time: %5.2f s -- %s", elapsed * 10E-10d, request.getPath())); } } };