use of com.tremolosecurity.provisioning.scheduler.StopScheduler in project OpenUnison by TremoloSecurity.
the class SendMessageThread method initScheduler.
@Override
public void initScheduler() throws ProvisioningException {
if (this.cfgMgr.getCfg().getProvisioning() == null || this.cfgMgr.getCfg().getProvisioning().getScheduler() == null) {
logger.warn("Scheduler not defined");
return;
}
SchedulingType sct = this.cfgMgr.getCfg().getProvisioning().getScheduler();
Properties scheduleProps = new Properties();
scheduleProps.setProperty("org.quartz.scheduler.instanceName", sct.getInstanceLabel());
/*String instanceLabel = null;
try {
Enumeration<NetworkInterface> enumer = NetworkInterface.getNetworkInterfaces();
while (enumer.hasMoreElements()) {
NetworkInterface ni = enumer.nextElement();
Enumeration<InetAddress> enumeri = ni.getInetAddresses();
while (enumeri.hasMoreElements()) {
InetAddress addr = enumeri.nextElement();
if (addr.getHostAddress().startsWith(sct.getInstanceIPMask())) {
instanceLabel = addr.getHostAddress();
}
}
}
} catch (SocketException e) {
throw new ProvisioningException("Could not read network addresses",e);
}
if (instanceLabel == null) {
logger.warn("No IP starts with '" + sct.getInstanceIPMask() + "'");
instanceLabel = "AUTO";
}*/
scheduleProps.setProperty("org.quartz.scheduler.instanceId", UUID.randomUUID().toString());
scheduleProps.setProperty("org.quartz.threadPool.threadCount", Integer.toString(sct.getThreadCount()));
if (sct.isUseDB()) {
scheduleProps.setProperty("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
scheduleProps.setProperty("org.quartz.jobStore.driverDelegateClass", sct.getScheduleDB().getDelegateClassName());
scheduleProps.setProperty("org.quartz.jobStore.dataSource", "scheduleDB");
scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.driver", sct.getScheduleDB().getDriver());
scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.URL", sct.getScheduleDB().getUrl());
scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.user", sct.getScheduleDB().getUser());
scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.password", sct.getScheduleDB().getPassword());
scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.maxConnections", Integer.toString(sct.getScheduleDB().getMaxConnections()));
scheduleProps.setProperty("org.quartz.dataSource.scheduleDB.validationQuery", sct.getScheduleDB().getValidationQuery());
scheduleProps.setProperty("org.quartz.jobStore.useProperties", "true");
scheduleProps.setProperty("org.quartz.jobStore.isClustered", "true");
} else {
scheduleProps.setProperty("org.quartz.jobStore.class", "org.quartz.simpl.RAMJobStore");
}
try {
/*String classpath = System.getProperty("java.class.path");
String[] classpathEntries = classpath.split(File.pathSeparator);
for (String cp : classpathEntries) {
System.out.println(cp);
}*/
PrintStream out = new PrintStream(new FileOutputStream(System.getProperty(OpenUnisonConstants.UNISON_CONFIG_QUARTZDIR) + "/quartz.properties"));
scheduleProps.store(out, "Unison internal scheduler properties");
out.flush();
out.close();
} catch (IOException e) {
throw new ProvisioningException("Could not write to quartz.properties", e);
}
try {
this.scheduler = StdSchedulerFactory.getDefaultScheduler();
this.scheduler.start();
this.cfgMgr.addThread(new StopScheduler(this.scheduler));
HashSet<String> jobKeys = new HashSet<String>();
for (JobType jobType : sct.getJob()) {
addNewJob(jobKeys, jobType);
}
DynamicPortalUrlsType dynamicJobs = cfgMgr.getCfg().getProvisioning().getScheduler().getDynamicJobs();
if (dynamicJobs != null && dynamicJobs.isEnabled()) {
String className = dynamicJobs.getClassName();
HashMap<String, Attribute> cfgAttrs = new HashMap<String, Attribute>();
for (ParamType pt : dynamicJobs.getParams()) {
Attribute attr = cfgAttrs.get(pt.getName());
if (attr == null) {
attr = new Attribute(pt.getName());
cfgAttrs.put(pt.getName(), attr);
}
attr.getValues().add(pt.getValue());
}
DynamicJobs dynJobs = null;
try {
dynJobs = (DynamicJobs) Class.forName(className).newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new ProvisioningException("Could not create dynmaic job", e);
}
dynJobs.loadDynamicJobs(cfgMgr, this, cfgAttrs, jobKeys);
}
for (String groupName : scheduler.getJobGroupNames()) {
this.deleteRemovedJobs(jobKeys, groupName);
}
} catch (SchedulerException e) {
throw new ProvisioningException("Could not initialize scheduler", e);
} catch (ClassNotFoundException e) {
throw new ProvisioningException("Could not initialize scheduler", e);
}
}
Aggregations