Search in sources :

Example 6 with TimerImpl

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

the class CalendarTimerTask method invokeBeanMethod.

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

Example 7 with TimerImpl

use of org.jboss.as.ejb3.timerservice.TimerImpl 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 8 with TimerImpl

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

the class TimerServiceImpl method getTimer.

/**
 * Returns the timer corresponding to the passed timer id and timed object id.
 *
 * @param timerId timer id
 * @param timedObjectId timed object id
 * @return the {@code TimerImpl} corresponding to the passed timer id and timed object id
 */
public TimerImpl getTimer(final String timerId, final String timedObjectId) {
    TimerImpl timer;
    timer = this.timers.get(timerId);
    if (timer != null) {
        return timer;
    }
    timer = getWaitingOnTxCompletionTimers().get(timerId);
    if (timer != null) {
        return timer;
    }
    final TimerPersistence persistence = timerPersistence.getOptionalValue();
    if (persistence instanceof DatabaseTimerPersistence) {
        timer = ((DatabaseTimerPersistence) persistence).loadTimer(timedObjectId, timerId, this);
    }
    return timer;
}
Also used : DatabaseTimerPersistence(org.jboss.as.ejb3.timerservice.persistence.database.DatabaseTimerPersistence) TimerPersistence(org.jboss.as.ejb3.timerservice.persistence.TimerPersistence) DatabaseTimerPersistence(org.jboss.as.ejb3.timerservice.persistence.database.DatabaseTimerPersistence)

Example 9 with TimerImpl

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

the class TimerAttributeDefinition method addInfo.

private static void addInfo(Timer timer, ModelNode timerNode, final String componentName) {
    try {
        final Serializable info = ((TimerImpl) timer).getCachedTimerInfo();
        if (info != null) {
            final ModelNode detailNode = timerNode.get(INFO);
            detailNode.set(info.toString());
        }
    } catch (IllegalStateException e) {
    // ignore
    } catch (NoSuchObjectLocalException e) {
    // ignore
    } catch (EJBException e) {
        logTimerFailure(componentName, e);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) Serializable(java.io.Serializable) TimerImpl(org.jboss.as.ejb3.timerservice.TimerImpl) ModelNode(org.jboss.dmr.ModelNode) EJBException(javax.ejb.EJBException)

Example 10 with TimerImpl

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

the class FileTimerPersistence method loadActiveTimers.

@Override
public List<TimerImpl> loadActiveTimers(final String timedObjectId, final TimerServiceImpl timerService) {
    final Lock lock = getLock(timedObjectId);
    try {
        lock.lock();
        final Map<String, TimerImpl> timers = getTimers(timedObjectId, timerService);
        final List<TimerImpl> entities = new ArrayList<TimerImpl>();
        for (Map.Entry<String, TimerImpl> entry : timers.entrySet()) {
            entities.add(mostRecentEntityVersion(entry.getValue()));
        }
        return entities;
    } finally {
        lock.unlock();
    }
}
Also used : ArrayList(java.util.ArrayList) TimerImpl(org.jboss.as.ejb3.timerservice.TimerImpl) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

TimerImpl (org.jboss.as.ejb3.timerservice.TimerImpl)11 CalendarTimer (org.jboss.as.ejb3.timerservice.CalendarTimer)5 IOException (java.io.IOException)4 SystemException (javax.transaction.SystemException)4 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ScheduleExpression (javax.ejb.ScheduleExpression)3 TimeoutMethod (org.jboss.as.ejb3.timerservice.persistence.TimeoutMethod)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Serializable (java.io.Serializable)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2