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.database.ArchivaDatabaseException;
23 import org.apache.maven.archiva.database.updater.DatabaseUpdater;
24 import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
25 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
26 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
27 import org.codehaus.plexus.taskqueue.Task;
28 import org.codehaus.plexus.taskqueue.execution.TaskExecutionException;
29 import org.codehaus.plexus.taskqueue.execution.TaskExecutor;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * ArchivaDatabaseTaskExecutor
39 * role="org.codehaus.plexus.taskqueue.execution.TaskExecutor"
40 * role-hint="database-update"
42 public class ArchivaDatabaseUpdateTaskExecutor
43 implements TaskExecutor, Initializable
45 private Logger log = LoggerFactory.getLogger( ArchivaDatabaseUpdateTaskExecutor.class );
48 * @plexus.requirement role-hint="jdo"
50 private DatabaseUpdater databaseUpdater;
52 public void initialize()
53 throws InitializationException
55 log.info( "Initialized " + this.getClass().getName() );
58 public void executeTask( Task task )
59 throws TaskExecutionException
61 DatabaseTask dbtask = (DatabaseTask) task;
63 log.info( "Executing task from queue with job name: " + dbtask.getName() );
64 long time = System.currentTimeMillis();
68 log.info( "Task: Updating unprocessed artifacts" );
69 databaseUpdater.updateAllUnprocessed();
71 catch ( ArchivaDatabaseException e )
73 throw new TaskExecutionException( "Error running unprocessed updater", e );
78 log.info( "Task: Updating processed artifacts" );
79 databaseUpdater.updateAllProcessed();
81 catch ( ArchivaDatabaseException e )
83 throw new TaskExecutionException( "Error running processed updater", e );
86 time = System.currentTimeMillis() - time;
88 log.info( "Finished database task in " + time + "ms." );