Search in sources :

Example 6 with TimerServiceImpl

use of org.jboss.as.ejb3.timerservice.TimerServiceImpl 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)

Example 7 with TimerServiceImpl

use of org.jboss.as.ejb3.timerservice.TimerServiceImpl 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)

Aggregations

TimerImpl (org.jboss.as.ejb3.timerservice.TimerImpl)5 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 SystemException (javax.transaction.SystemException)2 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)2 TimerServiceImpl (org.jboss.as.ejb3.timerservice.TimerServiceImpl)2 FileOutputStream (java.io.FileOutputStream)1 Method (java.lang.reflect.Method)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1