当前位置: 首页>>代码示例>>Java>>正文


Java TriggerBuilder类代码示例

本文整理汇总了Java中org.quartz.TriggerBuilder的典型用法代码示例。如果您正苦于以下问题:Java TriggerBuilder类的具体用法?Java TriggerBuilder怎么用?Java TriggerBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TriggerBuilder类属于org.quartz包,在下文中一共展示了TriggerBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildTrigger

import org.quartz.TriggerBuilder; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private Trigger buildTrigger(String confId, JobScheduling conf, JobKey job) {

    TriggerKey key = this.buildTiggerKey(confId);
    TriggerBuilder trigger = TriggerBuilder.newTrigger().withIdentity(key);

    // Set CRON value
    if (StringUtils.isNotEmpty(conf.getValue())) {
        trigger.withSchedule(CronScheduleBuilder.cronSchedule(conf.getValue()));
    }

    // Set DATE value
    if (conf.getStartAt() > 0) {
        trigger.startAt(new Date(conf.getStartAt()));
    }

    if (job != null) {
        trigger.forJob(job);
    }

    return trigger.build();
}
 
开发者ID:AirVantage,项目名称:av-sched,代码行数:23,代码来源:JobSchedulingServiceImpl.java

示例2: refreshMetadata

import org.quartz.TriggerBuilder; //导入依赖的package包/类
/**
 * Refresh metadata. Schedules the job to retrieve metadata.
 * @throws SchedulerException the scheduler exception
 */
@PostConstruct
public void refreshMetadata() throws SchedulerException {
    final Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            buildMetadataResolverAggregate();
        }
    });
    thread.start();

    final JobDetail job = JobBuilder.newJob(this.getClass())
            .withIdentity(this.getClass().getSimpleName()).build();
    final Trigger trigger = TriggerBuilder.newTrigger()
            .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                    .withIntervalInMinutes(this.refreshIntervalInMinutes)
                    .repeatForever()).build();

    final SchedulerFactory schFactory = new StdSchedulerFactory();
    final Scheduler sch = schFactory.getScheduler();
    sch.start();
    sch.scheduleJob(job, trigger);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:27,代码来源:StaticMetadataResolverAdapter.java

示例3: scheduleJob

import org.quartz.TriggerBuilder; //导入依赖的package包/类
/**
 * The user may configure this binding to update the internal clock of
 * FHT80b devices via rf command. The method takes care of scheduling this
 * job.
 */
private JobKey scheduleJob(Class<? extends Job> jobClass, String cronExpression) {
	JobKey jobKey = null;
	try {
		Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
		JobDetail detail = JobBuilder.newJob(jobClass).withIdentity("FHT "+jobClass.getSimpleName(), "cul").build();
		detail.getJobDataMap().put(FHTBinding.class.getName(), this);
		
		CronTrigger trigger = TriggerBuilder.newTrigger().forJob(detail)
				.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();
		jobKey = detail.getKey();
		sched.scheduleJob(detail, trigger);
	} catch (SchedulerException e) {
		logger.error("Can't schedule time update job", e);
	}
	return jobKey;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:22,代码来源:FHTBinding.java

示例4: schedule

import org.quartz.TriggerBuilder; //导入依赖的package包/类
protected <T extends Job> void schedule(final Class<T> reference, final Map<String, Object> jobMap)
        throws JobExecutionException {

    @SuppressWarnings("unchecked")
    T jobInstance = (T) ApplicationContextProvider.getBeanFactory().
            createBean(reference, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
    String jobName = getClass().getName() + UUID.randomUUID();

    jobMap.put(JobManager.DOMAIN_KEY, AuthContextUtils.getDomain());

    ApplicationContextProvider.getBeanFactory().registerSingleton(jobName, jobInstance);

    JobBuilder jobDetailBuilder = JobBuilder.newJob(reference).
            withIdentity(jobName).
            usingJobData(new JobDataMap(jobMap));

    TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger().
            withIdentity(JobNamer.getTriggerName(jobName)).
            startNow();

    try {
        scheduler.getScheduler().scheduleJob(jobDetailBuilder.build(), triggerBuilder.build());
    } catch (SchedulerException e) {
        throw new JobExecutionException("Could not schedule, aborting", e);
    }
}
 
开发者ID:apache,项目名称:syncope,代码行数:27,代码来源:SchedulingPullActions.java

示例5: addSchedule

import org.quartz.TriggerBuilder; //导入依赖的package包/类
/**
 * 增加一个调度任务(cron版)
 * 
 * @param name
 *            任务名称
 * @param job
 *            执行内容
 * @param cronExpression
 *            cron表达式
 * @throws SchedulerException
 */
public Trigger addSchedule(String name, Class<? extends Job> task, String cronExpression, JobDataMap param)
		throws SchedulerException {
	Scheduler sched = SF.getScheduler();
	JobBuilder builder = JobBuilder.newJob(task);
	builder.withIdentity(name, Scheduler.DEFAULT_GROUP);
	if (param != null) {
		builder.usingJobData(param);
	}
	Trigger trigger = TriggerBuilder.newTrigger().withIdentity(name, Scheduler.DEFAULT_GROUP)
			.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();
	sched.scheduleJob(builder.build(), trigger);
	if (!sched.isShutdown())
		sched.start();
	return trigger;
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:27,代码来源:SchedulerUtil.java

示例6: 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

示例7: create

import org.quartz.TriggerBuilder; //导入依赖的package包/类
@Override
public void create(ScheduleJob scheduleJob) throws SchedulerException {
	Scheduler scheduler = schedulerFactoryBean.getScheduler();

	Class<? extends Job> jobClass = null;

	try {
		jobClass = (Class<? extends Job>) Class.forName(scheduleJob.getJobClassName());
	} catch (ClassNotFoundException e) {
		throw new SchedulerException(e);
	}

	if (null != jobClass) {
		JobDetail jobDetail = JobBuilder.newJob(jobClass)
				.withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroupName())
				.withDescription(scheduleJob.getJobDescription()).build();
		Trigger trigger = TriggerBuilder.newTrigger()
				.withIdentity(scheduleJob.getTriggerName(), scheduleJob.getTriggerGroupName())
				.withDescription(scheduleJob.getTriggerDescription())
				.withSchedule(CronScheduleBuilder.cronSchedule(scheduleJob.getTriggerCronExpression())).startNow()
				.build();

		scheduler.scheduleJob(jobDetail, trigger);
	}
}
 
开发者ID:easynet-cn,项目名称:easynetcn-cloud,代码行数:26,代码来源:JobServiceImpl.java

示例8: startAndSchedule

import org.quartz.TriggerBuilder; //导入依赖的package包/类
public synchronized void startAndSchedule(Integer jobIntervalSeconds) throws SchedulerException {
	if (!scheduler.isStarted()) {
		logger.debug(DEBUG_JOBS_INIT_STARTING_MESSAGE);

		scheduler.start();

		JobDetail job = JobBuilder.newJob(FetchEventsJob.class).build();
		Trigger trigger = TriggerBuilder.newTrigger().startNow().withSchedule(
				SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(jobIntervalSeconds).repeatForever())
				.build();

		scheduler.scheduleJob(job, trigger);

		logger.debug(DEBUG_JOBS_INIT_DONE_MESSAGE);
	} else {
		logger.debug(DEBUG_SCHEDULER_IS_ALREADY_STARTED_MESSAGE);
	}
}
 
开发者ID:SAP,项目名称:cloud-ariba-partner-flow-extension-ext,代码行数:19,代码来源:EventsScheduler.java

示例9: persistTrigger

import org.quartz.TriggerBuilder; //导入依赖的package包/类
/**
 * Persist the trigger in the Quartz scheduler.
 */
private VmSchedule persistTrigger(final VmSchedule schedule) throws SchedulerException {
	// The trigger for the common VM Job will the following convention :
	// schedule.id-subscription.id
	final String id = VmJob.format(schedule);
	final JobDetailImpl object = (JobDetailImpl) vmJobDetailFactoryBean.getObject();
	object.getJobDataMap().put("vmServicePlugin", this);
	final Trigger trigger = TriggerBuilder.newTrigger().withIdentity(id, SCHEDULE_TRIGGER_GROUP)
			.withSchedule(CronScheduleBuilder.cronSchedule(schedule.getCron()).inTimeZone(DateUtils.getApplicationTimeZone()))
			.forJob(object).usingJobData("subscription", schedule.getSubscription().getId())
			.usingJobData("operation", schedule.getOperation().name()).usingJobData("schedule", schedule.getId()).build();

	// Add this trigger
	vmSchedulerFactoryBean.getObject().scheduleJob(trigger);
	return schedule;
}
 
开发者ID:ligoj,项目名称:plugin-vm,代码行数:19,代码来源:VmResource.java

示例10: enableSessionValidation

import org.quartz.TriggerBuilder; //导入依赖的package包/类
public void enableSessionValidation() {  
    if (log.isDebugEnabled()) {  
        log.debug("Scheduling session validation job using Quartz with session validation interval of ["  
                + this.sessionValidationInterval + "]ms...");  
    }  
  
    try {  
        SimpleTrigger trigger = TriggerBuilder.newTrigger().startNow().withIdentity(JOB_NAME, Scheduler.DEFAULT_GROUP)  
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(sessionValidationInterval))  
                .build(); 
  
        JobDetail detail = JobBuilder.newJob(QuartzSessionValidationJob.class)  
                .withIdentity(JOB_NAME, Scheduler.DEFAULT_GROUP).build();  
        detail.getJobDataMap().put(SESSION_MANAGER_KEY, this.sessionManager);  
        Scheduler scheduler = getScheduler();  
  
        scheduler.scheduleJob(detail, trigger);  
        if (this.schedulerImplicitlyCreated) {  
            scheduler.start();  
            if (log.isDebugEnabled()) {  
                log.debug("Successfully started implicitly created Quartz Scheduler instance.");  
            }  
        }  
        this.enabled = true;  
  
        if (log.isDebugEnabled())  
            log.debug("Session validation job successfully scheduled with Quartz.");  
    } catch (SchedulerException e) {  
        if (log.isErrorEnabled())  
            log.error("Error starting the Quartz session validation job.  Session validation may not occur.", e);  
    }  
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:33,代码来源:QuartzSessionValidationScheduler.java

示例11: run

import org.quartz.TriggerBuilder; //导入依赖的package包/类
@Override
	public void run(String... strings) throws Exception {
		try {
			/*
			 * 在 Quartz 中, scheduler 由 SchedulerFactory创建:DirectSchedulerFactory 或者
			 * StdSchedulerFactory。第二种工厂 StdSchedulerFactory 使用较多,因为
			 * DirectSchedulerFactory 使用起来不够方便,需要作许多详细的手工编码设置。
			 */
			// 获取Scheduler实例
			scheduler = StdSchedulerFactory.getDefaultScheduler();
			scheduler.start();
//			System.out.println("scheduler.start");
//			System.out.println(scheduler.getSchedulerName());
			// 注册任务
			JobDetail jobDetail = JobBuilder.newJob(QuartzTask.class).withIdentity("QuartzTaskJob", "QuartzTaskGroup").build();
			// 设置出发时间(每1天执行1次)
			SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInHours(24).repeatForever();
			Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger", "group").startNow().withSchedule(simpleScheduleBuilder).build();
			// 交由Scheduler安排触发
			scheduler.scheduleJob(jobDetail, trigger);
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:CharleyXu,项目名称:tulingchat,代码行数:25,代码来源:QuartzConfig.java

示例12: serverTasks

import org.quartz.TriggerBuilder; //导入依赖的package包/类
public serverTasks() throws SchedulerException, ParseException{
	
	/* 
	 * 循环式的
	 */
	SchedulerFactory factory = new StdSchedulerFactory();
	Scheduler scheduler = factory.getScheduler();
	//设置启动时间
	DateBuilder.evenMinuteDate(new Date());
	JobDetail job = JobBuilder.newJob(job.class).withIdentity("job1", "group1").build();
 
	//job.getJobDataMap().put("a", true);//实现传参
	// @NOTICE
	// 与SimpleTrigger对比:类不同了,现在的是Trigger的子类CronTrigger;withSchedule中的参数变为CronScheduleBuilder了
	// CronScheduleBuilder可以通过类似"0/13 * * * * ?"这种表达式来创建定时任务
	// 当前这个表达式的定义是30分钟执行一次
	CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1")
			.withSchedule(CronScheduleBuilder.cronSchedule("1 0/30 * * * ?")).build();

	scheduler.scheduleJob(job, trigger);

	scheduler.start();
 
	//scheduler.shutdown(true);
	
}
 
开发者ID:Xvms,项目名称:xvms,代码行数:27,代码来源:serverTasks.java

示例13: updateExistingTrigger

import org.quartz.TriggerBuilder; //导入依赖的package包/类
private void updateExistingTrigger(Trigger quartzTrigger, Trigger existingQuartzTrigger) throws SchedulerException {
    if (!quartzTrigger.getJobKey().equals(existingQuartzTrigger.getJobKey())) {
        throw new SchedulingException(
                String.format("the updated trigger's job has to be identical to that of the previous trigger. tried changing [%s] to [%s]",
                        existingQuartzTrigger.getJobKey().toString(), quartzTrigger.getJobKey().toString()));
    }

    TriggerBuilder triggerUpdater = existingQuartzTrigger.getTriggerBuilder();
    Trigger updatedTrigger = triggerUpdater.forJob(quartzTrigger.getJobKey())
                                           .withSchedule(quartzTrigger.getScheduleBuilder())
                                           .build();
    updatedTrigger.getJobDataMap().putAll(quartzTrigger.getJobDataMap());
    scheduler.rescheduleJob(updatedTrigger.getKey(), updatedTrigger);
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:15,代码来源:QuartzSchedulerServiceImpl.java

示例14: addJob

import org.quartz.TriggerBuilder; //导入依赖的package包/类
private void addJob(ScheduleJob scheduleJob) throws Exception{  
  	checkNotNull(scheduleJob);
Preconditions.checkNotNull(StringUtils.isEmpty(scheduleJob.getCronExpression()), "CronExpression is null");

      TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());  
      CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);  
      if(trigger != null){  
          throw new Exception("job already exists!");  
      }
      
      // simulate job info db persist operation
      scheduleJob.setJobId(String.valueOf(QuartzJobFactory.jobList.size()+1));
      QuartzJobFactory.jobList.add(scheduleJob);
      
      JobDetail jobDetail = JobBuilder.newJob(QuartzJobFactory.class).withIdentity(scheduleJob.getJobName(),scheduleJob.getJobGroup()).build();  
      jobDetail.getJobDataMap().put("scheduleJob", scheduleJob);  

      CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());  
      trigger = TriggerBuilder.newTrigger().withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroup()).withSchedule(cronScheduleBuilder).build();  

      scheduler.scheduleJob(jobDetail, trigger);  

  }
 
开发者ID:jiwenxing,项目名称:springboot-quartz,代码行数:24,代码来源:ScheduleJobService.java

示例15: prvateAddQuartz

import org.quartz.TriggerBuilder; //导入依赖的package包/类
private boolean prvateAddQuartz(Class<? extends Job> jobClass,JobKey jobKey, CronScheduleBuilder builder, SimpleScheduleBuilder repeatForever) {
	if(scheduler==null){
		init();
	}
	//创建一个任务计划生成器	设置任务名称与分组	创建任务计划
	JobDetail job = JobBuilder.newJob(jobClass).withIdentity(jobKey).build();
	//创建一个触发生成器	设置触发器名称与分组	设置触发器出发条件	创建触发器
	Trigger trigger = TriggerBuilder.newTrigger().withIdentity(jobKey.getName(),jobKey.getGroup()).withSchedule(builder==null?repeatForever:builder).build();
	try {
		scheduler.scheduleJob(job, trigger);
		outLog("添加任务计划成功!");
		return true;
	} catch (SchedulerException e) {
		outLog("添加任务计划失败!");
	}
	return false;
}
 
开发者ID:zhiqiang94,项目名称:BasicsProject,代码行数:18,代码来源:QuartzUtil.java


注:本文中的org.quartz.TriggerBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。