struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r811700 - in /struts/struts2/trunk/plugins/spring/src: main/java/org/apache/struts2/spring/ main/resources/ test/java/org/apache/struts2/spring/
Date Sat, 05 Sep 2009 19:06:34 GMT
Author: musachy
Date: Sat Sep  5 19:06:34 2009
New Revision: 811700

URL: http://svn.apache.org/viewvc?rev=811700&view=rev
Log:
Add constant to reload config when a change is detected

Modified:
    struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
    struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
    struts/struts2/trunk/plugins/spring/src/main/resources/struts-plugin.xml
    struts/struts2/trunk/plugins/spring/src/test/java/org/apache/struts2/spring/StrutsSpringObjectFactoryTest.java

Modified: struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java?rev=811700&r1=811699&r2=811700&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
(original)
+++ struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
Sat Sep  5 19:06:34 2009
@@ -29,6 +29,7 @@
 import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
 import org.apache.commons.jci.monitor.FilesystemAlterationObserver;
 import org.apache.commons.lang.xwork.StringUtils;
+import org.apache.struts2.dispatcher.Dispatcher;
 import org.springframework.web.context.support.XmlWebApplicationContext;
 import org.springframework.beans.factory.support.DefaultListableBeanFactory;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -76,13 +77,17 @@
     protected FilesystemAlterationMonitor fam;
 
     protected ClassReloadingBeanFactory beanFactory;
+    //reload the runtime configuration when a change is detected
+    private boolean reloadConfig;
+
+    public void setupReloading(String[] watchList, String acceptClasses, ServletContext servletContext,
boolean reloadConfig) {
+        this.reloadConfig = reloadConfig;
 
-    public void setupReloading(String[] watchList, String acceptClasses, ServletContext servletContext)
{
         classLoader = new ReloadingClassLoader(ClassReloadingXMLWebApplicationContext.class.getClassLoader());
 
         //make a list of accepted classes
         if (StringUtils.isNotBlank(acceptClasses)) {
-            String[] splitted =  acceptClasses.split(",");
+            String[] splitted = acceptClasses.split(",");
             Set<Pattern> patterns = new HashSet<Pattern>(splitted.length);
             for (String pattern : splitted)
                 patterns.add(Pattern.compile(pattern));
@@ -176,32 +181,34 @@
     }
 
     public void onDirectoryChange(File file) {
+        reload(file);
     }
 
     public void onDirectoryCreate(File file) {
-        if (classLoader != null) {
-            if (LOG.isDebugEnabled())
-                LOG.debug("Change detected in file [#0], reloading class loader", file.getAbsolutePath());
-            classLoader.reload();
-        }
+        reload(file);
     }
 
     public void onDirectoryDelete(File file) {
     }
 
     public void onFileChange(File file) {
+        reload(file);
+    }
+
+    public void onFileCreate(File file) {
+        reload(file);
+    }
+
+    private void reload(File file) {
         if (classLoader != null) {
             if (LOG.isDebugEnabled())
                 LOG.debug("Change detected in file [#0], reloading class loader", file.getAbsolutePath());
             classLoader.reload();
+            if (reloadConfig && Dispatcher.getInstance() != null)
+                Dispatcher.getInstance().getConfigurationManager().reload();
         }
     }
 
-    public void onFileCreate(File file) {
-        if (classLoader != null)
-            classLoader.reload();
-    }
-
     public void onFileDelete(File file) {
     }
 

Modified: struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java?rev=811700&r1=811699&r2=811700&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
(original)
+++ struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
Sat Sep  5 19:06:34 2009
@@ -69,7 +69,8 @@
             @Inject ServletContext servletContext,
             @Inject(StrutsConstants.STRUTS_DEVMODE) String devMode,
             @Inject(value = "struts.class.reloading.watchList", required = false) String
watchList,
-            @Inject(value = "struts.class.reloading.acceptClasses", required = false) String
acceptClasses) {
+            @Inject(value = "struts.class.reloading.acceptClasses", required = false) String
acceptClasses,
+            @Inject(value = "struts.class.reloading.reloadConfig", required = false) String
reloadConfig) {
           
         super();
         boolean useClassCache = "true".equals(useClassCacheStr);
@@ -96,7 +97,7 @@
             useClassCache = false;
 
             ClassReloadingXMLWebApplicationContext reloadingContext = (ClassReloadingXMLWebApplicationContext)
appContext;
-            reloadingContext.setupReloading(watchList.split(","), acceptClasses, servletContext);
+            reloadingContext.setupReloading(watchList.split(","), acceptClasses, servletContext,
"true".equals(reloadConfig));
             LOG.info("Class reloading is enabled. Make sure this is not used on a production
environment!", watchList);
 
             setClassLoader(reloadingContext.getReloadingClassLoader());

Modified: struts/struts2/trunk/plugins/spring/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/spring/src/main/resources/struts-plugin.xml?rev=811700&r1=811699&r2=811700&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/spring/src/main/resources/struts-plugin.xml (original)
+++ struts/struts2/trunk/plugins/spring/src/main/resources/struts-plugin.xml Sat Sep  5 19:06:34
2009
@@ -33,6 +33,7 @@
 
     <constant name="struts.class.reloading.watchList" value="" />
     <constant name="struts.class.reloading.acceptClasses" value="" />
+    <constant name="struts.class.reloading.reloadConfig" value="false" />
 
     <package name="spring-default">
         <interceptors>

Modified: struts/struts2/trunk/plugins/spring/src/test/java/org/apache/struts2/spring/StrutsSpringObjectFactoryTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/spring/src/test/java/org/apache/struts2/spring/StrutsSpringObjectFactoryTest.java?rev=811700&r1=811699&r2=811700&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/spring/src/test/java/org/apache/struts2/spring/StrutsSpringObjectFactoryTest.java
(original)
+++ struts/struts2/trunk/plugins/spring/src/test/java/org/apache/struts2/spring/StrutsSpringObjectFactoryTest.java
Sat Sep  5 19:06:34 2009
@@ -39,7 +39,7 @@
 
     public void testNoSpringContext() throws Exception {
         // to cover situations where there will be logged an error
-        StrutsSpringObjectFactory fac = new StrutsSpringObjectFactory(null, null, null, new
MockServletContext(), null, "false", null);
+        StrutsSpringObjectFactory fac = new StrutsSpringObjectFactory(null, null, null, new
MockServletContext(), null, "false", null, null);
 
         assertEquals(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, fac.getAutowireStrategy());
     }
@@ -53,7 +53,7 @@
         ac.setServletContext(msc);
         ac.setConfigLocations(new String[] {"org/apache/struts2/spring/StrutsSpringObjectFactoryTest-applicationContext.xml"});
         ac.refresh();
-        StrutsSpringObjectFactory fac = new StrutsSpringObjectFactory("constructor", null,
null, msc, null, "true", null);
+        StrutsSpringObjectFactory fac = new StrutsSpringObjectFactory("constructor", null,
null, msc, null, "true", null, null);
 
         assertEquals(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, fac.getAutowireStrategy());
     }



Mime
View raw message