Search in sources :

Example 1 with CalendarTimer

use of org.jboss.as.ejb3.timerservice.CalendarTimer in project wildfly by wildfly.

the class CalendarTimerTask method invokeBeanMethod.

protected void invokeBeanMethod(TimerImpl timer) throws Exception {
    CalendarTimer calendarTimer = (CalendarTimer) timer;
    // finally invoke the timeout method through the invoker
    if (calendarTimer.isAutoTimer()) {
        TimedObjectInvoker invoker = this.timerService.getInvoker();
        // call the timeout method
        invoker.callTimeout(calendarTimer, calendarTimer.getTimeoutMethod());
    } else {
        this.timerService.getInvoker().callTimeout(calendarTimer);
    }
}
Also used : TimedObjectInvoker(org.jboss.as.ejb3.timerservice.spi.TimedObjectInvoker)

Example 2 with CalendarTimer

use of org.jboss.as.ejb3.timerservice.CalendarTimer in project wildfly by wildfly.

the class TimerServiceImpl method restoreTimers.

/**
     * Restores persisted timers, corresponding to this timerservice, which are eligible for any new timeouts.
     * <p>
     * This includes timers whose {@link TimerState} is <b>neither</b> of the following:
     * <ul>
     * <li>{@link TimerState#CANCELED}</li>
     * <li>{@link TimerState#EXPIRED}</li>
     * </ul>
     * </p>
     * <p>
     * All such restored timers will be schedule for their next timeouts.
     * </p>
     *
     * @param autoTimers
     */
public void restoreTimers(final List<ScheduleTimer> autoTimers) {
    // get the persisted timers which are considered active
    List<TimerImpl> restorableTimers = this.getActivePersistentTimers();
    //timers are removed from the list as they are loaded
    final List<ScheduleTimer> newAutoTimers = new LinkedList<ScheduleTimer>(autoTimers);
    if (EJB3_TIMER_LOGGER.isDebugEnabled()) {
        EJB3_TIMER_LOGGER.debug("Found " + restorableTimers.size() + " active persistentTimers for timedObjectId: " + getInvoker().getTimedObjectId());
    }
    // and scheduling the timer task
    for (final TimerImpl activeTimer : restorableTimers) {
        if (activeTimer.isAutoTimer()) {
            CalendarTimer calendarTimer = (CalendarTimer) activeTimer;
            boolean found = false;
            //so we know we have an auto timer. We need to try and match it up with the auto timers.
            ListIterator<ScheduleTimer> it = newAutoTimers.listIterator();
            while (it.hasNext()) {
                ScheduleTimer timer = it.next();
                final String methodName = timer.getMethod().getName();
                final String[] params = new String[timer.getMethod().getParameterTypes().length];
                for (int i = 0; i < timer.getMethod().getParameterTypes().length; ++i) {
                    params[i] = timer.getMethod().getParameterTypes()[i].getName();
                }
                if (doesTimeoutMethodMatch(calendarTimer.getTimeoutMethod(), methodName, params)) {
                    // and the timer does not change the persistence
                    if (this.doesScheduleMatch(calendarTimer.getScheduleExpression(), timer.getScheduleExpression()) && timer.getTimerConfig().isPersistent()) {
                        it.remove();
                        found = true;
                        break;
                    }
                }
            }
            if (!found) {
                activeTimer.setTimerState(TimerState.CANCELED);
            } else {
                // ensure state switch to active if was TIMEOUT in the DB
                // if the persistence is shared it must be ensured to not update
                // timers of other nodes in the cluster
                activeTimer.setTimerState(TimerState.ACTIVE);
            }
            this.persistTimer(activeTimer, false);
            if (found) {
                startTimer(activeTimer);
                EJB3_TIMER_LOGGER.debugv("Started timer: {0}", activeTimer);
            }
        } else if (!ineligibleTimerStates.contains(activeTimer.getState())) {
            startTimer(activeTimer);
        }
        EJB3_TIMER_LOGGER.debugv("Started timer: {0}", activeTimer);
    }
    for (ScheduleTimer timer : newAutoTimers) {
        this.loadAutoTimer(timer.getScheduleExpression(), timer.getTimerConfig(), timer.getMethod());
    }
}
Also used : LinkedList(java.util.LinkedList) ScheduleTimer(org.jboss.as.ejb3.timerservice.spi.ScheduleTimer) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint)

Example 3 with CalendarTimer

use of org.jboss.as.ejb3.timerservice.CalendarTimer in project wildfly by wildfly.

the class EjbTimerXmlPersister method writeContent.

@Override
public void writeContent(XMLExtendedStreamWriter writer, List<TimerImpl> timers) throws XMLStreamException {
    writer.writeStartDocument();
    writer.writeStartElement(TIMERS);
    writer.writeDefaultNamespace(EjbTimerXmlParser_1_0.NAMESPACE);
    for (TimerImpl timer : timers) {
        if (timer instanceof CalendarTimer) {
            writeCalendarTimer(writer, (CalendarTimer) timer);
        } else {
            writeTimer(writer, timer);
        }
    }
    writer.writeEndElement();
    writer.writeEndDocument();
}
Also used : CalendarTimer(org.jboss.as.ejb3.timerservice.CalendarTimer) TimerImpl(org.jboss.as.ejb3.timerservice.TimerImpl)

Example 4 with CalendarTimer

use of org.jboss.as.ejb3.timerservice.CalendarTimer in project wildfly by wildfly.

the class DatabaseTimerPersistence method timerFromResult.

private Holder timerFromResult(final ResultSet resultSet, final TimerServiceImpl timerService) throws SQLException {
    boolean calendarTimer = resultSet.getBoolean(24);
    final String nodeName = resultSet.getString(25);
    boolean requiresReset = false;
    TimerImpl.Builder builder = null;
    if (calendarTimer) {
        CalendarTimer.Builder cb = CalendarTimer.builder();
        builder = cb;
        //set calendar timer specifics first
        cb.setScheduleExprSecond(resultSet.getString(10));
        cb.setScheduleExprMinute(resultSet.getString(11));
        cb.setScheduleExprHour(resultSet.getString(12));
        cb.setScheduleExprDayOfWeek(resultSet.getString(13));
        cb.setScheduleExprDayOfMonth(resultSet.getString(14));
        cb.setScheduleExprMonth(resultSet.getString(15));
        cb.setScheduleExprYear(resultSet.getString(16));
        cb.setScheduleExprStartDate(resultSet.getTimestamp(17));
        cb.setScheduleExprEndDate(resultSet.getTimestamp(18));
        cb.setScheduleExprTimezone(resultSet.getString(19));
        cb.setAutoTimer(resultSet.getBoolean(20));
        final String clazz = resultSet.getString(21);
        final String methodName = resultSet.getString(22);
        if (methodName != null) {
            final String paramString = resultSet.getString(23);
            final String[] params = paramString == null || paramString.isEmpty() ? new String[0] : paramString.split(";");
            final Method timeoutMethod = CalendarTimer.getTimeoutMethod(new TimeoutMethod(clazz, methodName, params), timerService.getTimedObjectInvoker().getValue().getClassLoader());
            if (timeoutMethod == null) {
                EjbLogger.EJB3_TIMER_LOGGER.timerReinstatementFailed(resultSet.getString(2), resultSet.getString(1), new NoSuchMethodException());
                return null;
            }
            cb.setTimeoutMethod(timeoutMethod);
        }
    } else {
        builder = TimerImpl.builder();
    }
    builder.setId(resultSet.getString(1));
    builder.setTimedObjectId(resultSet.getString(2));
    builder.setInitialDate(resultSet.getTimestamp(3));
    builder.setRepeatInterval(resultSet.getLong(4));
    builder.setNextDate(resultSet.getTimestamp(5));
    builder.setPreviousRun(resultSet.getTimestamp(6));
    builder.setPrimaryKey(deSerialize(resultSet.getString(7)));
    builder.setInfo((Serializable) deSerialize(resultSet.getString(8)));
    builder.setTimerState(TimerState.valueOf(resultSet.getString(9)));
    builder.setPersistent(true);
    TimerImpl ret = builder.build(timerService);
    if (nodeName != null && (nodeName.equals(this.nodeName))) {
        if (ret.getState() == TimerState.IN_TIMEOUT || ret.getState() == TimerState.RETRY_TIMEOUT) {
            requiresReset = true;
        }
    }
    return new Holder(ret, requiresReset);
}
Also used : CalendarTimer(org.jboss.as.ejb3.timerservice.CalendarTimer) TimeoutMethod(org.jboss.as.ejb3.timerservice.persistence.TimeoutMethod) Method(java.lang.reflect.Method) TimeoutMethod(org.jboss.as.ejb3.timerservice.persistence.TimeoutMethod) TimerImpl(org.jboss.as.ejb3.timerservice.TimerImpl)

Example 5 with CalendarTimer

use of org.jboss.as.ejb3.timerservice.CalendarTimer in project wildfly by wildfly.

the class DatabaseTimerPersistence method statementParameters.

private void statementParameters(final TimerImpl timerEntity, final PreparedStatement statement) throws SQLException {
    statement.setString(1, timerEntity.getId());
    statement.setString(2, timerEntity.getTimedObjectId());
    statement.setTimestamp(3, timestamp(timerEntity.getInitialExpiration()));
    statement.setLong(4, timerEntity.getInterval());
    statement.setTimestamp(5, timestamp(timerEntity.getNextExpiration()));
    statement.setTimestamp(6, timestamp(timerEntity.getPreviousRun()));
    statement.setString(7, serialize((Serializable) timerEntity.getPrimaryKey()));
    statement.setString(8, serialize(timerEntity.getTimerInfo()));
    statement.setString(9, timerEntity.getState().name());
    if (timerEntity instanceof CalendarTimer) {
        final CalendarTimer c = (CalendarTimer) timerEntity;
        statement.setString(10, c.getScheduleExpression().getSecond());
        statement.setString(11, c.getScheduleExpression().getMinute());
        statement.setString(12, c.getScheduleExpression().getHour());
        statement.setString(13, c.getScheduleExpression().getDayOfWeek());
        statement.setString(14, c.getScheduleExpression().getDayOfMonth());
        statement.setString(15, c.getScheduleExpression().getMonth());
        statement.setString(16, c.getScheduleExpression().getYear());
        statement.setTimestamp(17, timestamp(c.getScheduleExpression().getStart()));
        statement.setTimestamp(18, timestamp(c.getScheduleExpression().getEnd()));
        statement.setString(19, c.getScheduleExpression().getTimezone());
        statement.setBoolean(20, c.isAutoTimer());
        if (c.isAutoTimer()) {
            statement.setString(21, c.getTimeoutMethod().getDeclaringClass().getName());
            statement.setString(22, c.getTimeoutMethod().getName());
            StringBuilder params = new StringBuilder();
            final Class<?>[] parameterTypes = c.getTimeoutMethod().getParameterTypes();
            for (int i = 0; i < parameterTypes.length; ++i) {
                params.append(parameterTypes[i].getName());
                if (i != parameterTypes.length - 1) {
                    params.append(";");
                }
            }
            statement.setString(23, params.toString());
        } else {
            statement.setString(21, null);
            statement.setString(22, null);
            statement.setString(23, null);
        }
        statement.setBoolean(24, true);
    } else {
        statement.setString(10, null);
        statement.setString(11, null);
        statement.setString(12, null);
        statement.setString(13, null);
        statement.setString(14, null);
        statement.setString(15, null);
        statement.setString(16, null);
        statement.setTimestamp(17, null);
        statement.setTimestamp(18, null);
        statement.setString(19, null);
        statement.setBoolean(20, false);
        statement.setString(21, null);
        statement.setString(22, null);
        statement.setString(23, null);
        statement.setBoolean(24, false);
    }
    statement.setString(25, partition);
    setNodeName(timerEntity.getState(), statement, 26);
}
Also used : Serializable(java.io.Serializable) CalendarTimer(org.jboss.as.ejb3.timerservice.CalendarTimer)

Aggregations

CalendarTimer (org.jboss.as.ejb3.timerservice.CalendarTimer)3 TimerImpl (org.jboss.as.ejb3.timerservice.TimerImpl)2 Serializable (java.io.Serializable)1 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 TimeoutMethod (org.jboss.as.ejb3.timerservice.persistence.TimeoutMethod)1 ScheduleTimer (org.jboss.as.ejb3.timerservice.spi.ScheduleTimer)1 TimedObjectInvoker (org.jboss.as.ejb3.timerservice.spi.TimedObjectInvoker)1 ControlPoint (org.wildfly.extension.requestcontroller.ControlPoint)1