View Javadoc

1   package org.apache.maven.continuum.scheduler;
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.continuum.purge.ContinuumPurgeManager;
23  import org.apache.continuum.purge.ContinuumPurgeManagerException;
24  import org.apache.maven.continuum.Continuum;
25  import org.apache.maven.continuum.model.project.Schedule;
26  import org.codehaus.plexus.scheduler.AbstractJob;
27  import org.quartz.JobDetail;
28  import org.quartz.JobExecutionContext;
29  import org.slf4j.Logger;
30  
31  /**
32   * @author Maria Catherine Tan
33   * @version $Id: ContinuumPurgeJob.java 1372260 2012-08-13 04:29:09Z brett $
34   * @since 25 jul 07
35   */
36  public class ContinuumPurgeJob
37      extends AbstractJob
38  {
39      public static final String PURGE_GROUP = "PURGE_GROUP";
40  
41      public void execute( JobExecutionContext context )
42      {
43          if ( isInterrupted() )
44          {
45              return;
46          }
47  
48          // ----------------------------------------------------------------------
49          // Get the job detail
50          // ----------------------------------------------------------------------
51  
52          JobDetail jobDetail = context.getJobDetail();
53  
54          // ----------------------------------------------------------------------
55          // Get data map out of the job detail
56          // ----------------------------------------------------------------------
57  
58          Logger logger = (Logger) jobDetail.getJobDataMap().get( AbstractJob.LOGGER );
59  
60          String jobName = jobDetail.getName();
61  
62          logger.info( ">>>>>>>>>>>>>>>>>>>>> Executing purge job (" + jobName + ")..." );
63  
64          Continuum continuum = (Continuum) jobDetail.getJobDataMap().get( ContinuumSchedulerConstants.CONTINUUM );
65  
66          ContinuumPurgeManager purgeManager = continuum.getPurgeManager();
67  
68          Schedule schedule = (Schedule) jobDetail.getJobDataMap().get( ContinuumSchedulerConstants.SCHEDULE );
69  
70          try
71          {
72              purgeManager.purge( schedule );
73          }
74          catch ( ContinuumPurgeManagerException e )
75          {
76              logger.error( "Error purging for job" + jobName + ".", e );
77          }
78  
79          try
80          {
81              if ( schedule.getDelay() > 0 )
82              {
83                  Thread.sleep( schedule.getDelay() * 1000 );
84              }
85          }
86          catch ( InterruptedException e )
87          {
88          }
89      }
90  }