use of org.jboss.as.ejb3.timerservice.persistence.TimeoutMethod in project wildfly by wildfly.
the class EjbTimerXmlParser_1_0 method parseCalendarTimer.
private void parseCalendarTimer(XMLExtendedStreamReader reader, List<TimerImpl> timers) throws XMLStreamException {
LoadableElements loadableElements = new LoadableElements();
CalendarTimer.Builder builder = CalendarTimer.builder();
builder.setAutoTimer(false).setPersistent(true);
final Set<String> required = new HashSet<>(Arrays.asList(new String[] { TIMED_OBJECT_ID, TIMER_ID, TIMER_STATE, SCHEDULE_EXPR_SECOND, SCHEDULE_EXPR_MINUTE, SCHEDULE_EXPR_HOUR, SCHEDULE_EXPR_DAY_OF_WEEK, SCHEDULE_EXPR_DAY_OF_MONTH, SCHEDULE_EXPR_MONTH, SCHEDULE_EXPR_YEAR }));
final ScheduleExpression scheduleExpression = new ScheduleExpression();
for (int i = 0; i < reader.getAttributeCount(); ++i) {
String attr = reader.getAttributeValue(i);
String attrName = reader.getAttributeLocalName(i);
required.remove(attrName);
boolean handled = handleCommonAttributes(builder, reader, i);
if (!handled) {
switch(attrName) {
case SCHEDULE_EXPR_SECOND:
scheduleExpression.second(attr);
break;
case SCHEDULE_EXPR_MINUTE:
scheduleExpression.minute(attr);
break;
case SCHEDULE_EXPR_HOUR:
scheduleExpression.hour(attr);
break;
case SCHEDULE_EXPR_DAY_OF_WEEK:
scheduleExpression.dayOfWeek(attr);
break;
case SCHEDULE_EXPR_DAY_OF_MONTH:
scheduleExpression.dayOfMonth(attr);
break;
case SCHEDULE_EXPR_MONTH:
scheduleExpression.month(attr);
break;
case SCHEDULE_EXPR_YEAR:
scheduleExpression.year(attr);
break;
case SCHEDULE_EXPR_START_DATE:
scheduleExpression.start(new Date(Long.parseLong(attr)));
break;
case SCHEDULE_EXPR_END_DATE:
scheduleExpression.end(new Date(Long.parseLong(attr)));
break;
case SCHEDULE_EXPR_TIMEZONE:
scheduleExpression.timezone(attr);
break;
default:
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
if (!required.isEmpty()) {
throw ParseUtils.missingRequired(reader, required);
}
builder.setScheduleExpression(scheduleExpression);
while (reader.hasNext()) {
switch(reader.nextTag()) {
case END_ELEMENT:
{
try {
if (loadableElements.info != null) {
builder.setInfo((Serializable) deserialize(loadableElements.info));
}
if (loadableElements.methodName != null) {
Method timeoutMethod = CalendarTimer.getTimeoutMethod(new TimeoutMethod(loadableElements.className, loadableElements.methodName, loadableElements.params.toArray(new String[loadableElements.params.size()])), classLoader);
if (timeoutMethod != null) {
builder.setTimeoutMethod(timeoutMethod);
timers.add(builder.build(timerService));
} else {
builder.setId("deleted-timer");
timers.add(builder.build(timerService));
EjbLogger.EJB3_TIMER_LOGGER.timerReinstatementFailed(builder.getTimedObjectId(), builder.getId(), null);
}
} else {
timers.add(builder.build(timerService));
}
} catch (Exception e) {
EjbLogger.EJB3_TIMER_LOGGER.timerReinstatementFailed(builder.getTimedObjectId(), builder.getId(), e);
}
return;
}
case START_ELEMENT:
{
boolean handled = handleCommonElements(reader, loadableElements);
if (!handled) {
switch(reader.getName().getLocalPart()) {
case TIMEOUT_METHOD:
{
builder.setAutoTimer(true);
parseTimeoutMethod(reader, loadableElements);
break;
}
default:
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
}
}
use of org.jboss.as.ejb3.timerservice.persistence.TimeoutMethod in project wildfly by wildfly.
the class DatabaseTimerPersistence method timerFromResult.
/**
* Obtains a {@link Holder} from a row in {@code ResultSet}.
* Caller of this method must get the timer id from the {@code ResultSet}
* in advance and pass in as param {@code timerId}.
* Caller of this method may get the timer state from the {@code ResultSet}
* in advance and pass in as param {@code timerState}.
*
* @param resultSet the {@code ResultSet} from database query
* @param timerService the associated {@code TimerServiceImpl}
* @param timerId the timer id, not null
* @param timerState the timer state from current row in the {@code ResultSet}, may be null
* @return the {@code Holder} instance containing the timer from current {@code ResultSet} row
* @throws SQLException on errors reading from {@code ResultSet}
*/
private Holder timerFromResult(final ResultSet resultSet, final TimerServiceImpl timerService, final String timerId, final TimerState timerState) throws SQLException {
boolean calendarTimer = resultSet.getBoolean(24);
final String nodeName = resultSet.getString(25);
boolean requiresReset = false;
TimerImpl.Builder builder;
if (calendarTimer) {
CalendarTimer.Builder cb = CalendarTimer.builder();
builder = cb;
// set calendar timer specifics first
final ScheduleExpression scheduleExpression = new ScheduleExpression();
scheduleExpression.second(resultSet.getString(10));
scheduleExpression.minute(resultSet.getString(11));
scheduleExpression.hour(resultSet.getString(12));
scheduleExpression.dayOfWeek(resultSet.getString(13));
scheduleExpression.dayOfMonth(resultSet.getString(14));
scheduleExpression.month(resultSet.getString(15));
scheduleExpression.year(resultSet.getString(16));
scheduleExpression.start(stringAsSchedulerDate(resultSet.getString(17), timerId));
scheduleExpression.end(stringAsSchedulerDate(resultSet.getString(18), timerId));
scheduleExpression.timezone(resultSet.getString(19));
cb.setScheduleExpression(scheduleExpression);
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() ? EMPTY_STRING_ARRAY : TIMER_PARAM_1_ARRAY;
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), timerId, new NoSuchMethodException());
return null;
}
cb.setTimeoutMethod(timeoutMethod);
}
} else {
builder = TimerImpl.builder();
}
builder.setId(timerId);
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 != null ? timerState : TimerState.valueOf(resultSet.getString(9)));
builder.setPersistent(true);
TimerImpl ret = builder.build(timerService);
if (isClearTimerInfoCache(ret)) {
ret.setCachedTimerInfo(Object.class);
EjbLogger.EJB3_TIMER_LOGGER.debugf("Cleared timer info for timer: %s", timerId);
}
if (nodeName != null && nodeName.equals(this.nodeName) && (ret.getState() == TimerState.IN_TIMEOUT || ret.getState() == TimerState.RETRY_TIMEOUT)) {
requiresReset = true;
}
return new Holder(ret, requiresReset);
}
Aggregations