View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed 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. 
3   	$Id
4   */
5   
6   package com.hack23.cia.service.impl.admin;
7   
8   import org.apache.commons.logging.Log;
9   import org.apache.commons.logging.LogFactory;
10  import org.quartz.Job;
11  import org.quartz.JobExecutionContext;
12  import org.quartz.JobExecutionException;
13  import org.quartz.SchedulerException;
14  import org.springframework.context.ApplicationContext;
15  
16  /***
17   * The Class LoaderJob.
18   */
19  public class LoaderJob implements Job {
20  
21      /*** The Constant ADMIN_SERVICE. */
22      private static final String ADMIN_SERVICE = "adminService"; //$NON-NLS-1$
23  
24      /*** The Constant APPLICATION_CONTEXT. */
25      private static final String APPLICATION_CONTEXT = "applicationContext"; //$NON-NLS-1$
26  
27      /*** The Constant LOGGER. */
28      private static final Log LOGGER = LogFactory.getLog(LoaderJob.class);
29  
30      /*
31       * (non-Javadoc)
32       * 
33       * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
34       */
35      @Override
36      public final void execute(final JobExecutionContext context)
37              throws JobExecutionException {
38          AdminService adminService = null;
39          try {
40              final ApplicationContext ctx = (ApplicationContext) context
41                      .getScheduler().getContext().get(APPLICATION_CONTEXT);
42              adminService = (AdminService) ctx.getBean(ADMIN_SERVICE);
43          } catch (final SchedulerException e) {
44              LOGGER.error("Quartz Scheduling", e); //$NON-NLS-1$
45          }
46  
47          if (adminService != null) {
48              LOGGER.info("Quartz job started"); //$NON-NLS-1$
49              adminService.startUpdateJob();
50              LOGGER.info("Quartz job completed"); //$NON-NLS-1$
51          }
52      }
53  }