]> source.dussan.org Git - archiva.git/commitdiff
more practical use of configuration change listeners
authorBrett Porter <brett@apache.org>
Mon, 12 Feb 2007 05:34:22 +0000 (05:34 +0000)
committerBrett Porter <brett@apache.org>
Mon, 12 Feb 2007 05:34:22 +0000 (05:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@506292 13f79535-47bb-0310-9956-ffa450edef68

archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
archiva-configuration/src/main/mdo/configuration.mdo
archiva-core/src/main/java/org/apache/maven/archiva/repositories/DefaultActiveManagedRepositories.java
archiva-core/src/main/java/org/apache/maven/archiva/scheduler/DefaultRepositoryTaskScheduler.java
archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java

index 7c467c8846333896378fb92ae902c9d27fca11fb..36cbd5a8e8bc4c63b5308e928b3128d43b5d936a 100644 (file)
@@ -69,12 +69,8 @@ public class DefaultArchivaConfiguration
 
     public void addChangeListener( RegistryListener listener )
     {
-        registry.addChangeListener( listener );
-    }
-
-    public synchronized void notifyOfConfigurationChange( Registry registry )
-    {
-        configuration = null;
+        Registry section = registry.getSection( KEY );
+        section.addChangeListener( listener );
     }
 
     public void initialize()
@@ -82,4 +78,14 @@ public class DefaultArchivaConfiguration
     {
         registry.addChangeListener( this );
     }
+
+    public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+    {
+        // nothing to do here
+    }
+
+    public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+    {
+        configuration = null;
+    }
 }
index 274f83f529fcc2c3c6ec128dd733902e30bf677b..6187c49c43a72b4b3d426a245fd9c09db52b0d19 100644 (file)
         for ( java.util.Iterator i = getRepositories().iterator(); i.hasNext(); )\r
         {\r
             RepositoryConfiguration repository = (RepositoryConfiguration) i.next();\r
-            if ( repository.getUrlName().equals( urlName ) )\r
+            if ( urlName.equals( repository.getUrlName() ) )\r
             {\r
                 return repository;\r
             }\r
         for ( java.util.Iterator i = getRepositories().iterator(); i.hasNext(); )\r
         {\r
             RepositoryConfiguration repository = (RepositoryConfiguration) i.next();\r
-            if ( repository.getId().equals( id ) )\r
+            if ( id.equals( repository.getId() ) )\r
             {\r
                 return repository;\r
             }\r
         for ( java.util.Iterator i = getSyncedRepositories().iterator(); i.hasNext(); )\r
         {\r
             SyncedRepositoryConfiguration repository = (SyncedRepositoryConfiguration) i.next();\r
-            if ( repository.getId().equals( id ) )\r
+            if ( id.equals( repository.getId() ) )\r
             {\r
                 return repository;\r
             }\r
         for ( java.util.Iterator i = getProxiedRepositories().iterator(); i.hasNext(); )\r
         {\r
             ProxiedRepositoryConfiguration repository = (ProxiedRepositoryConfiguration) i.next();\r
-            if ( repository.getId().equals( id ) )\r
+            if ( id.equals( repository.getId() ) )\r
             {\r
                 return repository;\r
             }\r
index 14d4478a594b72136faac46e64cec9b652bf5fe3..54b50bf522e70c4fa78f6dbfea0e10ac817eb610 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectBuilder;
 import org.apache.maven.project.ProjectBuildingException;
 import org.codehaus.plexus.cache.Cache;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
 import org.codehaus.plexus.registry.Registry;
@@ -53,6 +54,7 @@ import java.util.List;
  * @plexus.component role="org.apache.maven.archiva.repositories.ActiveManagedRepositories"
  */
 public class DefaultActiveManagedRepositories
+    extends AbstractLogEnabled
     implements ActiveManagedRepositories, Initializable, RegistryListener
 {
     /**
@@ -267,8 +269,22 @@ public class DefaultActiveManagedRepositories
         return path;
     }
 
-    public void notifyOfConfigurationChange( Registry registry )
+    public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
     {
-        configureSelf( archivaConfiguration.getConfiguration() );
+        // nothing to do
+    }
+
+    public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+    {
+        if ( propertyName.startsWith( "repositories" ) || propertyName.startsWith( "localRepository" ) )
+        {
+            getLogger().debug( "Triggering managed repository configuration change with " + propertyName + " set to " +
+                propertyValue );
+            configureSelf( archivaConfiguration.getConfiguration() );
+        }
+        else
+        {
+            getLogger().debug( "Not triggering managed repository configuration change with " + propertyName );
+        }
     }
 }
index 62a1cb355b38d72befc11e522a57728c439381cb..04ab088d4daae4c947d02e4e642563adb4022d5f 100644 (file)
@@ -92,7 +92,7 @@ public class DefaultRepositoryTaskScheduler
 
         try
         {
-            scheduleJobs( configuration );
+            scheduleJobs( configuration.getIndexPath(), configuration.getIndexerCronExpression() );
         }
         catch ( ParseException e )
         {
@@ -104,16 +104,15 @@ public class DefaultRepositoryTaskScheduler
         }
     }
 
-    private void scheduleJobs( Configuration configuration )
+    private void scheduleJobs( String indexPath, String indexerCronExpression )
         throws ParseException, SchedulerException
     {
-        if ( configuration.getIndexPath() != null )
+        if ( indexPath != null )
         {
             JobDetail jobDetail = createJobDetail( INDEXER_JOB );
 
-            getLogger().info( "Scheduling indexer: " + configuration.getIndexerCronExpression() );
-            CronTrigger trigger =
-                new CronTrigger( INDEXER_JOB + "Trigger", DISCOVERER_GROUP, configuration.getIndexerCronExpression() );
+            getLogger().info( "Scheduling indexer: " + indexerCronExpression );
+            CronTrigger trigger = new CronTrigger( INDEXER_JOB + "Trigger", DISCOVERER_GROUP, indexerCronExpression );
             scheduler.scheduleJob( jobDetail, trigger );
 
             try
@@ -156,30 +155,47 @@ public class DefaultRepositoryTaskScheduler
         }
     }
 
-    public void notifyOfConfigurationChange( Registry registry )
+
+    public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
     {
-        try
-        {
-            stop();
-        }
-        catch ( StoppingException e )
-        {
-            getLogger().warn( "Error stopping task scheduler: " + e.getMessage(), e );
-        }
+        // nothing to do
+    }
 
-        try
-        {
-            scheduleJobs( archivaConfiguration.getConfiguration() );
-        }
-        catch ( ParseException e )
+    public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+    {
+        if ( "indexPath".equals( propertyName ) || "indexerCronExpression".equals( propertyName ) )
         {
-            getLogger().error(
-                "Error restarting task scheduler after configuration change, due to configuration error: " +
-                    e.getMessage(), e );
+            getLogger().debug( "Restarting task scheduler with new configuration after property change: " +
+                propertyName + " to " + propertyValue );
+            try
+            {
+                stop();
+            }
+            catch ( StoppingException e )
+            {
+                getLogger().warn( "Error stopping task scheduler: " + e.getMessage(), e );
+            }
+
+            try
+            {
+                Configuration configuration = archivaConfiguration.getConfiguration();
+                scheduleJobs( configuration.getIndexPath(), configuration.getIndexerCronExpression() );
+            }
+            catch ( ParseException e )
+            {
+                getLogger().error(
+                    "Error restarting task scheduler after configuration change, due to configuration error: " +
+                        e.getMessage(), e );
+            }
+            catch ( SchedulerException e )
+            {
+                getLogger().error( "Error restarting task scheduler after configuration change: " + e.getMessage(), e );
+            }
         }
-        catch ( SchedulerException e )
+        else
         {
-            getLogger().error( "Error restarting task scheduler after configuration change: " + e.getMessage(), e );
+            getLogger().debug(
+                "Not restarting task scheduler with new configuration after property change: " + propertyName );
         }
     }
 
index 85ab6a2ce8d1d8d9a903474a747cfd0f7a0ab00a..d658dce275b7639fb3c73578dedfa9ea8014fbcb 100644 (file)
@@ -90,7 +90,6 @@ public class RepositoryServlet
         archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName() );
         configuration = archivaConfiguration.getConfiguration();
         archivaConfiguration.addChangeListener( this );
-
     }
 
     public void initServers( ServletConfig servletConfig )
@@ -205,19 +204,34 @@ public class RepositoryServlet
         return true;
     }
 
-    public void notifyOfConfigurationChange( Registry registry )
+    public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
     {
-        configuration = archivaConfiguration.getConfiguration();
+        // nothing to do
+    }
 
-        getDavManager().removeAllServers();
+    public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+    {
+        configuration = archivaConfiguration.getConfiguration();
 
-        try
+        if ( propertyName.startsWith( "repositories" ) )
         {
-            initServers( getServletConfig() );
+            log( "Triggering managed repository configuration change with " + propertyName + " set to " +
+                propertyValue );
+            getDavManager().removeAllServers();
+
+            try
+            {
+                initServers( getServletConfig() );
+            }
+            catch ( DavServerException e )
+            {
+                log( "Error restarting WebDAV server after configuration change - service disabled: " + e.getMessage(),
+                     e );
+            }
         }
-        catch ( DavServerException e )
+        else
         {
-            log( "Error restarting WebDAV server after configuration change - service disabled: " + e.getMessage(), e );
+            log( "Not triggering managed repository configuration change with " + propertyName );
         }
     }
 }