use of org.jboss.as.ejb3.timerservice.spi.ScheduleTimer in project wildfly by wildfly.
the class TimerServiceImpl method activate.
public synchronized void activate() {
final List<ScheduleTimer> timers = new ArrayList<ScheduleTimer>();
for (Map.Entry<Method, List<AutoTimer>> entry : autoTimers.entrySet()) {
for (AutoTimer timer : entry.getValue()) {
timers.add(new ScheduleTimer(entry.getKey(), timer.getScheduleExpression(), timer.getTimerConfig()));
}
}
// restore the timers
restoreTimers(timers);
}
use of org.jboss.as.ejb3.timerservice.spi.ScheduleTimer 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());
}
}
Aggregations