Search in sources :

Example 41 with ScheduleExpression

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

the class TimerServiceImpl method copy.

private ScheduleExpression copy(final ScheduleExpression scheduleExpression) {
    final ScheduleExpression scheduleExpressionCopy = new ScheduleExpression();
    scheduleExpressionCopy.year(scheduleExpression.getYear());
    scheduleExpressionCopy.month(scheduleExpression.getMonth());
    scheduleExpressionCopy.dayOfMonth(scheduleExpression.getDayOfMonth());
    scheduleExpressionCopy.dayOfWeek(scheduleExpression.getDayOfWeek());
    scheduleExpressionCopy.hour(scheduleExpression.getHour());
    scheduleExpressionCopy.minute(scheduleExpression.getMinute());
    scheduleExpressionCopy.second(scheduleExpression.getSecond());
    scheduleExpressionCopy.start(scheduleExpression.getStart());
    scheduleExpressionCopy.end(scheduleExpression.getEnd());
    scheduleExpressionCopy.timezone(scheduleExpression.getTimezone());
    return scheduleExpressionCopy;
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression)

Example 42 with ScheduleExpression

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

the class EJBCronTriggerPersistenceDelegate method loadExtendedTriggerProperties.

@Override
public TriggerPropertyBundle loadExtendedTriggerProperties(final Connection conn, final TriggerKey triggerKey) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        ps = conn.prepareStatement(Util.rtp(SELECT_CRON_TRIGGER, tablePrefix, schedNameLiteral));
        ps.setString(1, triggerKey.getName());
        ps.setString(2, triggerKey.getGroup());
        rs = ps.executeQuery();
        if (rs.next()) {
            final String cronExpr = rs.getString(COL_CRON_EXPRESSION);
            final String timeZoneId = rs.getString(COL_TIME_ZONE_ID);
            final String[] parts = cronExpr.split(EJBCronTrigger.DELIMITER);
            try {
                final EJBCronTrigger cb = new EJBCronTrigger(new ScheduleExpression().year(parts[0]).month(parts[1]).dayOfMonth(parts[2]).dayOfWeek(parts[3]).hour(parts[4]).minute(parts[5]).second(parts[6]).timezone(timeZoneId));
                return new TriggerPropertyBundle(new EJBCronTriggerSceduleBuilder(cb), null, null);
            } catch (final EJBCronTrigger.ParseException e) {
                throw new IllegalStateException("Can't build the Trigger with key: '" + triggerKey + "' and statement: " + Util.rtp(SELECT_CRON_TRIGGER, tablePrefix, schedNameLiteral));
            }
        }
        throw new IllegalStateException("No record found for selection of Trigger with key: '" + triggerKey + "' and statement: " + Util.rtp(SELECT_CRON_TRIGGER, tablePrefix, schedNameLiteral));
    } finally {
        Util.closeResultSet(rs);
        Util.closeStatement(ps);
    }
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 43 with ScheduleExpression

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

the class CalendarTimerData method readObject.

private void readObject(final ObjectInputStream in) throws IOException {
    super.doReadObject(in);
    autoCreated = in.readBoolean();
    try {
        scheduleExpression = ScheduleExpression.class.cast(in.readObject());
    } catch (final ClassNotFoundException e) {
        throw new IOException(e);
    }
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) IOException(java.io.IOException)

Example 44 with ScheduleExpression

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

the class FarmerBrown method construct.

@PostConstruct
private void construct() {
    final TimerConfig plantTheCorn = new TimerConfig("plantTheCorn", false);
    timerService.createCalendarTimer(new ScheduleExpression().month(5).dayOfMonth("20-Last").minute(0).hour(8), plantTheCorn);
    timerService.createCalendarTimer(new ScheduleExpression().month(6).dayOfMonth("1-10").minute(0).hour(8), plantTheCorn);
    final TimerConfig harvestTheCorn = new TimerConfig("harvestTheCorn", false);
    timerService.createCalendarTimer(new ScheduleExpression().month(9).dayOfMonth("20-Last").minute(0).hour(8), harvestTheCorn);
    timerService.createCalendarTimer(new ScheduleExpression().month(10).dayOfMonth("1-10").minute(0).hour(8), harvestTheCorn);
    final TimerConfig checkOnTheDaughters = new TimerConfig("checkOnTheDaughters", false);
    timerService.createCalendarTimer(new ScheduleExpression().second("*").minute("*").hour("*"), checkOnTheDaughters);
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) TimerConfig(javax.ejb.TimerConfig) PostConstruct(javax.annotation.PostConstruct)

Example 45 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project wildfly by wildfly.

the class TimerAttributeDefinition method addSchedule.

private static void addSchedule(Timer timer, ModelNode timerNode, final String componentName) {
    try {
        final ModelNode schedNode = timerNode.get(SCHEDULE);
        ScheduleExpression sched = timer.getSchedule();
        addScheduleDetailString(schedNode, sched.getYear(), YEAR);
        addScheduleDetailString(schedNode, sched.getMonth(), MONTH);
        addScheduleDetailString(schedNode, sched.getDayOfMonth(), DAY_OF_MONTH);
        addScheduleDetailString(schedNode, sched.getDayOfWeek(), DAY_OF_WEEK);
        addScheduleDetailString(schedNode, sched.getHour(), HOUR);
        addScheduleDetailString(schedNode, sched.getMinute(), MINUTE);
        addScheduleDetailString(schedNode, sched.getSecond(), SECOND);
        addScheduleDetailString(schedNode, sched.getTimezone(), TIMEZONE);
        addScheduleDetailDate(schedNode, sched.getStart(), START);
        addScheduleDetailDate(schedNode, sched.getEnd(), END);
    } catch (IllegalStateException e) {
    // ignore
    } catch (NoSuchObjectLocalException e) {
    // ignore
    } catch (EJBException e) {
        logTimerFailure(componentName, e);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) ScheduleExpression(javax.ejb.ScheduleExpression) ModelNode(org.jboss.dmr.ModelNode) EJBException(javax.ejb.EJBException)

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