当前位置: 首页>>代码示例>>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;未经允许,请勿转载。