2 * ============LICENSE_START========================================================================
\r
3 * ONAP : tr-069-adapter
\r
4 * =================================================================================================
\r
5 * Copyright (C) 2020 CommScope Inc Intellectual Property.
\r
6 * =================================================================================================
\r
7 * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
\r
8 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
\r
9 * may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
\r
14 * either express or implied. See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
16 * ===============LICENSE_END=======================================================================
\r
20 package org.commscope.tr069adapter.common.scheduler.impl;
\r
22 import static org.commscope.tr069adapter.common.scheduler.impl.QuartzSchedulerConstants.JOB_NAME;
\r
23 import static org.commscope.tr069adapter.common.scheduler.impl.QuartzSchedulerConstants.SUB_SYSTEM;
\r
25 import org.apache.commons.logging.Log;
\r
26 import org.apache.commons.logging.LogFactory;
\r
27 import org.commscope.tr069adapter.common.scheduler.ExecutionContext;
\r
28 import org.commscope.tr069adapter.common.scheduler.Job;
\r
29 import org.quartz.DisallowConcurrentExecution;
\r
30 import org.quartz.JobDataMap;
\r
31 import org.quartz.JobExecutionContext;
\r
32 import org.quartz.JobExecutionException;
\r
33 import org.quartz.PersistJobDataAfterExecution;
\r
34 import org.springframework.context.ApplicationContext;
\r
36 @PersistJobDataAfterExecution
\r
37 @DisallowConcurrentExecution
\r
38 public class QuartzJob implements org.quartz.Job {
\r
40 private static ApplicationContext appctx;
\r
42 private static final Log logger = LogFactory.getLog(QuartzJob.class);
\r
44 protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
\r
45 JobDataMap dataMap = null;
\r
47 dataMap = context.getJobDetail().getJobDataMap();
\r
48 ExecutionContext jobContext = new ExecutionContext(context.getJobDetail().getKey().getName(),
\r
49 dataMap.getString(SUB_SYSTEM), dataMap.getString(JOB_NAME));
\r
50 for (String key : dataMap.getKeys()) {
\r
51 jobContext.addJobData(key, dataMap.get(key));
\r
53 // add scheduling information
\r
54 jobContext.addJobData("SCHEDULED_TIME", context.getScheduledFireTime());
\r
55 String beanName = jobContext.getJobName();
\r
56 Job job = (Job) appctx.getBean(beanName);
\r
57 job.execute(jobContext);
\r
59 } catch (Exception exception) {
\r
60 if (dataMap != null) {
\r
61 logger.error("executeInternal : Executing job " + dataMap.getString(JOB_NAME)
\r
62 + ", SubSystem " + dataMap.getString(SUB_SYSTEM));
\r
64 logger.error("executeInternal : Could not execute job. Exception while executing the job",
\r
66 throw new JobExecutionException(exception);
\r
70 public static String getJndiName(String subSystem, String jobName) {
\r
71 String jndiName = "csadapter/";
\r
72 jndiName += subSystem + "/" + jobName + "#" + Job.class.getName();
\r
76 public void execute(JobExecutionContext context) {
\r
78 executeInternal(context);
\r
79 } catch (JobExecutionException e) {
\r
80 logger.error("Exception : " + e.getMessage());
\r
84 public static void setApplicationContext(ApplicationContext ctx) {
\r
88 public static ApplicationContext getApplicationContext() {
\r