當前位置: 首頁>>代碼示例>>Java>>正文


Java TriggerBuilder.startNow方法代碼示例

本文整理匯總了Java中org.quartz.TriggerBuilder.startNow方法的典型用法代碼示例。如果您正苦於以下問題:Java TriggerBuilder.startNow方法的具體用法?Java TriggerBuilder.startNow怎麽用?Java TriggerBuilder.startNow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.quartz.TriggerBuilder的用法示例。


在下文中一共展示了TriggerBuilder.startNow方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTrigger

import org.quartz.TriggerBuilder; //導入方法依賴的package包/類
@Override
public Trigger getTrigger() {
	Checker.require(triggerKey).notNull();
	TriggerBuilder<Trigger> triggerBuilder = newTrigger().withIdentity(triggerKey);
	if (getStartTime() == null) {
		triggerBuilder.startNow();
	} else {
		triggerBuilder.startAt(getStartTime());
	}
	if (getEndTime() != null) {
		triggerBuilder.endAt(getEndTime());
	}
	if (isRepeatable()) {
		SimpleScheduleBuilder scheduleBuilder = simpleSchedule();
		scheduleBuilder.withIntervalInSeconds(getIntervalInSeconds());
		if (isRepeatForever()) {
			scheduleBuilder.repeatForever();
		} else {
			scheduleBuilder.withRepeatCount(getRepeatCount());
		}
		triggerBuilder.withSchedule(scheduleBuilder);
	}
	return triggerBuilder.build();
}
 
開發者ID:daileyet,項目名稱:webscheduler,代碼行數:25,代碼來源:SimpleTaskTrigger.java

示例2: newJob

import org.quartz.TriggerBuilder; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.PUT)
public ResultVO newJob(@Valid JobVO jobVO, BindingResult bResult) throws SchedulerException {
	ResultVO result = new ResultVO();
	if (bResult.hasErrors()) {
		for (FieldError fieldError : bResult.getFieldErrors()) {
			result.addError(fieldError);
		}
		return result;
	} else if (scheduler.getJobDetail(new JobKey(jobVO.getDataSetId(), CsvJob.GROUP)) != null) {
		result.addError("job 已存在");
		return result;
	} else if (!validateSQL(jobVO)) {
		result.addError("無法執行 sql");
		return result;
	}

	JobDataMap map = new JobDataMap();
	map.put(JobConstant.DATABASE_DRIVER_CLASS_NAME, jobVO.getDriverClassName());
	map.put(JobConstant.DATABASE_URL, jobVO.getUrl());
	map.put(JobConstant.DATABASE_USERNAME, jobVO.getUsername());
	map.put(JobConstant.DATABASE_PASSWORD, jobVO.getPassword());
	map.put(JobConstant.SQL, jobVO.getSql());

	JobDetail job = JobBuilder.newJob(CsvJob.class).withIdentity(jobVO.getDataSetId(), CsvJob.GROUP)
			.withDescription(jobVO.getDescription()).setJobData(map).build();

	TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger().forJob(job);
	if (jobVO.getIntervalDay() != null) {
		triggerBuilder.withSchedule(SimpleScheduleBuilder.repeatHourlyForever(jobVO.getIntervalDay() * 24));
	}
	if (jobVO.getStartTime() != null) {
		triggerBuilder.startAt(jobVO.getStartTime());
	} else {
		triggerBuilder.startNow();
	}

	scheduler.scheduleJob(job, triggerBuilder.build());

	return result;
}
 
開發者ID:mow811236,項目名稱:sample-schedule-job-admin,代碼行數:41,代碼來源:JobsRestful.java

示例3: scheduleCronTask

import org.quartz.TriggerBuilder; //導入方法依賴的package包/類
/**
 * Schedules a new task using supplied cron expression.
 *
 * @param inJobName Name of new task.
 * @param inTriggerName Name of trigger for the new task.
 * @param inGroupName Name of group to which new task and trigger is to belong.
 * @param inJobClass The job class that will be executed when the new task triggers.
 * @param inCronExpression Cron expression specifying when task is to be
 * executed.
 * @param inJobDataMap Map holding information to be passed to the
 * job being executed. Contents of map will be copied.
 * @param inStartDate Point in time after which task is to start being
 * scheduled for execution, or null if task is to be scheduled now.
 * @param inEndDate Point in time after which the task will no longer
 * be scheduled for execution, or null if task is to be scheduled
 * indefinitely.
 * @throws Exception If error occurs scheduling task.
 */
public void scheduleCronTask(final String inJobName, final String inTriggerName, final String inGroupName,
    final Class<? extends Job> inJobClass, final String inCronExpression, final Map<String, Object> inJobDataMap,
    final Date inStartDate, final Date inEndDate) throws Exception {
    final JobDetail theJob = JobBuilder.newJob(inJobClass).withIdentity(inJobName, inGroupName).build();

    /* Copy job data from the supplied map to the actual job data map. */
    theJob.getJobDataMap().putAll(inJobDataMap);

    /*
     * Create builder that will create a schedule for the new task using
     * the supplied cron expression.
     */
    final CronScheduleBuilder theScheduleBuilder = CronScheduleBuilder.cronSchedule(inCronExpression);

    /*
     * Create a trigger builder using the schedule builder,
     * the start and end dates, if supplied.
     */
    TriggerBuilder<CronTrigger> theTriggerBuilder =
        TriggerBuilder.newTrigger().withIdentity(inTriggerName, inGroupName).withSchedule(theScheduleBuilder);
    /* If no start date supplied, start now, else start at start date. */
    if (inStartDate == null) {
        theTriggerBuilder = theTriggerBuilder.startNow();
    } else {
        theTriggerBuilder = theTriggerBuilder.startAt(inStartDate);
    }
    /*  If an end date supplied end at that date, otherwise continue indefinitely. */
    theTriggerBuilder = theTriggerBuilder.endAt(inEndDate);

    /* Schedule the new task. */
    mTaskScheduler.scheduleJob(theJob, theTriggerBuilder.build());

    LOGGER.debug("Scheduled task {} in group {}", inJobName, inGroupName);
}
 
開發者ID:krizsan,項目名稱:message-cowboy,代碼行數:53,代碼來源:QuartzSchedulerHelper.java

示例4: createTrigger

import org.quartz.TriggerBuilder; //導入方法依賴的package包/類
protected Trigger createTrigger(JobDataMap data, Date start, int interval,
		int repeat, Date end) {

	TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();

	if (data != null) {
		triggerBuilder.usingJobData(data);
	}
	if (interval > 0) {
		SimpleScheduleBuilder schedule = SimpleScheduleBuilder
				.simpleSchedule();
		schedule.withIntervalInMilliseconds(interval).withRepeatCount(
				repeat);
		triggerBuilder.withSchedule(schedule);
	}

	if (start != null) {
		triggerBuilder.startAt(start);
	} else {
		triggerBuilder.startNow();
	}

	if (end != null) {
		triggerBuilder.endAt(end);
	}

	return triggerBuilder.build();
}
 
開發者ID:ludup,項目名稱:hypersocket-framework,代碼行數:29,代碼來源:SchedulerServiceImpl.java

示例5: initTrigger

import org.quartz.TriggerBuilder; //導入方法依賴的package包/類
protected Trigger initTrigger(String name, Options<ScheduleOption> opts) {
    TriggerBuilder<Trigger> builder = TriggerBuilder.newTrigger()
            .withIdentity(name, name());

    if (opts.has(AT)) {
        builder.startAt(opts.getDate(AT));
    } else if (opts.has(IN)) {
        builder.startAt(new java.util.Date(System.currentTimeMillis() + opts.getLong(IN)));
    } else {
        builder.startNow();
    }

    if (opts.has(UNTIL)) {
        builder.endAt(opts.getDate(UNTIL));
    }

    if (opts.has(CRON)) {
        builder.withSchedule(CronScheduleBuilder.cronSchedule(opts.getString(CRON)));
    } else if (opts.has(EVERY)) {
        SimpleScheduleBuilder schedule =
                SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInMilliseconds(opts.getInt(EVERY));
        if (opts.has(LIMIT)) {
            schedule.withRepeatCount(opts.getInt(LIMIT) - 1);
        } else {
            schedule.repeatForever();
        }
        builder.withSchedule(schedule);
    }

    return builder.build();
}
 
開發者ID:projectodd,項目名稱:wunderboss,代碼行數:33,代碼來源:QuartzScheduling.java

示例6: createUpdateWeatherDataScheduler

import org.quartz.TriggerBuilder; //導入方法依賴的package包/類
private Scheduler createUpdateWeatherDataScheduler(int interval,
		TimeUnit unit, ResourceBinder resourceBinder, int startDelay)
		throws SchedulerException, IOException, URISyntaxException {

	StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
	Properties properties = new Properties();
	properties.setProperty("org.quartz.threadPool.threadCount",
			String.valueOf(1));
	schedulerFactory.initialize(properties);

	Scheduler scheduler = schedulerFactory.getScheduler();

	JobDetail job = JobBuilder.newJob(UpdateWeatherData.class).build();

	job.getJobDataMap().put("baseDir", ResourceBinder
			.getDataDir(this.getClass()).toFile().getCanonicalPath());
	job.getJobDataMap().put("resourceBinder", resourceBinder);

	int secs = 60;
	switch (unit) {
	case HOUR:
		secs = interval * 60 * 60;
		break;
	case MINUTE:
		secs = interval * 60;
	case SECOND:
		secs = interval;
		break;
	default:
		break;
	}

	ScheduleBuilder<SimpleTrigger> scheduleBuilder = SimpleScheduleBuilder
			.simpleSchedule().withIntervalInSeconds(secs).repeatForever();

	TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger()
			.withIdentity("trigger1", "group1");

	if (startDelay < 1)
		triggerBuilder.startNow();
	else
		triggerBuilder.startAt(
				DateBuilder.futureDate(startDelay, IntervalUnit.SECOND));

	Trigger trigger = triggerBuilder.withSchedule(scheduleBuilder).build();

	scheduler.scheduleJob(job, trigger);

	return scheduler;

}
 
開發者ID:biggis-project,項目名稱:path-optimizer,代碼行數:52,代碼來源:WebApi.java

示例7: registerJob

import org.quartz.TriggerBuilder; //導入方法依賴的package包/類
private void registerJob(
        final String jobName, final Job jobInstance,
        final String cronExpression, final Date startAt,
        final Map<String, Object> jobMap)
        throws SchedulerException {

    if (isRunning(new JobKey(jobName, Scheduler.DEFAULT_GROUP))) {
        LOG.debug("Job {} already running, cancel", jobName);
        return;
    }

    // 0. unregister job
    unregisterJob(jobName);

    // 1. Job bean
    ApplicationContextProvider.getBeanFactory().registerSingleton(jobName, jobInstance);

    // 2. JobDetail bean
    JobBuilder jobDetailBuilder = JobBuilder.newJob(jobInstance.getClass()).
            withIdentity(jobName).
            usingJobData(new JobDataMap(jobMap));

    // 3. Trigger
    if (cronExpression == null && startAt == null) {
        // Jobs added with no trigger must be durable
        scheduler.getScheduler().addJob(jobDetailBuilder.storeDurably().build(), true);
    } else {
        TriggerBuilder<?> triggerBuilder;

        if (cronExpression == null) {
            triggerBuilder = TriggerBuilder.newTrigger().
                    withIdentity(JobNamer.getTriggerName(jobName)).
                    startAt(startAt);
        } else {
            triggerBuilder = TriggerBuilder.newTrigger().
                    withIdentity(JobNamer.getTriggerName(jobName)).
                    withSchedule(CronScheduleBuilder.cronSchedule(cronExpression));

            if (startAt == null) {
                triggerBuilder = triggerBuilder.startNow();
            } else {
                triggerBuilder = triggerBuilder.startAt(startAt);
            }
        }

        scheduler.getScheduler().scheduleJob(jobDetailBuilder.build(), triggerBuilder.build());
    }
}
 
開發者ID:apache,項目名稱:syncope,代碼行數:49,代碼來源:JobManagerImpl.java

示例8: configureTriggerJob

import org.quartz.TriggerBuilder; //導入方法依賴的package包/類
private Trigger configureTriggerJob(String jobName, String jobGroup, Job job) {
 TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
 		 
 // base trigger configuration 
 triggerBuilder.withIdentity(jobName, jobGroup);
 
 if (job.getStartTime() != null)
	 triggerBuilder.startAt(job.getStartTime());
 else {
	 if (job.getActive())
		 triggerBuilder.startNow();
 }

 if (job.getEndTime() != null)
	 triggerBuilder.endAt(job.getEndTime());		 
	 
 triggerBuilder.withPriority(job.getJobTriggerPriority());
 
 // propietary trigger configuration
 if (job.getJobTriggerType().getCode().equals(Job.JOB_TRIGGER_TYPE.SIMPLE.name())) {
	 SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule();
	 
	 if (job.getJobInterval() != null) {
		 if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.SECOND.name()))
			 simpleScheduleBuilder.withIntervalInSeconds(job.getJobInterval());
		 else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.MINUTE.name()))
			 simpleScheduleBuilder.withIntervalInMinutes(job.getJobInterval());
		 else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.HOUR.name()))
			 simpleScheduleBuilder.withIntervalInHours(job.getJobInterval());
		 else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.DAY.name()))
			 simpleScheduleBuilder.withIntervalInHours(job.getJobInterval() * 24);
		 else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.WEEK.name()))
			 simpleScheduleBuilder.withIntervalInHours(job.getJobInterval() * 24 * 7);
	 }
	
	 if (job.getRepeatCount() != null)
		 simpleScheduleBuilder.withRepeatCount(job.getRepeatCount());
	 else
		 simpleScheduleBuilder.repeatForever();
	 
     triggerBuilder.withSchedule(simpleScheduleBuilder);
		 
 }
 else if (job.getJobTriggerType().getCode().equals(Job.JOB_TRIGGER_TYPE.CRON.name())) {
	 CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
	 
	 triggerBuilder.withSchedule(cronScheduleBuilder);
 }
 						 
 return triggerBuilder.build();
}
 
開發者ID:thingtrack,項目名稱:konekti,代碼行數:52,代碼來源:JobManagerServiceImpl.java

示例9: schedule

import org.quartz.TriggerBuilder; //導入方法依賴的package包/類
private void schedule(NamedJob job, long delay, long period) throws SchedulerException {
	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setKey(new JobKey(job.getName()));
	jobDetail.setJobClass(job.getClass());
	
	this.quartzFactory.register(job.getName(), job, period == 0 ? false : true);
	
	TriggerBuilder<Trigger> builder = TriggerBuilder.newTrigger()
			.withIdentity(jobDetail.getKey().getName().concat("_trigger"));
	
	if (delay != 0) {
		Date delayDate = new Date();
		delayDate = new Date(delayDate.getTime() + delay);
		builder = builder.startAt(delayDate);
	}
	else {
		builder = builder.startNow();
	}
	
	if (period != 0) {
		builder.withSchedule(
				SimpleScheduleBuilder.simpleSchedule()
						.withIntervalInMilliseconds(period)
						.repeatForever());
	}
	
	Trigger trigger = builder.build();

	try {
		this.quartz.scheduleJob(jobDetail, trigger);
		LOGGER.info(
				String.format("Added Job '%s' (%s) to scheduling. Next execution at %s; Recurring: %s",
						jobDetail.getKey().getName(),
						job.getClass().getSimpleName(),
						trigger.getStartTime(),
						period));
	} catch (SchedulerException e) {
		LOGGER.warn(e.getMessage(), e);
		throw e;
	}
}
 
開發者ID:52North,項目名稱:ArcGIS-Server-SOS-Extension,代碼行數:42,代碼來源:QuartzCacheScheduler.java

示例10: submit

import org.quartz.TriggerBuilder; //導入方法依賴的package包/類
@Override
public void submit(String identifier, CheckRunner t, long delay, long period)
		throws TaskExecutorException {
	QuartzRunner job = new QuartzRunner(t, this.db);
	JobDetailImpl jobDetail = new JobDetailImpl();
	jobDetail.setKey(new JobKey(identifier));
	jobDetail.setJobClass(job.getClass());
	
	this.factory.register(jobDetail.getKey().getName(), job);

	TriggerBuilder<Trigger> builder = TriggerBuilder.newTrigger()
			.withIdentity(identifier.concat("_trigger"));
	
	if (delay != 0) {
		Date delayDate = new Date();
		delayDate = new Date(delayDate.getTime() + delay);
		builder = builder.startAt(delayDate);
	}
	else {
		builder = builder.startNow();
	}
	
	if (period != 0) {
		builder.withSchedule(
				SimpleScheduleBuilder.simpleSchedule()
						.withIntervalInMilliseconds(period)
						.repeatForever());
	}
	
	Trigger trigger = builder.build();

	try {
		this.quartz.scheduleJob(jobDetail, trigger);

		synchronized (this) {
			this.jobs.put(identifier, jobDetail);
		}

		logger.info("Added Job '{}' to scheduling.", identifier);
	} catch (SchedulerException e) {
		logger.warn(e.getMessage(), e);
		throw new TaskExecutorException(e);
	}

}
 
開發者ID:52North,項目名稱:Supervisor,代碼行數:46,代碼來源:QuartzTaskExecutor.java


注:本文中的org.quartz.TriggerBuilder.startNow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。