use of javax.ejb.ScheduleExpression in project wildfly by wildfly.
the class CalendarTimerServiceBean method createTimer.
public TimerHandle createTimer() {
ScheduleExpression expression = new ScheduleExpression();
expression.second("*");
expression.minute("*");
expression.hour("*");
expression.dayOfMonth("*");
expression.year("*");
return timerService.createCalendarTimer(expression).getHandle();
}
use of javax.ejb.ScheduleExpression in project wildfly by wildfly.
the class CalendarTimerBean method createTimer.
@Override
public void createTimer() {
ScheduleExpression scheduleExpression = new ScheduleExpression();
scheduleExpression.second(getSeconds());
scheduleExpression.hour("*");
scheduleExpression.minute("*");
final TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(persistent);
timerConfig.setInfo(info);
super.timerService.createCalendarTimer(scheduleExpression, timerConfig);
}
use of javax.ejb.ScheduleExpression in project wildfly by wildfly.
the class TimerMethodMergingProcessor method parseScheduleMethods.
private void parseScheduleMethods(final EnterpriseBeanMetaData beanMetaData, final EJBComponentDescription sessionBean, final Class<?> componentClass, final DeploymentReflectionIndex deploymentReflectionIndex) throws DeploymentUnitProcessingException {
if (beanMetaData instanceof IScheduleTarget) {
IScheduleTarget md = (IScheduleTarget) beanMetaData;
if (md.getTimers() != null) {
for (final TimerMetaData timer : md.getTimers()) {
AutoTimer autoTimer = new AutoTimer();
autoTimer.getTimerConfig().setInfo(timer.getInfo());
autoTimer.getTimerConfig().setPersistent(timer.isPersistent());
final ScheduleExpression scheduleExpression = autoTimer.getScheduleExpression();
final ScheduleMetaData schedule = timer.getSchedule();
if (schedule != null) {
scheduleExpression.dayOfMonth(schedule.getDayOfMonth());
scheduleExpression.dayOfWeek(schedule.getDayOfWeek());
scheduleExpression.hour(schedule.getHour());
scheduleExpression.minute(schedule.getMinute());
scheduleExpression.month(schedule.getMonth());
scheduleExpression.second(schedule.getSecond());
scheduleExpression.year(schedule.getYear());
}
if (timer.getEnd() != null) {
scheduleExpression.end(timer.getEnd().getTime());
}
if (timer.getStart() != null) {
scheduleExpression.start(timer.getStart().getTime());
}
scheduleExpression.timezone(timer.getTimezone());
sessionBean.addScheduleMethod(MethodResolutionUtils.resolveMethod(timer.getTimeoutMethod(), componentClass, deploymentReflectionIndex), autoTimer);
}
}
}
}
use of javax.ejb.ScheduleExpression in project wildfly by wildfly.
the class CalendarTimerEntity method getScheduleExpression.
public ScheduleExpression getScheduleExpression() {
if (this.scheduleExpression == null) {
this.scheduleExpression = new ScheduleExpression();
this.scheduleExpression.second(this.scheduleExprSecond).minute(this.scheduleExprMinute).hour(this.scheduleExprHour).dayOfWeek(this.scheduleExprDayOfWeek).dayOfMonth(this.scheduleExprDayOfMonth).month(this.scheduleExprMonth).year(this.scheduleExprYear).timezone(this.scheduleExprTimezone).start(this.scheduleExprStartDate).end(this.scheduleExprEndDate);
}
return scheduleExpression;
}
use of javax.ejb.ScheduleExpression in project wildfly by wildfly.
the class CalendarBasedTimeoutWithDifferentTimeZoneTestCase method testScheduledTimezoneDifferentThanCurrentSystem.
@Test
public void testScheduledTimezoneDifferentThanCurrentSystem() {
// This tests replicates an automatic timer below being deployed in a system whose default timezone is America/Chicago
// @Schedule(persistent = false, timezone = "America/New_York", dayOfMonth = "*", dayOfWeek = "*", month = "*", hour =
// "2", minute = "*", second = "0", year = "*")
// The schedule for the timer is to fire every minute where the hour is 2 in the America/New_York timezone
ScheduleExpression sch = new ScheduleExpression();
sch.timezone("America/New_York");
sch.dayOfMonth("*");
sch.dayOfWeek("*");
sch.month("*");
sch.hour("2");
sch.minute("*");
sch.second("0");
sch.year("*");
CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(sch);
Calendar firstTimeout = calendarTimeout.getFirstTimeout();
Assert.assertNotNull("first timeout is null", firstTimeout);
logger.info("First timeout is " + firstTimeout.getTime());
// currentCal sets up a dummy time in the future, the timezone is America/Chicago in which this imaginary system is
// running
TimeZone currentTimezone = TimeZone.getTimeZone("America/Chicago");
Calendar currentCal = new GregorianCalendar(currentTimezone);
currentCal.set(Calendar.YEAR, 2014);
currentCal.set(Calendar.MONTH, 1);
currentCal.set(Calendar.DATE, 8);
currentCal.set(Calendar.HOUR_OF_DAY, 1);
currentCal.set(Calendar.MINUTE, 1);
currentCal.set(Calendar.SECOND, 1);
currentCal.set(Calendar.MILLISECOND, 0);
// https://issues.jboss.org/browse/WFLY-2840 - @Schedule EJB Timer not using timezone when calcualting next timeout
// Next test WFLY-2840, by calling getNextTimeout with the dummy time above, the expected result is for the timer to
// fire at 1:02:00
// If the bug is not fixed it will return 2:00:00
Calendar nextTimeout = calendarTimeout.getNextTimeout(currentCal);
logger.info("Next timeout is " + nextTimeout.getTime());
Calendar expectedCal = new GregorianCalendar(currentTimezone);
expectedCal.set(Calendar.YEAR, 2014);
expectedCal.set(Calendar.MONTH, 1);
expectedCal.set(Calendar.DATE, 8);
expectedCal.set(Calendar.HOUR_OF_DAY, 1);
expectedCal.set(Calendar.MINUTE, 2);
expectedCal.set(Calendar.SECOND, 0);
expectedCal.set(Calendar.MILLISECOND, 0);
Assert.assertEquals("[WFLY-2840] Next timeout should be: " + expectedCal.getTime(), expectedCal.getTime(), nextTimeout.getTime());
}
Aggregations