org.quartz.ScheduleBuilder Java Examples

The following examples show how to use org.quartz.ScheduleBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleTriggerImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a {@link ScheduleBuilder} that is configured to produce a 
 * schedule identical to this trigger's schedule.
 * 
 * @see #getTriggerBuilder()
 */
@Override
public ScheduleBuilder<SimpleTrigger> getScheduleBuilder() {
    
    SimpleScheduleBuilder sb = SimpleScheduleBuilder.simpleSchedule()
    .withIntervalInMilliseconds(getRepeatInterval())
    .withRepeatCount(getRepeatCount());
    
    switch(getMisfireInstruction()) {
        case MISFIRE_INSTRUCTION_FIRE_NOW : sb.withMisfireHandlingInstructionFireNow();
        break;
        case MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT : sb.withMisfireHandlingInstructionNextWithExistingCount();
        break;
        case MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT : sb.withMisfireHandlingInstructionNextWithRemainingCount();
        break;
        case MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT : sb.withMisfireHandlingInstructionNowWithExistingCount();
        break;
        case MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT : sb.withMisfireHandlingInstructionNowWithRemainingCount();
        break;
    }
    
    return sb;
}
 
Example #2
Source File: CalendarIntervalTriggerImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a {@link ScheduleBuilder} that is configured to produce a 
 * schedule identical to this trigger's schedule.
 * 
 * @see #getTriggerBuilder()
 */
@Override
public ScheduleBuilder<CalendarIntervalTrigger> getScheduleBuilder() {
    
    CalendarIntervalScheduleBuilder cb = CalendarIntervalScheduleBuilder.calendarIntervalSchedule()
            .withInterval(getRepeatInterval(), getRepeatIntervalUnit());
        
    switch(getMisfireInstruction()) {
        case MISFIRE_INSTRUCTION_DO_NOTHING : cb.withMisfireHandlingInstructionDoNothing();
        break;
        case MISFIRE_INSTRUCTION_FIRE_ONCE_NOW : cb.withMisfireHandlingInstructionFireAndProceed();
        break;
    }
    
    return cb;
}
 
Example #3
Source File: DailyTimeIntervalTriggerImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a {@link ScheduleBuilder} that is configured to produce a 
 * schedule identical to this trigger's schedule.
 * 
 * @see #getTriggerBuilder()
 */
@Override
public ScheduleBuilder<DailyTimeIntervalTrigger> getScheduleBuilder() {
    
    DailyTimeIntervalScheduleBuilder cb = DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule()
            .withInterval(getRepeatInterval(), getRepeatIntervalUnit())
            .onDaysOfTheWeek(getDaysOfWeek()).startingDailyAt(getStartTimeOfDay()).endingDailyAt(getEndTimeOfDay());
        
    switch(getMisfireInstruction()) {
        case MISFIRE_INSTRUCTION_DO_NOTHING : cb.withMisfireHandlingInstructionDoNothing();
        break;
        case MISFIRE_INSTRUCTION_FIRE_ONCE_NOW : cb.withMisfireHandlingInstructionFireAndProceed();
        break;
    }
    
    return cb;
}
 
Example #4
Source File: CronTriggerImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a {@link ScheduleBuilder} that is configured to produce a 
 * schedule identical to this trigger's schedule.
 * 
 * @see #getTriggerBuilder()
 */
@Override
public ScheduleBuilder<CronTrigger> getScheduleBuilder() {
    
    CronScheduleBuilder cb = CronScheduleBuilder.cronSchedule(getCronExpression())
            .inTimeZone(getTimeZone());
        
    switch(getMisfireInstruction()) {
        case MISFIRE_INSTRUCTION_DO_NOTHING : cb.withMisfireHandlingInstructionDoNothing();
        break;
        case MISFIRE_INSTRUCTION_FIRE_ONCE_NOW : cb.withMisfireHandlingInstructionFireAndProceed();
        break;
    }
    
    return cb;
}
 
Example #5
Source File: CalendarIntervalTriggerPersistenceDelegate.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected TriggerPropertyBundle getTriggerPropertyBundle(SimplePropertiesTriggerProperties props) {

    TimeZone tz = null; // if we use null, that's ok as system default tz will be used
    String tzId = props.getString2();
    if(tzId != null && tzId.trim().length() != 0) // there could be null entries from previously released versions
        tz = TimeZone.getTimeZone(tzId);
    
    ScheduleBuilder<?> sb = CalendarIntervalScheduleBuilder.calendarIntervalSchedule()
        .withInterval(props.getInt1(), IntervalUnit.valueOf(props.getString1()))
        .inTimeZone(tz)
        .preserveHourOfDayAcrossDaylightSavings(props.isBoolean1())
        .skipDayIfHourDoesNotExist(props.isBoolean2());
    
    int timesTriggered = props.getInt2();
    
    String[] statePropertyNames = { "timesTriggered" };
    Object[] statePropertyValues = { timesTriggered };

    return new TriggerPropertyBundle(sb, statePropertyNames, statePropertyValues);
}
 
Example #6
Source File: GlassSchedulerParser.java    From quartz-glass with Apache License 2.0 5 votes vote down vote up
private static ScheduleBuilder<? extends Trigger> parseEveryExpr(String everyExpr) {
    Matcher matcher = everyExprPattern.matcher(everyExpr);
    if (!matcher.matches()) throw new RuntimeException(everyExpr + " is not valid");
    int num = Integer.parseInt(matcher.group(1));
    if (num <= 0) throw new RuntimeException(everyExpr + " is not valid");
    char unit = matcher.group(2).charAt(0);
    TimeUnit timeUnit = TimeUnit.MILLISECONDS;
    switch (unit) {
        case 'h':
        case 'H':
            timeUnit = TimeUnit.HOURS;
            break;
        case 'm':
        case 'M':
            timeUnit = TimeUnit.MINUTES;
            break;
        case 's':
        case 'S':
            timeUnit = TimeUnit.SECONDS;
            break;
        default:
    }

    return SimpleScheduleBuilder.simpleSchedule()
            .withIntervalInSeconds((int) timeUnit.toSeconds(num))
            .repeatForever();
}
 
Example #7
Source File: GlassSchedulerParser.java    From quartz-glass with Apache License 2.0 5 votes vote down vote up
private static ScheduleBuilder<? extends Trigger> parseAtExpr(String atExpr) {
    Matcher matcher = atExprPattern.matcher(atExpr);
    if (!matcher.matches()) throw new RuntimeException(atExpr + " is not valid");

    if (matcher.group(1).equals("??")) {
        return CronScheduleBuilder.cronSchedule("0 " + matcher.group(2) + " * * * ?");
    }

    DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm");
    DateTime dateTime = formatter.parseDateTime(matcher.group().trim());

    return CronScheduleBuilder.dailyAtHourAndMinute(dateTime.getHourOfDay(),
            dateTime.getMinuteOfHour());
}
 
Example #8
Source File: DefaultDataManager.java    From onedev with MIT License 5 votes vote down vote up
@Override
public void scheduleBackup(BackupSetting backupSetting) {
	if (backupTaskId != null)
		taskScheduler.unschedule(backupTaskId);
	if (backupSetting != null) { 
		backupTaskId = taskScheduler.schedule(new SchedulableTask() {

			@Override
			public void execute() {
				File tempDir = FileUtils.createTempDir("backup");
				try {
					File backupDir = new File(Bootstrap.getSiteDir(), Upgrade.DB_BACKUP_DIR);
					FileUtils.createDir(backupDir);
					persistManager.exportData(tempDir);
					File backupFile = new File(backupDir, 
							DateTimeFormat.forPattern(Upgrade.BACKUP_DATETIME_FORMAT).print(new DateTime()) + ".zip");
					ZipUtils.zip(tempDir, backupFile);
				} catch (Exception e) {
					notifyBackupError(e);
					throw ExceptionUtils.unchecked(e);
				} finally {
					FileUtils.deleteDir(tempDir);
				}
			}

			@Override
			public ScheduleBuilder<?> getScheduleBuilder() {
				return CronScheduleBuilder.cronSchedule(backupSetting.getSchedule());
			}
			
		});
	}
}
 
Example #9
Source File: DefaultTaskScheduler.java    From onedev with MIT License 5 votes vote down vote up
@Override
public synchronized String schedule(SchedulableTask task) {		
	Subject subject = SecurityUtils.getSubject();
	SchedulableTask subjectAwareTask = new SchedulableTask() {
		
		@Override
		public ScheduleBuilder<?> getScheduleBuilder() {
			return task.getScheduleBuilder();
		}
		
		@Override
		public void execute() {
			ThreadContext.bind(subject);
			task.execute();
		}
	};
       try {
		JobDetail job = JobBuilder.newJob(HelperTask.class)
				.withIdentity(UUID.randomUUID().toString())
				.build();
		Trigger trigger = TriggerBuilder.newTrigger()
				.withIdentity(UUID.randomUUID().toString())
				.withSchedule(subjectAwareTask.getScheduleBuilder())
				.forJob(job)
				.build();
		trigger.getJobDataMap().put("task", subjectAwareTask);
		quartz.scheduleJob(job, trigger);
		return job.getKey().getName();
	} catch (SchedulerException e) {
		throw new RuntimeException(e);
	}
}
 
Example #10
Source File: TriggerPersistenceDelegate.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public TriggerPropertyBundle(ScheduleBuilder<?> sb, String[] statePropertyNames, Object[] statePropertyValues) {
    this.sb = sb;
    this.statePropertyNames = statePropertyNames;
    this.statePropertyValues = statePropertyValues;
}
 
Example #11
Source File: GlassSchedulerParser.java    From quartz-glass with Apache License 2.0 4 votes vote down vote up
public ScheduleBuilder<? extends Trigger> getScheduleBuilder() {
    return scheduleBuilder;
}
 
Example #12
Source File: TriggerPersistenceDelegate.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ScheduleBuilder<?> getScheduleBuilder() {
    return sb;
}
 
Example #13
Source File: DefaultWebSocketManager.java    From onedev with MIT License 4 votes vote down vote up
@Listen
public void on(SystemStarted event) {
	keepAliveTaskId = taskScheduler.schedule(new SchedulableTask() {
		
		@Override
		public ScheduleBuilder<?> getScheduleBuilder() {
			return SimpleScheduleBuilder.repeatSecondlyForever((int)webSocketPolicy.getIdleTimeout()/2000);
		}
		
		@Override
		public void execute() {
			for (IWebSocketConnection connection: connectionRegistry.getConnections(application)) {
				if (connection.isOpen()) {
					try {
						connection.sendMessage(WebSocketManager.KEEP_ALIVE);
					} catch (Exception e) {
						logger.error("Error sending websocket keep alive message", e);
					}
				}
			}
		}
		
	});
	notifiedObservableCleanupTaskId = taskScheduler.schedule(new SchedulableTask() {
		
		private static final int TOLERATE_SECONDS = 10;
		
		@Override
		public ScheduleBuilder<?> getScheduleBuilder() {
			return SimpleScheduleBuilder.repeatSecondlyForever(TOLERATE_SECONDS);
		}
		
		@Override
		public void execute() {
			Date threshold = new DateTime().minusSeconds(TOLERATE_SECONDS).toDate();
			for (Iterator<Map.Entry<String, Date>> it = notifiedObservables.entrySet().iterator(); it.hasNext();) {
				if (it.next().getValue().before(threshold))
					it.remove();
			}
		}
		
	});
}
 
Example #14
Source File: MyTriggerImpl.java    From blog with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public ScheduleBuilder getScheduleBuilder() {
	// TODO Auto-generated method stub
	return null;
}
 
Example #15
Source File: MyTrigger.java    From blog with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public ScheduleBuilder getScheduleBuilder() {
	// TODO Auto-generated method stub
	return null;
}
 
Example #16
Source File: DefaultAttachmentStorageManager.java    From onedev with MIT License 4 votes vote down vote up
@Override
public ScheduleBuilder<?> getScheduleBuilder() {
	return CronScheduleBuilder.dailyAtHourAndMinute(0, 0);
}
 
Example #17
Source File: DefaultIssueChangeManager.java    From onedev with MIT License 4 votes vote down vote up
@Override
public ScheduleBuilder<?> getScheduleBuilder() {
	return CronScheduleBuilder.dailyAtHourAndMinute(1, 0);
}
 
Example #18
Source File: DefaultBuildManager.java    From onedev with MIT License 4 votes vote down vote up
@Override
public ScheduleBuilder<?> getScheduleBuilder() {
	return CronScheduleBuilder.dailyAtHourAndMinute(0, 0);
}
 
Example #19
Source File: DefaultProjectManager.java    From onedev with MIT License 4 votes vote down vote up
@Override
public ScheduleBuilder<?> getScheduleBuilder() {
	return SimpleScheduleBuilder.repeatMinutelyForever();
}
 
Example #20
Source File: TaskButton.java    From onedev with MIT License 4 votes vote down vote up
@Override
public ScheduleBuilder<?> getScheduleBuilder() {
	return SimpleScheduleBuilder.repeatHourlyForever();
}
 
Example #21
Source File: SchedulableTask.java    From onedev with MIT License votes vote down vote up
ScheduleBuilder<?> getScheduleBuilder(); 
Example #22
Source File: AbstractTrigger.java    From lams with GNU General Public License v2.0 votes vote down vote up
public abstract ScheduleBuilder<T> getScheduleBuilder();