Making archiva startup deterministic.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@581348 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-10-02 18:57:19 +00:00
parent eaab7a56c6
commit b07a8c9aac
7 changed files with 111 additions and 48 deletions

View File

@ -55,4 +55,6 @@ public interface ArchivaTaskScheduler
public void scheduleDatabaseTasks() public void scheduleDatabaseTasks()
throws TaskExecutionException; throws TaskExecutionException;
public void startup()
throws ArchivaException;
} }

View File

@ -35,6 +35,7 @@ import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener; import org.codehaus.plexus.registry.RegistryListener;
import org.codehaus.plexus.scheduler.CronExpressionValidator; import org.codehaus.plexus.scheduler.CronExpressionValidator;
import org.codehaus.plexus.scheduler.Scheduler; import org.codehaus.plexus.scheduler.Scheduler;
import org.codehaus.plexus.taskqueue.Task;
import org.codehaus.plexus.taskqueue.TaskQueue; import org.codehaus.plexus.taskqueue.TaskQueue;
import org.codehaus.plexus.taskqueue.TaskQueueException; import org.codehaus.plexus.taskqueue.TaskQueueException;
import org.codehaus.plexus.taskqueue.execution.TaskExecutionException; import org.codehaus.plexus.taskqueue.execution.TaskExecutionException;
@ -44,7 +45,6 @@ import org.quartz.JobDetail;
import org.quartz.SchedulerException; import org.quartz.SchedulerException;
import java.text.ParseException; import java.text.ParseException;
import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
@ -92,17 +92,29 @@ public class DefaultArchivaTaskScheduler
public static final String CRON_HOURLY = "0 0 * * * ?"; 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() public void start()
throws StartingException throws StartingException
{ {
try try
{ {
List repositories = archivaConfiguration.getConfiguration().getManagedRepositories(); List<ManagedRepositoryConfiguration> repositories = archivaConfiguration.getConfiguration()
.getManagedRepositories();
for ( Iterator i = repositories.iterator(); i.hasNext(); ) for ( ManagedRepositoryConfiguration repoConfig : repositories )
{ {
ManagedRepositoryConfiguration repoConfig = (ManagedRepositoryConfiguration) i.next();
if ( repoConfig.isScanned() ) if ( repoConfig.isScanned() )
{ {
scheduleRepositoryJobs( repoConfig ); 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 // currently we have to reschedule all repo jobs because we don't know where the changed one came from
if ( "refreshCronExpression".equals( propertyName ) ) if ( "refreshCronExpression".equals( propertyName ) )
{ {
List repositories = archivaConfiguration.getConfiguration().getManagedRepositories(); List<ManagedRepositoryConfiguration> repositories = archivaConfiguration.getConfiguration()
.getManagedRepositories();
for ( Iterator i = repositories.iterator(); i.hasNext(); ) for ( ManagedRepositoryConfiguration repoConfig : repositories )
{ {
ManagedRepositoryConfiguration repoConfig = (ManagedRepositoryConfiguration) i.next();
if ( repoConfig.getRefreshCronExpression() != null ) if ( repoConfig.getRefreshCronExpression() != null )
{ {
try try
@ -282,7 +293,7 @@ public class DefaultArchivaTaskScheduler
public boolean isProcessingAnyRepositoryTask() public boolean isProcessingAnyRepositoryTask()
throws ArchivaException throws ArchivaException
{ {
List queue = null; List<? extends Task> queue = null;
try try
{ {
@ -299,7 +310,7 @@ public class DefaultArchivaTaskScheduler
public boolean isProcessingRepositoryTask( String repositoryId ) public boolean isProcessingRepositoryTask( String repositoryId )
throws ArchivaException throws ArchivaException
{ {
List queue = null; List<? extends Task> queue = null;
try try
{ {
@ -316,7 +327,7 @@ public class DefaultArchivaTaskScheduler
public boolean isProcessingDatabaseTask() public boolean isProcessingDatabaseTask()
throws ArchivaException throws ArchivaException
{ {
List queue = null; List<? extends Task> queue = null;
try try
{ {

View File

@ -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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @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 );
}
}
}

View File

@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.startup;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger; 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 org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -40,7 +39,6 @@ import java.util.regex.Pattern;
*/ */
public class Banner public class Banner
extends AbstractLogEnabled extends AbstractLogEnabled
implements Initializable
{ {
public static String encode( String raw ) public static String encode( String raw )
{ {

View File

@ -19,6 +19,7 @@ package org.apache.maven.archiva.web.startup;
* under the License. * under the License.
*/ */
import org.apache.maven.archiva.common.ArchivaException;
import org.apache.maven.archiva.common.utils.PathUtil; import org.apache.maven.archiva.common.utils.PathUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationNames; 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.model.ArchivaRepository;
import org.apache.maven.archiva.repository.ArchivaConfigurationAdaptor; import org.apache.maven.archiva.repository.ArchivaConfigurationAdaptor;
import org.codehaus.plexus.logging.AbstractLogEnabled; 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.RoleManager;
import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.redback.role.RoleManagerException;
import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener; import org.codehaus.plexus.registry.RegistryListener;
import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
@ -50,7 +48,7 @@ import java.util.List;
*/ */
public class ConfigurationSynchronization public class ConfigurationSynchronization
extends AbstractLogEnabled extends AbstractLogEnabled
implements RegistryListener, Initializable implements RegistryListener
{ {
/** /**
* @plexus.requirement role-hint="jdo" * @plexus.requirement role-hint="jdo"
@ -80,12 +78,10 @@ public class ConfigurationSynchronization
/* do nothing */ /* do nothing */
} }
private void synchConfiguration( List repos ) private void synchConfiguration( List<ManagedRepositoryConfiguration> repos )
{ {
Iterator it = repos.iterator(); for ( ManagedRepositoryConfiguration repoConfig : repos )
while ( it.hasNext() )
{ {
ManagedRepositoryConfiguration repoConfig = (ManagedRepositoryConfiguration) it.next();
try try
{ {
try try
@ -139,8 +135,8 @@ public class ConfigurationSynchronization
} }
} }
public void initialize() public void startup()
throws InitializationException throws ArchivaException
{ {
synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() ); synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() );
archivaConfiguration.addChangeListener( this ); archivaConfiguration.addChangeListener( this );

View File

@ -19,12 +19,11 @@ package org.apache.maven.archiva.web.startup;
* under the License. * under the License.
*/ */
import org.apache.maven.archiva.common.ArchivaException;
import org.apache.maven.archiva.database.project.ProjectModelToDatabaseListener; import org.apache.maven.archiva.database.project.ProjectModelToDatabaseListener;
import org.apache.maven.archiva.repository.project.ProjectModelResolver; import org.apache.maven.archiva.repository.project.ProjectModelResolver;
import org.apache.maven.archiva.repository.project.ProjectModelResolverFactory; import org.apache.maven.archiva.repository.project.ProjectModelResolverFactory;
import org.codehaus.plexus.logging.AbstractLogEnabled; 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 * ResolverFactoryInit - Initialize the Resolver Factory, and hook it up to
@ -39,7 +38,6 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce
*/ */
public class ResolverFactoryInit public class ResolverFactoryInit
extends AbstractLogEnabled extends AbstractLogEnabled
implements Initializable
{ {
/** /**
* @plexus.requirement role-hint="database" * @plexus.requirement role-hint="database"
@ -60,8 +58,8 @@ public class ResolverFactoryInit
*/ */
private ProjectModelResolverFactory resolverFactory; private ProjectModelResolverFactory resolverFactory;
public void initialize() public void startup()
throws InitializationException throws ArchivaException
{ {
if ( !resolverFactory.getCurrentResolverStack().hasResolver( databaseResolver ) ) if ( !resolverFactory.getCurrentResolverStack().hasResolver( databaseResolver ) )
{ {

View File

@ -21,23 +21,7 @@
<plexus> <plexus>
<load-on-start> <load-on-start>
<component> <component>
<role>org.apache.maven.archiva.web.startup.Banner</role> <role>org.apache.maven.archiva.web.startup.ArchivaStartup</role>
<role-hint>default</role-hint>
</component>
<component>
<role>org.apache.maven.archiva.web.startup.ConfigurationSynchronization</role>
<role-hint>default</role-hint>
</component>
<component>
<role>org.apache.maven.archiva.web.startup.ResolverFactoryInit</role>
<role-hint>default</role-hint>
</component>
<component>
<role>org.apache.maven.archiva.web.startup.Banner</role>
<role-hint>default</role-hint>
</component>
<component>
<role>org.apache.maven.archiva.scheduled.ArchivaTaskScheduler</role>
<role-hint>default</role-hint> <role-hint>default</role-hint>
</component> </component>
<component> <component>