volosied commented on code in PR #573:
URL: https://github.com/apache/myfaces/pull/573#discussion_r1199266833


##########
impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java:
##########
@@ -503,82 +480,57 @@ public void update()
                     application.publishEvent(facesContext, 
PostConstructApplicationEvent.class,
                             Application.class, application);
                 }
+                catch (Exception e)
+                {
+                    log.severe("Error during configuration clean-up" + 
e.getMessage());
+
+                    // We still want to update the timestamp to avoid running 
purge on every subsequent
+                    // request after this one.
+                    //
+                    lastUpdate = System.currentTimeMillis();
+                }
             }
         }
     }
 
-    private boolean purgeConfiguration() throws NoSuchMethodException, 
IllegalAccessException, InvocationTargetException
+    private void purgeConfiguration()
     {
-
-        Method appFactoryPurgeMethod;
-        Method renderKitPurgeMethod;
-        Method lifecyclePurgeMethod;
-        Method facesContextPurgeMethod;
-
         // Check that we have access to all of the necessary purge methods 
before purging anything
-        //
+
         ApplicationFactory applicationFactory
                 = (ApplicationFactory) 
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
-        //appFactoryPurgeMethod = 
applicationFactory.getClass().getMethod("purgeApplication", NO_PARAMETER_TYPES);
-        appFactoryPurgeMethod = getPurgeMethod(applicationFactory, 
"purgeApplication", NO_PARAMETER_TYPES);
+        purge(applicationFactory);
 
         RenderKitFactory renderKitFactory
                 = (RenderKitFactory) 
FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
-        //renderKitPurgeMethod = 
renderKitFactory.getClass().getMethod("purgeRenderKit", NO_PARAMETER_TYPES);
-        renderKitPurgeMethod = getPurgeMethod(renderKitFactory, 
"purgeRenderKit", NO_PARAMETER_TYPES);
+        purge(renderKitFactory);
+
+        RuntimeConfig.getCurrentInstance(_externalContext).purge();
 
         LifecycleFactory lifecycleFactory
                 = (LifecycleFactory) 
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
-        //lifecyclePurgeMethod = 
lifecycleFactory.getClass().getMethod("purgeLifecycle", NO_PARAMETER_TYPES);
-        lifecyclePurgeMethod = getPurgeMethod(lifecycleFactory, 
"purgeLifecycle", NO_PARAMETER_TYPES);
+        purge(lifecycleFactory);
 
         FacesContext facesContext = getFacesContext();
-        facesContextPurgeMethod = getPurgeMethod(facesContext, 
"purgeFacesContext", NO_PARAMETER_TYPES);
-        
-        // If there was no exception so far, now we can purge
-        //
-        if (appFactoryPurgeMethod != null && renderKitPurgeMethod != null && 
lifecyclePurgeMethod != null && 
-            facesContextPurgeMethod != null)
-        {
-            appFactoryPurgeMethod.invoke(applicationFactory, NO_PARAMETERS);
-            renderKitPurgeMethod.invoke(renderKitFactory, NO_PARAMETERS);
-            RuntimeConfig.getCurrentInstance(_externalContext).purge();
-            lifecyclePurgeMethod.invoke(lifecycleFactory, NO_PARAMETERS);
-            facesContextPurgeMethod.invoke(facesContext, NO_PARAMETERS);
-
-            // factories and serial factory need not be purged...
+        purge(facesContext);
 
-            // Remove first request processed so we can initialize it again
-            
_externalContext.getApplicationMap().remove(LifecycleImpl.FIRST_REQUEST_PROCESSED_PARAM);
-            return true;
-        }
-        return false;
+        
_externalContext.getApplicationMap().remove(LifecycleImpl.FIRST_REQUEST_PROCESSED_PARAM);
     }
     
-    private Method getPurgeMethod(Object instance, String methodName, 
Class<?>[] parameters)
-    {
+    <T> void purge(T instance)
+    {        
         while (instance != null)
         {
-            Method purgeMethod = null;
-            try
+            if (instance instanceof Purgeable)
             {
-                purgeMethod = instance.getClass().getMethod(methodName, 
parameters);
-            }
-            catch (NoSuchMethodException e)
-            {
-                // No op, it is expected to found this case, so in that case
-                // look for the parent to do the purge
-            }
-            if (purgeMethod != null)
-            {
-                return purgeMethod;
+                ((Purgeable) instance).purge();
             }
+
             if (instance instanceof FacesWrapper)
             {
-                instance = ((FacesWrapper)instance).getWrapped();
+                instance = ((FacesWrapper<T>) instance).getWrapped();
             }
         }

Review Comment:
   Returned originally missed, but added here: 
https://github.com/apache/myfaces/commit/218dd53ce0d38263fb74f6d49b70b5b15671eeeb
 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@myfaces.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to