--- /dev/null
+/*\r
+ * ============LICENSE_START========================================================================\r
+ * ONAP : tr-069-adapter\r
+ * =================================================================================================\r
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
+ * =================================================================================================\r
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
+ * may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
+ * either express or implied. See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ===============LICENSE_END=======================================================================\r
+ */\r
+\r
+\r
+package org.commscope.tr069adapter.common.scheduler.impl;\r
+\r
+import static org.commscope.tr069adapter.common.scheduler.impl.QuartzSchedulerConstants.JOB_NAME;\r
+import static org.commscope.tr069adapter.common.scheduler.impl.QuartzSchedulerConstants.SUB_SYSTEM;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.commscope.tr069adapter.common.scheduler.ExecutionContext;\r
+import org.commscope.tr069adapter.common.scheduler.Job;\r
+import org.quartz.DisallowConcurrentExecution;\r
+import org.quartz.JobDataMap;\r
+import org.quartz.JobExecutionContext;\r
+import org.quartz.JobExecutionException;\r
+import org.quartz.PersistJobDataAfterExecution;\r
+import org.springframework.context.ApplicationContext;\r
+\r
+@PersistJobDataAfterExecution\r
+@DisallowConcurrentExecution\r
+public class QuartzJob implements org.quartz.Job {\r
+\r
+ private static ApplicationContext appctx;\r
+\r
+ private static final Log logger = LogFactory.getLog(QuartzJob.class);\r
+\r
+ protected void executeInternal(JobExecutionContext context) throws JobExecutionException {\r
+ JobDataMap dataMap = null;\r
+ try {\r
+ dataMap = context.getJobDetail().getJobDataMap();\r
+ ExecutionContext jobContext = new ExecutionContext(context.getJobDetail().getKey().getName(),\r
+ dataMap.getString(SUB_SYSTEM), dataMap.getString(JOB_NAME));\r
+ for (String key : dataMap.getKeys()) {\r
+ jobContext.addJobData(key, dataMap.get(key));\r
+ }\r
+ // add scheduling information\r
+ jobContext.addJobData("SCHEDULED_TIME", context.getScheduledFireTime());\r
+ String beanName = jobContext.getJobName();\r
+ Job job = (Job) appctx.getBean(beanName);\r
+ job.execute(jobContext);\r
+\r
+ } catch (Exception exception) {\r
+ if (dataMap != null) {\r
+ logger.error("executeInternal : Executing job " + dataMap.getString(JOB_NAME)\r
+ + ", SubSystem " + dataMap.getString(SUB_SYSTEM));\r
+ }\r
+ logger.error("executeInternal : Could not execute job. Exception while executing the job",\r
+ exception);\r
+ throw new JobExecutionException(exception);\r
+ }\r
+ }\r
+\r
+ public static String getJndiName(String subSystem, String jobName) {\r
+ String jndiName = "csadapter/";\r
+ jndiName += subSystem + "/" + jobName + "#" + Job.class.getName();\r
+ return jndiName;\r
+ }\r
+\r
+ public void execute(JobExecutionContext context) {\r
+ try {\r
+ executeInternal(context);\r
+ } catch (JobExecutionException e) {\r
+ logger.error("Exception : " + e.getMessage());\r
+ }\r
+ }\r
+\r
+ public static void setApplicationContext(ApplicationContext ctx) {\r
+ appctx = ctx;\r
+ }\r
+\r
+ public static ApplicationContext getApplicationContext() {\r
+ return appctx;\r
+ }\r
+}\r