From 025470bc79fdd423b02f892f33fd6d05a5c5fba1 Mon Sep 17 00:00:00 2001 From: Andrew Pielage Date: Tue, 25 Jun 2024 12:27:37 +0100 Subject: [PATCH] Merge pull request #6777 from Pandrex247/FISH-8857 FISH-8672 FISH-8857 Keep Semantic Versioning Happy --- .../apache/catalina/core/ContainerBase.java | 100 +++++++++++++++--- .../apache/catalina/core/StandardEngine.java | 2 +- core/core-parent/pom.xml | 2 - .../api/invocation/ComponentInvocation.java | 36 +++++-- 4 files changed, 113 insertions(+), 27 deletions(-) diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/core/ContainerBase.java b/appserver/web/web-core/src/main/java/org/apache/catalina/core/ContainerBase.java index 2a783c96a57..d6277fc0587 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/core/ContainerBase.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/core/ContainerBase.java @@ -208,10 +208,19 @@ public Void run() { protected int debug = 0; + /** + * The deprecated processor delay for this component. + * + * DO NOT USE! Retained for semantic versioning. Replaced by {@link ContainerBase#backgroundProcessorDelayAtomic}. + * Use {@link ContainerBase#getBackgroundProcessorDelay()} and {@link ContainerBase#setBackgroundProcessorDelay(int)} + */ + @Deprecated(forRemoval = true, since = "6.17.0") + protected int backgroundProcessorDelay = -1; + /** * The processor delay for this component. */ - protected AtomicInteger backgroundProcessorDelay = new AtomicInteger(-1); + private AtomicInteger backgroundProcessorDelayAtomic = new AtomicInteger(-1); /** @@ -322,7 +331,6 @@ public Void run() { */ private AtomicBoolean threadDone = new AtomicBoolean(); - /** * The session background thread completion semaphore. */ @@ -385,7 +393,7 @@ public void setDebug(int debug) { */ @Override public int getBackgroundProcessorDelay() { - return backgroundProcessorDelay.get(); + return backgroundProcessorDelayAtomic.get(); } @@ -398,7 +406,8 @@ public int getBackgroundProcessorDelay() { */ @Override public void setBackgroundProcessorDelay(int delay) { - backgroundProcessorDelay.set(delay); + backgroundProcessorDelayAtomic.set(delay); + backgroundProcessorDelay = delay; } @@ -1737,13 +1746,13 @@ protected void threadStart() { if (thread != null) return; - if (backgroundProcessorDelay.get() <= 0) + if (backgroundProcessorDelayAtomic.get() <= 0) return; threadDone.set(false); String threadName = "ContainerBackgroundProcessor[" + toString() + "]"; - thread = new Thread(new ContainerBackgroundProcessor(getMappingObject(), threadDone, - backgroundProcessorDelay), threadName); + thread = new Thread(new ContainerBackgroundProcessorAtomic(getMappingObject(), threadDone, + backgroundProcessorDelayAtomic), threadName); thread.setDaemon(true); thread.start(); @@ -1758,7 +1767,7 @@ protected void threadSessionStart() { return; threadSessionDone.set(false); String threadName = "ContainerBackgroundSessionProcessor[" + toString() + "]"; - sessionThread = new Thread(new ContainerBackgroundSessionProcessor(getMappingObject(), manager, + sessionThread = new Thread(new ContainerBackgroundSessionProcessorAtomic(getMappingObject(), manager, threadSessionDone), threadName); sessionThread.setDaemon(true); sessionThread.start(); @@ -1808,17 +1817,18 @@ protected void threadSessionStop() { // -------------------------------------- ContainerExecuteDelay Inner Class - /** * Private thread class to invoke the backgroundProcess method * of this container and its children after a fixed delay. + * + * Replaces {@link ContainerBackgroundProcessor} */ - protected static class ContainerBackgroundProcessor implements Runnable { + protected static class ContainerBackgroundProcessorAtomic implements Runnable { private final WeakReference base; private final AtomicBoolean threadDone; private final AtomicInteger backgroundProcessorDelay; - public ContainerBackgroundProcessor(Object base, + public ContainerBackgroundProcessorAtomic(Object base, AtomicBoolean threadDone, AtomicInteger backgroundProcessorDelay) { this.base = new WeakReference<>(base); this.threadDone = threadDone; @@ -1870,13 +1880,15 @@ protected void processChildren(Container container, ClassLoader cl) { /** * Thread class to invoke the backgroundSessionUpdate method * of this container and its children after 500 milliseconds. + * + * Replaces {@link ContainerBackgroundSessionProcessor} */ - protected static class ContainerBackgroundSessionProcessor implements Runnable { + protected static class ContainerBackgroundSessionProcessorAtomic implements Runnable { private final WeakReference base; private final WeakReference manager; private final AtomicBoolean threadSessionDone; - public ContainerBackgroundSessionProcessor(Object base, Manager manager, AtomicBoolean threadSessionDone) { + public ContainerBackgroundSessionProcessorAtomic(Object base, Manager manager, AtomicBoolean threadSessionDone) { this.base = new WeakReference<>(base); this.manager = new WeakReference<>(manager); this.threadSessionDone = threadSessionDone; @@ -1926,6 +1938,68 @@ protected void processChildren(Container container, ClassLoader cl) { } } + + // -------------------------------------- DEPRECATED! + /** + * Deprecated private thread class to invoke the backgroundProcess method + * of this container and its children after a fixed delay. + * + * DO NOT USE! Retained for semantic versioning. Replaced by {@link ContainerBackgroundProcessorAtomic}. + */ + @Deprecated(forRemoval = true, since = "6.17.0") + protected class ContainerBackgroundProcessor implements Runnable { + + private final ContainerBackgroundProcessorAtomic containerBackgroundProcessorAtomic; + + public ContainerBackgroundProcessor() { + containerBackgroundProcessorAtomic = new ContainerBackgroundProcessorAtomic(getMappingObject(), + threadDone, backgroundProcessorDelayAtomic); + } + + public ContainerBackgroundProcessor(ContainerBackgroundProcessorAtomic containerBackgroundProcessorAtomic) { + this.containerBackgroundProcessorAtomic = containerBackgroundProcessorAtomic; + } + + @Override + public void run() { + containerBackgroundProcessorAtomic.run(); + } + + protected void processChildren(Container container, ClassLoader cl) { + containerBackgroundProcessorAtomic.processChildren(container, cl); + } + } + + /** + * Deprecated thread class to invoke the backgroundSessionUpdate method + * of this container and its children after 500 milliseconds. + * + * DO NOT USE! Retained for semantic versioning. Replaced by {@link ContainerBackgroundSessionProcessorAtomic}. + */ + @Deprecated(forRemoval = true, since = "6.17.0") + protected class ContainerBackgroundSessionProcessor implements Runnable { + + private final ContainerBackgroundSessionProcessorAtomic containerBackgroundSessionProcessorAtomic; + + public ContainerBackgroundSessionProcessor() { + containerBackgroundSessionProcessorAtomic = new ContainerBackgroundSessionProcessorAtomic( + getMappingObject(), manager, threadSessionDone); + } + + public ContainerBackgroundSessionProcessor(ContainerBackgroundSessionProcessorAtomic containerBackgroundSessionProcessorAtomic) { + this.containerBackgroundSessionProcessorAtomic = containerBackgroundSessionProcessorAtomic; + } + + @Override + public void run() { + containerBackgroundSessionProcessorAtomic.run(); + } + + protected void processChildren(Container container, ClassLoader cl) { + containerBackgroundSessionProcessorAtomic.processChildren(container, cl); + } + + } } diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardEngine.java b/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardEngine.java index a2e4b53ae9d..53e0c218ad5 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardEngine.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardEngine.java @@ -97,7 +97,7 @@ public StandardEngine() { } catch(Exception ex) { } // By default, the engine will hold the reloading thread - backgroundProcessorDelay.set(10); + setBackgroundProcessorDelay(10); } diff --git a/core/core-parent/pom.xml b/core/core-parent/pom.xml index b88ddb4f71c..2071bf75a4c 100644 --- a/core/core-parent/pom.xml +++ b/core/core-parent/pom.xml @@ -642,8 +642,6 @@ io.opentelemetry.extension io.opentelemetry.instrumentation fish.payara.shaded - org.glassfish.api.invocation - org.apache.catalina.core diff --git a/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/invocation/ComponentInvocation.java b/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/invocation/ComponentInvocation.java index 18130931752..86e1cbd8d79 100644 --- a/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/invocation/ComponentInvocation.java +++ b/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/invocation/ComponentInvocation.java @@ -79,11 +79,25 @@ public enum ComponentInvocationType { private String instanceName; /** - * ServletContext for servlet, Container for EJB + * The deprecated ServletContext for servlet, Container for EJB + * + * DO NOT USE! Retained for semantic versioning. Replaced by {@link ComponentInvocation#containerReference}. + * Use {@link ComponentInvocation#getContainer()} and {@link ComponentInvocation#setContainer(Object)} instead. + * + */ + @Deprecated(forRemoval = true, since = "6.17.0") + public Object container; + + /** + * DO NOT USE! Retained for semantic versioning. Replaced by {@link ComponentInvocation#jndiEnvironmentReference}. + * Use {@link ComponentInvocation#getJNDIEnvironment()} and {@link ComponentInvocation#setJNDIEnvironment(Object)} instead. */ - private WeakReference container; + @Deprecated(forRemoval = true, since = "6.17.0") + public Object jndiEnvironment; + + private WeakReference containerReference; - private WeakReference jndiEnvironment; + private WeakReference jndiEnvironmentReference; public String componentId; @@ -118,13 +132,13 @@ public enum ComponentInvocationType { protected String registrationName; public ComponentInvocation() { - container = new WeakReference<>(null); + containerReference = new WeakReference<>(null); } public ComponentInvocation(String componentId, ComponentInvocationType invocationType, Object container, String appName, String moduleName, String registrationName) { this.componentId = componentId; this.invocationType = invocationType; - this.container = new WeakReference<>(container); + this.containerReference = new WeakReference<>(container); this.appName = appName; this.moduleName = moduleName; this.registrationName = registrationName; @@ -134,7 +148,7 @@ public ComponentInvocation(String componentId, ComponentInvocationType invocatio this.componentId = componentId; this.invocationType = invocationType; this.instance = instance; - this.container = new WeakReference<>(container); + this.containerReference = new WeakReference<>(container); this.transaction = transaction; } @@ -211,22 +225,22 @@ public void setJndiEnvironment(Object jndiEnvironment) { } public void setJNDIEnvironment(Object val) { - jndiEnvironment = new WeakReference<>(val); + jndiEnvironmentReference = new WeakReference<>(val); } public Object getJNDIEnvironment() { - if (jndiEnvironment == null) { + if (jndiEnvironmentReference == null) { return null; } - return jndiEnvironment.get(); + return jndiEnvironmentReference.get(); } public Object getContainer() { - return container.get(); + return containerReference.get(); } public void setContainer(Object container) { - this.container = new WeakReference<>(container); + this.containerReference = new WeakReference<>(container); } public Object getContainerContext() {