Search in sources :

Example 1 with ScheduleExpression

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();
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression)

Example 2 with ScheduleExpression

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);
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) TimerConfig(javax.ejb.TimerConfig)

Example 3 with ScheduleExpression

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);
            }
        }
    }
}
Also used : AutoTimer(org.jboss.as.ejb3.timerservice.AutoTimer) ScheduleExpression(javax.ejb.ScheduleExpression) TimerMetaData(org.jboss.metadata.ejb.spec.TimerMetaData) IScheduleTarget(org.jboss.metadata.common.ejb.IScheduleTarget) ScheduleMetaData(org.jboss.metadata.ejb.spec.ScheduleMetaData)

Example 4 with ScheduleExpression

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;
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression)

Example 5 with 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());
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) CalendarBasedTimeout(org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout) TimeZone(java.util.TimeZone) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Aggregations

ScheduleExpression (javax.ejb.ScheduleExpression)75 GregorianCalendar (java.util.GregorianCalendar)60 Test (org.junit.Test)52 EJBCronTrigger (org.apache.openejb.core.timer.EJBCronTrigger)44 Date (java.util.Date)34 Calendar (java.util.Calendar)21 CalendarBasedTimeout (org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout)17 TimerConfig (javax.ejb.TimerConfig)4 TimeZone (java.util.TimeZone)3 ArrayList (java.util.ArrayList)2 ParseException (org.apache.openejb.core.timer.EJBCronTrigger.ParseException)2 IOException (java.io.IOException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 PostConstruct (javax.annotation.PostConstruct)1 EJBException (javax.ejb.EJBException)1 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)1 ScheduleData (org.apache.openejb.core.timer.ScheduleData)1 AutoTimer (org.jboss.as.ejb3.timerservice.AutoTimer)1 ModelNode (org.jboss.dmr.ModelNode)1