Search in sources :

Example 56 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project tomee by apache.

the class MethodScheduleBuilder method addSchedulesToMethod.

private void addSchedulesToMethod(final MethodContext methodContext, final MethodScheduleInfo info) {
    if (methodContext == null) {
        return;
    }
    for (final ScheduleInfo scheduleInfo : info.schedules) {
        final ScheduleExpression expr = new ScheduleExpression();
        expr.second(scheduleInfo.second == null ? "0" : scheduleInfo.second);
        expr.minute(scheduleInfo.minute == null ? "0" : scheduleInfo.minute);
        expr.hour(scheduleInfo.hour == null ? "0" : scheduleInfo.hour);
        expr.dayOfWeek(scheduleInfo.dayOfWeek == null ? "*" : scheduleInfo.dayOfWeek);
        expr.dayOfMonth(scheduleInfo.dayOfMonth == null ? "*" : scheduleInfo.dayOfMonth);
        expr.month(scheduleInfo.month == null ? "*" : scheduleInfo.month);
        expr.year(scheduleInfo.year == null ? "*" : scheduleInfo.year);
        expr.timezone(scheduleInfo.timezone);
        expr.start(scheduleInfo.start);
        expr.end(scheduleInfo.end);
        final TimerConfig config = new TimerConfig();
        config.setInfo(scheduleInfo.info);
        config.setPersistent(scheduleInfo.persistent);
        methodContext.getSchedules().add(new ScheduleData(config, expr));
    }
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) ScheduleData(org.apache.openejb.core.timer.ScheduleData) TimerConfig(javax.ejb.TimerConfig)

Example 57 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project tomee by apache.

the class EJBCronTriggerTest method testListDayOfWeekB.

@Test(timeout = 5000)
public void testListDayOfWeekB() throws ParseException {
    final String[] dayOfWeeks = { "2,3,4,5", "3,2,4,5", "2,3,4,5,2" };
    for (final String dayOfWeek : dayOfWeeks) {
        final ScheduleExpression expr = new ScheduleExpression().dayOfWeek(dayOfWeek).hour(23).minute(1).second(59).start(new Date(0));
        final EJBCronTrigger trigger = new EJBCronTrigger(expr);
        assertEquals(new GregorianCalendar(2010, 5, 29, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 5, 30, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 1, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 3, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 6, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 2, 23, 2, 0).getTime()));
    }
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 58 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project tomee by apache.

the class EJBCronTriggerTest method testSecond.

@Test(timeout = 5000)
public void testSecond() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().hour("*").minute("*").second(5).start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 1, 5, 0, 0, 5).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 1, 5, 0, 0, 4).getTime()));
    assertEquals(new GregorianCalendar(2011, 1, 5, 0, 1, 5).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 1, 5, 0, 0, 6).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 59 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project tomee by apache.

the class EJBCronTriggerTest method testIncrementsB.

@Test(timeout = 1000)
public void testIncrementsB() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year(2011).month(5).dayOfMonth(5).hour("23").minute("25/35").start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 4, 5, 23, 25, 0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 5, 22, 0, 0).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 60 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project tomee by apache.

the class EJBCronTriggerTest method testCompoundListDayOfMonth.

@Test(timeout = 5000)
public void testCompoundListDayOfMonth() throws ParseException {
    final String[] dayOfMonthsA = { "5,6-8,10,24", "5,10,24,6-8", "5,10,24,6-8,7" };
    for (final String dayOfMonth : dayOfMonthsA) {
        final ScheduleExpression expr = new ScheduleExpression().dayOfMonth(dayOfMonth).hour(23).minute(1).second(59).start(new Date(0));
        final EJBCronTrigger trigger = new EJBCronTrigger(expr);
        assertEquals(new GregorianCalendar(2010, 6, 5, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 6, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 5, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 8, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 7, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 10, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 8, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 24, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 24, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 7, 5, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 24, 23, 3, 0).getTime()));
    }
    final String[] dayOfMonthsB = { "5,6-8,10,24", "5,10,24,6-8", "5,10,24,6-8,7", "5,10,7,24,6-8" };
    for (final String dayOfMonth : dayOfMonthsB) {
        final ScheduleExpression expr = new ScheduleExpression().dayOfMonth(dayOfMonth).hour(23).minute(1).second(59).start(new Date(0));
        final EJBCronTrigger trigger = new EJBCronTrigger(expr);
        assertEquals(new GregorianCalendar(2010, 6, 5, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 6, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 5, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 7, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 6, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 8, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 8, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 10, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 8, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 10, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 10, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 24, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 10, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 7, 5, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 24, 23, 3, 0).getTime()));
    }
    final String[] dayOfMonthsC = { "5, 10,26,25-3", "5,25-3,10,26", "5,25-LAST,1-3,26,10", "5,5,10,10,25-26,26-3", "5,5,10,10,25-26,26-LAST, 1-3" };
    for (final String dayOfMonth : dayOfMonthsC) {
        final ScheduleExpression expr = new ScheduleExpression().dayOfMonth(dayOfMonth).hour(23).minute(1).second(59).start(new Date(0));
        final EJBCronTrigger trigger = new EJBCronTrigger(expr);
        assertEquals(new GregorianCalendar(2010, 5, 29, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 1, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 30, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 5, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 5, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 10, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 5, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 10, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 10, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 25, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 10, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2010, 6, 27, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 26, 23, 3, 0).getTime()));
        //Test Leap year
        assertEquals(new GregorianCalendar(2012, 0, 29, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 0, 29, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2012, 1, 1, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 0, 31, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2012, 1, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 1, 1, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2012, 1, 5, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 1, 5, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2012, 1, 10, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 1, 5, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2012, 1, 10, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 1, 10, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2012, 1, 25, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 1, 10, 23, 2, 0).getTime()));
        assertEquals(new GregorianCalendar(2012, 1, 27, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 1, 26, 23, 3, 0).getTime()));
        assertEquals(new GregorianCalendar(2012, 1, 28, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 1, 28, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2012, 1, 29, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 1, 28, 23, 3, 0).getTime()));
        assertEquals(new GregorianCalendar(2012, 1, 29, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 1, 29, 23, 0, 0).getTime()));
        assertEquals(new GregorianCalendar(2012, 2, 1, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2012, 1, 29, 23, 3, 0).getTime()));
    }
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) 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