]> source.dussan.org Git - archiva.git/blob
e8a88e8c84614bbe76fe0bf79f3930f51e0bb7dc
[archiva.git] /
1 package org.apache.maven.archiva.scheduled.executors;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
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;
32
33 /**
34  * ArchivaDatabaseTaskExecutor 
35  *
36  * @version $Id$
37  * 
38  * @plexus.component
39  *   role="org.codehaus.plexus.taskqueue.execution.TaskExecutor"
40  *   role-hint="database-update"
41  */
42 public class ArchivaDatabaseUpdateTaskExecutor
43     implements TaskExecutor, Initializable
44 {
45     private Logger log = LoggerFactory.getLogger( ArchivaDatabaseUpdateTaskExecutor.class );
46     
47     /**
48      * @plexus.requirement role-hint="jdo"
49      */
50     private DatabaseUpdater databaseUpdater;
51
52     public void initialize()
53         throws InitializationException
54     {
55         log.info( "Initialized " + this.getClass().getName() );
56     }
57
58     public void executeTask( Task task )
59         throws TaskExecutionException
60     {
61         DatabaseTask dbtask = (DatabaseTask) task;
62
63         log.info( "Executing task from queue with job name: " + dbtask.getName() );
64         long time = System.currentTimeMillis();
65
66         try
67         {
68             log.info( "Task: Updating unprocessed artifacts" );
69             databaseUpdater.updateAllUnprocessed();
70         }
71         catch ( ArchivaDatabaseException e )
72         {
73             throw new TaskExecutionException( "Error running unprocessed updater", e );
74         }
75
76         try
77         {
78             log.info( "Task: Updating processed artifacts" );
79             databaseUpdater.updateAllProcessed();
80         }
81         catch ( ArchivaDatabaseException e )
82         {
83             throw new TaskExecutionException( "Error running processed updater", e );
84         }
85
86         time = System.currentTimeMillis() - time;
87
88         log.info( "Finished database task in " + time + "ms." );
89     }
90 }