From b07a8c9aac8945961c1d699699dcfe732017a0c0 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 2 Oct 2007 18:57:19 +0000 Subject: [PATCH] Making archiva startup deterministic. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@581348 13f79535-47bb-0310-9956-ffa450edef68 --- .../scheduled/ArchivaTaskScheduler.java | 2 + .../DefaultArchivaTaskScheduler.java | 35 ++++++--- .../archiva/web/startup/ArchivaStartup.java | 74 +++++++++++++++++++ .../maven/archiva/web/startup/Banner.java | 2 - .../startup/ConfigurationSynchronization.java | 16 ++-- .../web/startup/ResolverFactoryInit.java | 12 ++- .../resources/META-INF/plexus/application.xml | 18 +---- 7 files changed, 111 insertions(+), 48 deletions(-) create mode 100644 archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaStartup.java diff --git a/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/ArchivaTaskScheduler.java b/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/ArchivaTaskScheduler.java index 9f516b2a0..70478a591 100644 --- a/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/ArchivaTaskScheduler.java +++ b/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/ArchivaTaskScheduler.java @@ -55,4 +55,6 @@ public interface ArchivaTaskScheduler public void scheduleDatabaseTasks() throws TaskExecutionException; + public void startup() + throws ArchivaException; } diff --git a/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java b/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java index 3deb5bc42..f20293515 100644 --- a/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java +++ b/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java @@ -35,6 +35,7 @@ import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.RegistryListener; import org.codehaus.plexus.scheduler.CronExpressionValidator; import org.codehaus.plexus.scheduler.Scheduler; +import org.codehaus.plexus.taskqueue.Task; import org.codehaus.plexus.taskqueue.TaskQueue; import org.codehaus.plexus.taskqueue.TaskQueueException; import org.codehaus.plexus.taskqueue.execution.TaskExecutionException; @@ -44,7 +45,6 @@ import org.quartz.JobDetail; import org.quartz.SchedulerException; import java.text.ParseException; -import java.util.Iterator; import java.util.List; /** @@ -92,17 +92,29 @@ public class DefaultArchivaTaskScheduler public static final String CRON_HOURLY = "0 0 * * * ?"; + public void startup() + throws ArchivaException + { + try + { + start(); + } + catch ( StartingException e ) + { + throw new ArchivaException( e.getMessage(), e ); + } + } + public void start() throws StartingException { try { - List repositories = archivaConfiguration.getConfiguration().getManagedRepositories(); + List repositories = archivaConfiguration.getConfiguration() + .getManagedRepositories(); - for ( Iterator i = repositories.iterator(); i.hasNext(); ) + for ( ManagedRepositoryConfiguration repoConfig : repositories ) { - ManagedRepositoryConfiguration repoConfig = (ManagedRepositoryConfiguration) i.next(); - if ( repoConfig.isScanned() ) { scheduleRepositoryJobs( repoConfig ); @@ -242,12 +254,11 @@ public class DefaultArchivaTaskScheduler // currently we have to reschedule all repo jobs because we don't know where the changed one came from if ( "refreshCronExpression".equals( propertyName ) ) { - List repositories = archivaConfiguration.getConfiguration().getManagedRepositories(); + List repositories = archivaConfiguration.getConfiguration() + .getManagedRepositories(); - for ( Iterator i = repositories.iterator(); i.hasNext(); ) + for ( ManagedRepositoryConfiguration repoConfig : repositories ) { - ManagedRepositoryConfiguration repoConfig = (ManagedRepositoryConfiguration) i.next(); - if ( repoConfig.getRefreshCronExpression() != null ) { try @@ -282,7 +293,7 @@ public class DefaultArchivaTaskScheduler public boolean isProcessingAnyRepositoryTask() throws ArchivaException { - List queue = null; + List queue = null; try { @@ -299,7 +310,7 @@ public class DefaultArchivaTaskScheduler public boolean isProcessingRepositoryTask( String repositoryId ) throws ArchivaException { - List queue = null; + List queue = null; try { @@ -316,7 +327,7 @@ public class DefaultArchivaTaskScheduler public boolean isProcessingDatabaseTask() throws ArchivaException { - List queue = null; + List queue = null; try { diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaStartup.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaStartup.java new file mode 100644 index 000000000..20246eda6 --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaStartup.java @@ -0,0 +1,74 @@ +package org.apache.maven.archiva.web.startup; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.archiva.common.ArchivaException; +import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; + +/** + * ArchivaStartup - the startup of all archiva features in a deterministic order. + * + * @author Joakim Erdfelt + * @version $Id$ + * + * @plexus.component + * role="org.apache.maven.archiva.web.startup.ArchivaStartup" + * role-hint="default" + */ +public class ArchivaStartup + extends AbstractLogEnabled + implements Initializable +{ + /** + * @plexus.requirement role-hint="default" + */ + private ConfigurationSynchronization configSync; + + /** + * @plexus.requirement role-hint="default" + */ + private ResolverFactoryInit resolverFactory; + + /** + * @plexus.requirement role-hint="default" + */ + private ArchivaTaskScheduler taskScheduler; + + public void initialize() + throws InitializationException + { + Banner.display( getLogger(), ArchivaVersion.determineVersion( this.getClass().getClassLoader() ) ); + + try + { + configSync.startup(); + resolverFactory.startup(); + taskScheduler.startup(); + } + catch ( ArchivaException e ) + { + throw new InitializationException( "Unable to properly startup archiva: " + e.getMessage(), e ); + } + } + +} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java index 788584e9c..aedde96ff 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java @@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.startup; import org.apache.commons.lang.StringUtils; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; import java.util.regex.Matcher; @@ -40,7 +39,6 @@ import java.util.regex.Pattern; */ public class Banner extends AbstractLogEnabled - implements Initializable { public static String encode( String raw ) { diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ConfigurationSynchronization.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ConfigurationSynchronization.java index 041837977..267219808 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ConfigurationSynchronization.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ConfigurationSynchronization.java @@ -19,6 +19,7 @@ package org.apache.maven.archiva.web.startup; * under the License. */ +import org.apache.maven.archiva.common.ArchivaException; import org.apache.maven.archiva.common.utils.PathUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; @@ -29,14 +30,11 @@ import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.model.ArchivaRepository; import org.apache.maven.archiva.repository.ArchivaConfigurationAdaptor; 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.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.RegistryListener; -import java.util.Iterator; import java.util.List; /** @@ -50,7 +48,7 @@ import java.util.List; */ public class ConfigurationSynchronization extends AbstractLogEnabled - implements RegistryListener, Initializable + implements RegistryListener { /** * @plexus.requirement role-hint="jdo" @@ -80,12 +78,10 @@ public class ConfigurationSynchronization /* do nothing */ } - private void synchConfiguration( List repos ) + private void synchConfiguration( List repos ) { - Iterator it = repos.iterator(); - while ( it.hasNext() ) + for ( ManagedRepositoryConfiguration repoConfig : repos ) { - ManagedRepositoryConfiguration repoConfig = (ManagedRepositoryConfiguration) it.next(); try { try @@ -139,8 +135,8 @@ public class ConfigurationSynchronization } } - public void initialize() - throws InitializationException + public void startup() + throws ArchivaException { synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() ); archivaConfiguration.addChangeListener( this ); diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ResolverFactoryInit.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ResolverFactoryInit.java index 13a9c166c..d3bb918cb 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ResolverFactoryInit.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ResolverFactoryInit.java @@ -19,12 +19,11 @@ package org.apache.maven.archiva.web.startup; * under the License. */ +import org.apache.maven.archiva.common.ArchivaException; import org.apache.maven.archiva.database.project.ProjectModelToDatabaseListener; import org.apache.maven.archiva.repository.project.ProjectModelResolver; import org.apache.maven.archiva.repository.project.ProjectModelResolverFactory; import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; /** * ResolverFactoryInit - Initialize the Resolver Factory, and hook it up to @@ -39,13 +38,12 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce */ public class ResolverFactoryInit extends AbstractLogEnabled - implements Initializable { /** * @plexus.requirement role-hint="database" */ private ProjectModelResolver databaseResolver; - + /** * @plexus.requirement * role="org.apache.maven.archiva.repository.project.resolvers.ProjectModelResolutionListener" @@ -59,9 +57,9 @@ public class ResolverFactoryInit * @plexus.requirement */ private ProjectModelResolverFactory resolverFactory; - - public void initialize() - throws InitializationException + + public void startup() + throws ArchivaException { if ( !resolverFactory.getCurrentResolverStack().hasResolver( databaseResolver ) ) { diff --git a/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml b/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml index a29620371..c1fe07d13 100644 --- a/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml +++ b/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml @@ -21,23 +21,7 @@ - org.apache.maven.archiva.web.startup.Banner - default - - - org.apache.maven.archiva.web.startup.ConfigurationSynchronization - default - - - org.apache.maven.archiva.web.startup.ResolverFactoryInit - default - - - org.apache.maven.archiva.web.startup.Banner - default - - - org.apache.maven.archiva.scheduled.ArchivaTaskScheduler + org.apache.maven.archiva.web.startup.ArchivaStartup default