Search in sources :

Example 41 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project jforum2 by rafaelsteil.

the class POPJobStarter method startJob.

public static void startJob() throws SchedulerException {
    boolean isEnabled = SystemGlobals.getBoolValue(ConfigKeys.MAIL_POP3_INTEGRATION_ENABLED);
    if (!isStarted && isEnabled) {
        String filename = SystemGlobals.getValue(ConfigKeys.QUARTZ_CONFIG);
        String cronExpression = SystemGlobals.getValue("org.quartz.context.mailintegration.cron.expression");
        scheduler = new StdSchedulerFactory(filename).getScheduler();
        Trigger trigger = null;
        try {
            trigger = new CronTrigger(POPListener.class.getName(), "pop3Integration", cronExpression);
            logger.info("Starting POP3 integration expression " + cronExpression);
            scheduler.scheduleJob(new JobDetail(POPListener.class.getName(), "pop3Integration", POPListener.class), trigger);
            scheduler.start();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    isStarted = true;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) CronTrigger(org.quartz.CronTrigger) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) ParseException(java.text.ParseException)

Example 42 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project oxCore by GluuFederation.

the class QuartzSchedulerManager method initInternal.

protected void initInternal() {
    try {
        StdSchedulerFactory factory = new StdSchedulerFactory();
        factory.initialize(QUARTZ_PROPERTY_FILE_NAME);
        scheduler = factory.getScheduler();
        // Register job listener to bound request context to every job
        // execution
        scheduler.getListenerManager().addJobListener(jobListener, EverythingMatcher.allJobs());
        // Replace default job factory
        scheduler.setJobFactory(jobFactory);
    } catch (SchedulerException ex) {
        throw new IllegalStateException("Failed to initialize Quartz scheduler manager", ex);
    }
    log.info("Quartz scheduler manager initialized");
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerException(org.quartz.SchedulerException)

Example 43 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project siddhi by wso2.

the class CronTrigger method scheduleCronJob.

private void scheduleCronJob(String cronString, String elementId) {
    try {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        scheduler = schedulerFactory.getScheduler();
        jobName = "TriggerJob_" + elementId;
        JobKey jobKey = new JobKey(jobName, jobGroup);
        if (scheduler.checkExists(jobKey)) {
            scheduler.deleteJob(jobKey);
        }
        scheduler.start();
        JobDataMap dataMap = new JobDataMap();
        dataMap.put("trigger", this);
        JobDetail job = org.quartz.JobBuilder.newJob(CronTrigger.class).withIdentity(jobName, jobGroup).usingJobData(dataMap).build();
        org.quartz.Trigger trigger = org.quartz.TriggerBuilder.newTrigger().withIdentity("TriggerJob_" + elementId, jobGroup).withSchedule(CronScheduleBuilder.cronSchedule(cronString)).build();
        scheduler.scheduleJob(job, trigger);
    } catch (SchedulerException e) {
        LOG.error(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + " Error while instantiating quartz scheduler for trigger '" + triggerDefinition.getId() + "'.", e);
    }
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) JobKey(org.quartz.JobKey) JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerFactory(org.quartz.SchedulerFactory)

Example 44 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project javautils by jiadongpo.

the class StartQuartzJobTest method testQuartz.

public static void testQuartz() throws Exception {
    SchedulerFactory schedFact = new StdSchedulerFactory();
    Scheduler sched = schedFact.getScheduler();
    sched.start();
    JobDetail job = JobBuilder.newJob(StartQuartzJob.class).withIdentity("myJob", "group1").usingJobData("jobSays", "hello world!").usingJobData("myFloatValue", 3.141f).build();
    Trigger trigger = TriggerBuilder.newTrigger().withIdentity("myTrigger", "group1").startNow().withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?")).build();
    sched.scheduleJob(job, trigger);
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory)

Example 45 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project java-example by 1479005017.

the class QuartzTest method testModify.

@Test
public void testModify() throws Exception {
    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    Scheduler scheduler = schedulerFactory.getScheduler();
    QuartzManager quartzManager = new QuartzManager(scheduler);
    quartzManager.addJob("myJob", "test", MyJob.class, Collections.singletonMap("x", "1"), "0/5 * * * * ?");
    quartzManager.startScheduler();
    Thread.sleep(1500);
    for (int i = 0; Thread.activeCount() > 0; i++) {
        if (i % 3 == 0) {
            quartzManager.modifyJob("myJob", "test", Collections.singletonMap("x", i + ""));
        }
        Thread.sleep(1000);
    }
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Scheduler(org.quartz.Scheduler) QuartzManager(com.example.quartz.QuartzManager) SchedulerFactory(org.quartz.SchedulerFactory) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Test(org.junit.Test)

Aggregations

StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)66 SchedulerFactory (org.quartz.SchedulerFactory)29 SchedulerException (org.quartz.SchedulerException)22 Scheduler (org.quartz.Scheduler)19 JobDetail (org.quartz.JobDetail)17 Logger (org.slf4j.Logger)14 Date (java.util.Date)11 Properties (java.util.Properties)11 Trigger (org.quartz.Trigger)11 JobKey (org.quartz.JobKey)7 JobDataMap (org.quartz.JobDataMap)6 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)5 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 DateBuilder.nextGivenSecondDate (org.quartz.DateBuilder.nextGivenSecondDate)4 SimpleTrigger (org.quartz.SimpleTrigger)4 ParseException (java.text.ParseException)3 CronTrigger (org.quartz.CronTrigger)3 SimpleThreadPool (org.quartz.simpl.SimpleThreadPool)3 QuartzManager (com.example.quartz.QuartzManager)2