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


Java TriggerContext类代码示例

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


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

示例1: nextExecutionTime

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
/**
 * Determine the next execution time according to the given trigger context.
 * <p>Next execution times are calculated based on the
 * {@linkplain TriggerContext#lastCompletionTime completion time} of the
 * previous execution; therefore, overlapping executions won't occur.
 */
@Override
public Date nextExecutionTime(TriggerContext triggerContext) {
	Date date = triggerContext.lastCompletionTime();
	if (date != null) {
		Date scheduled = triggerContext.lastScheduledExecutionTime();
		if (scheduled != null && date.before(scheduled)) {
			// Previous task apparently executed too early...
			// Let's simply use the last calculated execution time then,
			// in order to prevent accidental re-fires in the same second.
			date = scheduled;
		}
	}
	else {
		date = new Date();
	}
	return this.sequenceGenerator.next(date);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:CronTrigger.java

示例2: testIncrementHour

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testIncrementHour() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 * * * *", timeZone);
	calendar.set(Calendar.MONTH, 9);
	calendar.set(Calendar.DAY_OF_MONTH, 30);
	calendar.set(Calendar.HOUR_OF_DAY, 11);
	calendar.set(Calendar.MINUTE, 1);
	calendar.set(Calendar.SECOND, 0);
	Date date = calendar.getTime();
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.HOUR_OF_DAY, 12);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.set(Calendar.HOUR_OF_DAY, 13);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:CronTriggerTests.java

示例3: testIncrementHourAndRollover

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testIncrementHourAndRollover() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 * * * *", timeZone);
	calendar.set(Calendar.MONTH, 9);
	calendar.set(Calendar.DAY_OF_MONTH, 10);
	calendar.set(Calendar.HOUR_OF_DAY, 23);
	calendar.set(Calendar.MINUTE, 1);
	calendar.set(Calendar.SECOND, 0);
	Date date = calendar.getTime();
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.DAY_OF_MONTH, 11);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.set(Calendar.HOUR_OF_DAY, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:CronTriggerTests.java

示例4: testIncrementDayOfMonth

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testIncrementDayOfMonth() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone);
	calendar.set(Calendar.DAY_OF_MONTH, 1);
	Date date = calendar.getTime();
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	assertEquals(2, calendar.get(Calendar.DAY_OF_MONTH));
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
	assertEquals(3, calendar.get(Calendar.DAY_OF_MONTH));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:CronTriggerTests.java

示例5: testDailyTriggerInShortMonth

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testDailyTriggerInShortMonth() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone);
	calendar.set(Calendar.MONTH, 8); // September: 30 days
	calendar.set(Calendar.DAY_OF_MONTH, 30);
	Date date = calendar.getTime();
	calendar.set(Calendar.MONTH, 9); // October
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	calendar.set(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.set(Calendar.DAY_OF_MONTH, 2);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:CronTriggerTests.java

示例6: testDailyTriggerInLongMonth

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testDailyTriggerInLongMonth() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone);
	calendar.set(Calendar.MONTH, 7); // August: 31 days and not a daylight saving boundary
	calendar.set(Calendar.DAY_OF_MONTH, 30);
	Date date = calendar.getTime();
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	calendar.set(Calendar.DAY_OF_MONTH, 31);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.set(Calendar.MONTH, 8); // September
	calendar.set(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:CronTriggerTests.java

示例7: testDailyTriggerOnDaylightSavingBoundary

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testDailyTriggerOnDaylightSavingBoundary() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone);
	calendar.set(Calendar.MONTH, 9); // October: 31 days and a daylight saving boundary in CET
	calendar.set(Calendar.DAY_OF_MONTH, 30);
	Date date = calendar.getTime();
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	calendar.set(Calendar.DAY_OF_MONTH, 31);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.set(Calendar.MONTH, 10); // November
	calendar.set(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:CronTriggerTests.java

示例8: testIncrementMonth

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testIncrementMonth() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 0 1 * *", timeZone);
	calendar.set(Calendar.MONTH, 9);
	calendar.set(Calendar.DAY_OF_MONTH, 30);
	Date date = calendar.getTime();
	calendar.set(Calendar.DAY_OF_MONTH, 1);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	calendar.set(Calendar.MONTH, 10);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.set(Calendar.MONTH, 11);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:CronTriggerTests.java

示例9: testIncrementMonthAndRollover

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testIncrementMonthAndRollover() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 0 1 * *", timeZone);
	calendar.set(Calendar.MONTH, 11);
	calendar.set(Calendar.DAY_OF_MONTH, 31);
	calendar.set(Calendar.YEAR, 2010);
	Date date = calendar.getTime();
	calendar.set(Calendar.DAY_OF_MONTH, 1);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	calendar.set(Calendar.MONTH, 0);
	calendar.set(Calendar.YEAR, 2011);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.set(Calendar.MONTH, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:CronTriggerTests.java

示例10: testSpecificMinuteHour

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testSpecificMinuteHour() throws Exception {
	CronTrigger trigger = new CronTrigger("* 5 10 * * *", timeZone);
	calendar.set(Calendar.MINUTE, 4);
	calendar.set(Calendar.HOUR_OF_DAY, 9);
	Date date = calendar.getTime();
	calendar.add(Calendar.MINUTE, 1);
	calendar.add(Calendar.HOUR_OF_DAY, 1);
	calendar.set(Calendar.SECOND, 0);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	// next trigger is in one second because second is wildcard
	calendar.add(Calendar.SECOND, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:CronTriggerTests.java

示例11: testSpecificDayOfMonthSecond

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testSpecificDayOfMonthSecond() throws Exception {
	CronTrigger trigger = new CronTrigger("55 * * 3 * *", timeZone);
	calendar.set(Calendar.DAY_OF_MONTH, 2);
	calendar.set(Calendar.SECOND, 54);
	Date date = calendar.getTime();
	TriggerContext context1 = getTriggerContext(date);
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 55);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.add(Calendar.MINUTE, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:CronTriggerTests.java

示例12: testSpecificDate

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testSpecificDate() throws Exception {
	CronTrigger trigger = new CronTrigger("* * * 3 11 *", timeZone);
	calendar.set(Calendar.DAY_OF_MONTH, 2);
	calendar.set(Calendar.MONTH, 9);
	Date date = calendar.getTime();
	TriggerContext context1 = getTriggerContext(date);
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MONTH, 10); // 10=November
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.add(Calendar.SECOND, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:CronTriggerTests.java

示例13: testLeapYearSpecificDate

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testLeapYearSpecificDate() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 0 29 2 *", timeZone);
	calendar.set(Calendar.YEAR, 2007);
	calendar.set(Calendar.DAY_OF_MONTH, 10);
	calendar.set(Calendar.MONTH, 1); // 2=February
	Date date = calendar.getTime();
	TriggerContext context1 = getTriggerContext(date);
	calendar.set(Calendar.YEAR, 2008);
	calendar.set(Calendar.DAY_OF_MONTH, 29);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	calendar.add(Calendar.YEAR, 4);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:CronTriggerTests.java

示例14: testWeekDaySequence

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testWeekDaySequence() throws Exception {
	CronTrigger trigger = new CronTrigger("0 0 7 ? * MON-FRI", timeZone);
	// This is a Saturday
	calendar.set(2009, 8, 26);
	Date date = calendar.getTime();
	// 7 am is the trigger time
	calendar.set(Calendar.HOUR_OF_DAY, 7);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	// Add two days because we start on Saturday
	calendar.add(Calendar.DAY_OF_MONTH, 2);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	// Next day is a week day so add one
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
	calendar.add(Calendar.DAY_OF_MONTH, 1);
	TriggerContext context3 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context3));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:CronTriggerTests.java

示例15: testMonthSequence

import org.springframework.scheduling.TriggerContext; //导入依赖的package包/类
@Test
public void testMonthSequence() throws Exception {
	CronTrigger trigger = new CronTrigger("0 30 23 30 1/3 ?", timeZone);
	calendar.set(2010, 11, 30);
	Date date = calendar.getTime();
	// set expected next trigger time
	calendar.set(Calendar.HOUR_OF_DAY, 23);
	calendar.set(Calendar.MINUTE, 30);
	calendar.set(Calendar.SECOND, 0);
	calendar.add(Calendar.MONTH, 1);
	TriggerContext context1 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
	// Next trigger is 3 months latter
	calendar.add(Calendar.MONTH, 3);
	TriggerContext context2 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context2));
	// Next trigger is 3 months latter
	calendar.add(Calendar.MONTH, 3);
	TriggerContext context3 = getTriggerContext(date);
	assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context3));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:CronTriggerTests.java


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