dropwizard-jobs/dropwizard-jobs

View on GitHub
dropwizard-jobs-spring/src/main/java/io/dropwizard/jobs/SpringJobFactory.java

Summary

Maintainability
A
0 mins
Test Coverage
package io.dropwizard.jobs;

import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.spi.JobFactory;
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.context.ApplicationContext;

public class SpringJobFactory implements JobFactory {

    ApplicationContext context;

    public SpringJobFactory(ApplicationContext context) {
        this.context = context;
    }

    @Override
    public Job newJob(TriggerFiredBundle triggerFiredBundle, Scheduler scheduler) throws SchedulerException {
        JobDetail jobDetail = triggerFiredBundle.getJobDetail();
        Class<? extends Job> jobClass = jobDetail.getJobClass();
        return context.getBean(jobClass);
    }
}