use of org.quartz.Scheduler in project spring-framework by spring-projects.
the class SchedulerAccessorBean method findScheduler.
protected Scheduler findScheduler(String schedulerName) throws SchedulerException {
if (this.beanFactory instanceof ListableBeanFactory) {
ListableBeanFactory lbf = (ListableBeanFactory) this.beanFactory;
String[] beanNames = lbf.getBeanNamesForType(Scheduler.class);
for (String beanName : beanNames) {
Scheduler schedulerBean = (Scheduler) lbf.getBean(beanName);
if (schedulerName.equals(schedulerBean.getSchedulerName())) {
return schedulerBean;
}
}
}
Scheduler schedulerInRepo = SchedulerRepository.getInstance().lookup(schedulerName);
if (schedulerInRepo == null) {
throw new IllegalStateException("No Scheduler named '" + schedulerName + "' found");
}
return schedulerInRepo;
}
use of org.quartz.Scheduler in project sling by apache.
the class WebConsolePrinter method printConfiguration.
/**
* Print out the configuration
* @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
*/
public void printConfiguration(PrintWriter pw) {
pw.println(HEADLINE);
pw.println();
final Map<String, SchedulerProxy> proxies = this.scheduler.getSchedulers();
if (!proxies.isEmpty()) {
pw.println("Status : active");
pw.println("Discovery : " + (QuartzJobExecutor.DISCOVERY_AVAILABLE.get() ? "available" : "not available"));
for (final Map.Entry<String, SchedulerProxy> entry : proxies.entrySet()) {
final Scheduler s = entry.getValue().getScheduler();
try {
pw.print("Name : ");
pw.println(s.getSchedulerName());
pw.print("ThreadPool: ");
pw.println(entry.getKey());
pw.print("Id : ");
pw.println(s.getSchedulerInstanceId());
pw.println();
final List<JobInfo> activeJobs = new ArrayList<>();
final List<JobInfo> disabledJobs = new ArrayList<>();
for (final String group : s.getJobGroupNames()) {
final Set<JobKey> keys = s.getJobKeys(GroupMatcher.jobGroupEquals(group));
for (final JobKey key : keys) {
final JobDetail detail = s.getJobDetail(key);
final QuartzJobExecutor.JobDesc desc = new QuartzJobExecutor.JobDesc(detail.getJobDataMap());
// only print jobs started through the sling scheduler
if (desc.isKnownJob()) {
final JobInfo info = new JobInfo();
info.name = desc.name;
info.className = desc.job.getClass().getName();
info.concurrent = !detail.isConcurrentExectionDisallowed();
// check run on information
if (desc.runOn != null) {
if (desc.isRunOnLeader()) {
info.runOn = "LEADER";
} else if (desc.isRunOnSingle()) {
info.runOn = "SINGLE";
} else {
info.runOn = Arrays.toString(desc.runOn);
}
if (desc.isRunOnLeader() || desc.isRunOnSingle()) {
if (QuartzJobExecutor.DISCOVERY_AVAILABLE.get()) {
if (QuartzJobExecutor.DISCOVERY_INFO_AVAILABLE.get()) {
if (desc.isRunOnLeader() || QuartzJobExecutor.FORCE_LEADER.get()) {
if (!QuartzJobExecutor.IS_LEADER.get()) {
info.reason = "not leader";
}
} else {
final String id = desc.shouldRunAsSingleOn();
if (id != null) {
info.reason = "single distributed elsewhere " + id;
}
}
} else {
info.reason = "no discovery info";
}
} else {
info.reason = "no discovery";
}
} else {
// sling IDs
final String myId = QuartzJobExecutor.SLING_ID;
if (myId == null) {
info.reason = "no Sling settings";
} else {
boolean schedule = false;
for (final String id : desc.runOn) {
if (myId.equals(id)) {
schedule = true;
break;
}
}
if (!schedule) {
info.reason = "Sling ID";
}
}
}
}
info.bundleId = (Long) detail.getJobDataMap().get(QuartzScheduler.DATA_MAP_BUNDLE_ID);
info.serviceId = (Long) detail.getJobDataMap().get(QuartzScheduler.DATA_MAP_SERVICE_ID);
int index = 0;
final List<? extends Trigger> triggers = s.getTriggersOfJob(key);
info.triggers = new String[triggers.size()];
for (final Trigger trigger : triggers) {
info.triggers[index] = trigger.toString();
index++;
}
if (info.reason != null) {
disabledJobs.add(info);
} else {
activeJobs.add(info);
}
}
}
}
if (!activeJobs.isEmpty()) {
pw.println();
pw.println("Active Jobs");
pw.println("-----------");
for (final JobInfo info : activeJobs) {
print(pw, info);
}
}
if (!disabledJobs.isEmpty()) {
pw.println();
pw.println("Inactive Jobs");
pw.println("-------------");
for (final JobInfo info : disabledJobs) {
print(pw, info);
}
}
} catch (final SchedulerException se) {
pw.print("Unable to print complete configuration: ");
pw.println(se.getMessage());
}
pw.println();
}
} else {
pw.println("Status : not active");
}
pw.println();
}
use of org.quartz.Scheduler in project searchcode-server by boyter.
the class JobService method startSpellingJob.
/**
* Starts a background job which updates the spelling corrector
*/
private void startSpellingJob() {
try {
Scheduler scheduler = Singleton.getScheduler();
// Setup the indexer which runs forever adding documents to be indexed
JobDetail job = newJob(PopulateSpellingCorrectorJob.class).withIdentity("spellingjob").build();
SimpleTrigger trigger = newTrigger().withIdentity("spellingjob").withSchedule(simpleSchedule().withIntervalInSeconds(360).repeatForever()).build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
} catch (SchedulerException ex) {
Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
}
}
use of org.quartz.Scheduler in project searchcode-server by boyter.
the class JobService method startEnqueueJob.
/**
* Starts a background job which pulls all repositories from the database and adds them to the
* queue to be indexed
*/
private void startEnqueueJob() {
try {
Scheduler scheduler = Singleton.getScheduler();
// Setup the indexer which runs forever adding documents to be indexed
JobDetail job = newJob(EnqueueRepositoryJob.class).withIdentity("enqueuejob").build();
SimpleTrigger trigger = newTrigger().withIdentity("enqueuejob").withSchedule(simpleSchedule().withIntervalInSeconds(this.UPDATETIME).repeatForever()).build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
Scheduler scheduler2 = Singleton.getScheduler();
// Setup the indexer which runs forever adding documents to be indexed
JobDetail job2 = newJob(EnqueueFileRepositoryJob.class).withIdentity("enqueuefilejob").build();
SimpleTrigger trigger2 = newTrigger().withIdentity("enqueuefilejob").withSchedule(simpleSchedule().withIntervalInSeconds(this.FILEINDEXUPDATETIME).repeatForever()).build();
scheduler2.scheduleJob(job2, trigger2);
scheduler2.start();
} catch (SchedulerException ex) {
Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
}
}
use of org.quartz.Scheduler in project searchcode-server by boyter.
the class JobService method startIndexGitRepoJobs.
/**
* Creates a git repo indexer job which will pull from the list of git repositories and start
* indexing them
*/
public void startIndexGitRepoJobs(String uniquename) {
try {
Scheduler scheduler = Singleton.getScheduler();
JobDetail job = newJob(IndexGitRepoJob.class).withIdentity("updateindex-git-" + uniquename).build();
SimpleTrigger trigger = newTrigger().withIdentity("updateindex-git-" + uniquename).withSchedule(simpleSchedule().withIntervalInSeconds(this.INDEXTIME).repeatForever()).build();
job.getJobDataMap().put("REPOLOCATIONS", this.REPOLOCATION);
job.getJobDataMap().put("LOWMEMORY", this.LOWMEMORY);
scheduler.scheduleJob(job, trigger);
scheduler.start();
} catch (SchedulerException ex) {
Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
}
}
Aggregations