1 package org.apache.maven.archiva.scheduled.executors;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
23 import org.apache.maven.archiva.configuration.Configuration;
24 import org.apache.maven.archiva.database.ArchivaDatabaseException;
25 import org.apache.maven.archiva.database.updater.DatabaseUpdater;
26 import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
27 import org.apache.maven.archiva.scheduled.tasks.RepositoryTask;
29 import org.codehaus.plexus.logging.AbstractLogEnabled;
30 import org.codehaus.plexus.taskqueue.Task;
31 import org.codehaus.plexus.taskqueue.execution.TaskExecutionException;
32 import org.codehaus.plexus.taskqueue.execution.TaskExecutor;
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.Iterator;
37 import java.util.List;
41 * @author <a href="mailto:jmcconnell@apache.org">Jesse McConnell</a>
44 * @plexus.component role="org.codehaus.plexus.taskqueue.execution.TaskExecutor"
45 * role-hint="archiva-task-executor"
47 public class ArchivaScheduledTaskExecutor extends AbstractLogEnabled implements TaskExecutor
50 * Configuration store.
54 private ArchivaConfiguration archivaConfiguration;
57 * @plexus.requirement role-hint="jdo"
59 private DatabaseUpdater databaseUpdater;
61 public void executeTask( Task task ) throws TaskExecutionException
64 if ( task instanceof DatabaseTask )
66 executeDatabaseTask( (DatabaseTask) task );
68 else if ( task instanceof RepositoryTask )
70 executeRepositoryTask( (RepositoryTask) task );
74 throw new TaskExecutionException( "Unknown Task: " + task.toString() );
79 private void executeDatabaseTask( DatabaseTask task ) throws TaskExecutionException
81 getLogger().info( "Executing task from queue with job name: " + task.getName() );
82 long time = System.currentTimeMillis();
87 databaseUpdater.updateAllUnprocessed();
89 catch ( ArchivaDatabaseException e )
91 throw new TaskExecutionException( "Error running unprocessed updater", e );
96 databaseUpdater.updateAllProcessed();
98 catch ( ArchivaDatabaseException e )
100 throw new TaskExecutionException( "Error running processed updater", e );
103 time = System.currentTimeMillis() - time;
105 getLogger().info( "Finished database task in " + time + "ms." );
109 private void executeRepositoryTask ( RepositoryTask task ) throws TaskExecutionException
111 getLogger().info( "Executing task from queue with job name: " + task.getName() );
113 long time = System.currentTimeMillis();
115 // insert repository scanning codelets here
117 time = System.currentTimeMillis() - time;
119 getLogger().info( "Finished repository task for " + time + "ms." );