You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2018/12/06 17:48:57 UTC
[myfaces] branch master updated: free mem
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/master by this push:
new 49352d8 free mem
49352d8 is described below
commit 49352d8d6aa8036f345807ec910342db04c8970a
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Thu Dec 6 18:48:56 2018 +0100
free mem
---
.../annotation/CdiAnnotationProviderExtension.java | 18 +++++++++++-----
.../myfaces/webapp/AbstractFacesInitializer.java | 24 ++++++++++++++++++++--
2 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/impl/src/main/java/org/apache/myfaces/config/annotation/CdiAnnotationProviderExtension.java b/impl/src/main/java/org/apache/myfaces/config/annotation/CdiAnnotationProviderExtension.java
index 3def86e..540d079 100644
--- a/impl/src/main/java/org/apache/myfaces/config/annotation/CdiAnnotationProviderExtension.java
+++ b/impl/src/main/java/org/apache/myfaces/config/annotation/CdiAnnotationProviderExtension.java
@@ -42,16 +42,16 @@ public class CdiAnnotationProviderExtension implements Extension
/**
* Defines if CDI should be used for annotation scanning to improve the startup performance.
*/
- @JSFWebConfigParam(since="2.2.9")
+ @JSFWebConfigParam(since="2.2.9", tags = "performance", defaultValue = "false")
public static final String USE_CDI_FOR_ANNOTATION_SCANNING
= "org.apache.myfaces.annotation.USE_CDI_FOR_ANNOTATION_SCANNING";
- private final Map<Class<? extends Annotation>, Set<Class<?>>> map;
- private final Class<? extends Annotation>[] annotationsToScan;
+ private Map<Class<? extends Annotation>, Set<Class<?>>> map;
+ private Class<? extends Annotation>[] annotationsToScan;
public CdiAnnotationProviderExtension()
{
- map = new HashMap<Class<? extends Annotation>, Set<Class<?>>>();
+ map = new HashMap<>();
annotationsToScan = new Class[] {
FacesComponent.class,
FacesBehavior.class,
@@ -75,7 +75,7 @@ public class CdiAnnotationProviderExtension implements Extension
Set<Class<?>> set = map.get(annotation);
if (set == null)
{
- set = new HashSet<Class<?>>();
+ set = new HashSet<>();
map.put(annotation, set);
}
@@ -88,4 +88,12 @@ public class CdiAnnotationProviderExtension implements Extension
{
return map;
}
+
+ public void clear()
+ {
+ map.clear();
+ map = null;
+
+ annotationsToScan = null;
+ }
}
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
index bedb2f8..7046f10 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
@@ -57,12 +57,16 @@ import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.enterprise.inject.spi.BeanManager;
import javax.faces.application.ViewVisitOption;
import javax.faces.push.PushContext;
import javax.servlet.ServletRegistration;
import javax.websocket.DeploymentException;
import javax.websocket.server.ServerContainer;
import javax.websocket.server.ServerEndpointConfig;
+import org.apache.myfaces.cdi.util.BeanProvider;
+import org.apache.myfaces.cdi.util.CDIUtils;
+import org.apache.myfaces.config.annotation.CdiAnnotationProviderExtension;
import org.apache.myfaces.push.EndpointImpl;
import org.apache.myfaces.push.WebsocketConfigurator;
import org.apache.myfaces.push.WebsocketFacesInit;
@@ -142,8 +146,7 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
ExternalContext externalContext = facesContext.getExternalContext();
// Setup ServiceProviderFinder
- ServiceProviderFinder spf = ServiceProviderFinderFactory.getServiceProviderFinder(
- externalContext);
+ ServiceProviderFinder spf = ServiceProviderFinderFactory.getServiceProviderFinder(externalContext);
Map<String, List<String>> spfConfig = spf.calculateKnownServiceProviderMapInfo(
externalContext, ServiceProviderFinder.KNOWN_SERVICES);
if (spfConfig != null)
@@ -274,6 +277,7 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
log.log(Level.WARNING, message.toString());
}
+ cleanupAfterStartup(facesContext);
}
catch (Exception ex)
{
@@ -282,6 +286,22 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
}
}
+ protected void cleanupAfterStartup(FacesContext facesContext)
+ {
+ ExternalContext externalContext = facesContext.getExternalContext();
+
+ if (ExternalSpecifications.isCDIAvailable(externalContext))
+ {
+ BeanManager beanManager = CDIUtils.getBeanManager(externalContext);
+ CdiAnnotationProviderExtension extension =
+ BeanProvider.getContextualReference(beanManager, CdiAnnotationProviderExtension.class, false);
+ if (extension != null)
+ {
+ extension.clear();
+ }
+ }
+ }
+
/**
* Eventually we can use our plugin infrastructure for this as well
* it would be a cleaner interception point than the base class