--- /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
+package org.commscope.tr069adapter.common.scheduler.impl;\r
+\r
+import java.io.BufferedInputStream;\r
+import java.io.FileInputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.util.Properties;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.quartz.Scheduler;\r
+import org.quartz.SchedulerException;\r
+import org.quartz.impl.StdSchedulerFactory;\r
+import org.springframework.stereotype.Component;\r
+\r
+@Component\r
+public class QuartzSchedulerProducer {\r
+\r
+ private static final Log logger = LogFactory.getLog(QuartzSchedulerProducer.class);\r
+\r
+ public Scheduler getStdScheduler() {\r
+ StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();\r
+ try {\r
+ schedulerFactory.initialize("config/quartz.properties");\r
+ Properties props = new Properties();\r
+ props.setProperty("org.quartz.scheduler.instanceName",\r
+ props.getProperty("org.quartz.scheduler.instanceName") + "_standby");\r
+ return schedulerFactory.getScheduler();\r
+ } catch (SchedulerException e) {\r
+ logger.error("SchedulerException : {}" + e.getMessage());\r
+ }\r
+\r
+ return null;\r
+ }\r
+\r
+ public Properties initialize(String filename) throws SchedulerException {\r
+\r
+ InputStream is = null;\r
+ Properties props = new Properties();\r
+\r
+ is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);\r
+\r
+ try {\r
+ if (is != null) {\r
+ is = new BufferedInputStream(is);\r
+ } else {\r
+ is = new BufferedInputStream(new FileInputStream(filename));\r
+ }\r
+ props.load(is);\r
+ } catch (IOException ioe) {\r
+ throw new SchedulerException("Properties file: '" + filename + "' could not be read.", ioe);\r
+ } finally {\r
+ if (is != null)\r
+ try {\r
+ is.close();\r
+ } catch (IOException ignore) {\r
+ logger.error("while initialize : {}" + ignore.getMessage());\r
+ }\r
+ }\r
+\r
+ return props;\r
+ }\r
+}\r