Skip to content

Commit

Permalink
free mem
Browse files Browse the repository at this point in the history
  • Loading branch information
tandraschko committed Dec 6, 2018
1 parent 2b20c2d commit 49352d8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -75,7 +75,7 @@ <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat)
Set<Class<?>> set = map.get(annotation);
if (set == null)
{
set = new HashSet<Class<?>>();
set = new HashSet<>();
map.put(annotation, set);
}

Expand All @@ -88,4 +88,12 @@ public Map<Class<? extends Annotation>, Set<Class<?>>> getMap()
{
return map;
}

public void clear()
{
map.clear();
map = null;

annotationsToScan = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@
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;
Expand Down Expand Up @@ -142,8 +146,7 @@ public void initFaces(ServletContext servletContext)
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)
Expand Down Expand Up @@ -274,6 +277,7 @@ public void initFaces(ServletContext servletContext)
log.log(Level.WARNING, message.toString());
}

cleanupAfterStartup(facesContext);
}
catch (Exception ex)
{
Expand All @@ -282,6 +286,22 @@ public void initFaces(ServletContext servletContext)
}
}

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
Expand Down

0 comments on commit 49352d8

Please sign in to comment.