mirror of https://github.com/apache/archiva.git
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:
parent
eaab7a56c6
commit
b07a8c9aac
|
@ -55,4 +55,6 @@ public interface ArchivaTaskScheduler
|
|||
public void scheduleDatabaseTasks()
|
||||
throws TaskExecutionException;
|
||||
|
||||
public void startup()
|
||||
throws ArchivaException;
|
||||
}
|
||||
|
|
|
@ -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<ManagedRepositoryConfiguration> 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<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 )
|
||||
{
|
||||
try
|
||||
|
@ -282,7 +293,7 @@ public class DefaultArchivaTaskScheduler
|
|||
public boolean isProcessingAnyRepositoryTask()
|
||||
throws ArchivaException
|
||||
{
|
||||
List queue = null;
|
||||
List<? extends Task> queue = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -299,7 +310,7 @@ public class DefaultArchivaTaskScheduler
|
|||
public boolean isProcessingRepositoryTask( String repositoryId )
|
||||
throws ArchivaException
|
||||
{
|
||||
List queue = null;
|
||||
List<? extends Task> queue = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -316,7 +327,7 @@ public class DefaultArchivaTaskScheduler
|
|||
public boolean isProcessingDatabaseTask()
|
||||
throws ArchivaException
|
||||
{
|
||||
List queue = null;
|
||||
List<? extends Task> queue = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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<ManagedRepositoryConfiguration> 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 );
|
||||
|
|
|
@ -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 ) )
|
||||
{
|
||||
|
|
|
@ -21,23 +21,7 @@
|
|||
<plexus>
|
||||
<load-on-start>
|
||||
<component>
|
||||
<role>org.apache.maven.archiva.web.startup.Banner</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>org.apache.maven.archiva.web.startup.ArchivaStartup</role>
|
||||
<role-hint>default</role-hint>
|
||||
</component>
|
||||
<component>
|
||||
|
|
Loading…
Reference in New Issue