}
File marker = new File(file, MIGRATION_MARKER);
if (marker.exists()) {
return timers;
}
Unmarshaller unmarshaller = factory.createUnmarshaller(configuration);
for (File timerFile : file.listFiles()) {
if(timerFile.getName().endsWith(".xml")) {
continue;
}
FileInputStream in = null;
try {
in = new FileInputStream(timerFile);
unmarshaller.start(new InputStreamByteInput(in));
final TimerEntity entity = unmarshaller.readObject(TimerEntity.class);
//we load the legacy timer entity class, and turn it into a timer state
TimerImpl.Builder builder;
if (entity instanceof CalendarTimerEntity) {
CalendarTimerEntity c = (CalendarTimerEntity) entity;
builder = CalendarTimer.builder()
.setScheduleExprSecond(c.getSecond())
.setScheduleExprMinute(c.getMinute())
.setScheduleExprHour(c.getHour())
.setScheduleExprDayOfWeek(c.getDayOfWeek())
.setScheduleExprDayOfMonth(c.getDayOfMonth())
.setScheduleExprMonth(c.getMonth())
.setScheduleExprYear(c.getYear())
.setScheduleExprStartDate(c.getStartDate())
.setScheduleExprEndDate(c.getEndDate())
.setScheduleExprTimezone(c.getTimezone())
.setAutoTimer(c.isAutoTimer())
.setTimeoutMethod(CalendarTimer.getTimeoutMethod(c.getTimeoutMethod(), timerService.getTimedObjectInvoker().getValue().getClassLoader()));
} else {
builder = TimerImpl.builder();
}
builder.setId(entity.getId())
.setTimedObjectId(entity.getTimedObjectId())
.setInitialDate(entity.getInitialDate())
.setRepeatInterval(entity.getInterval())
.setNextDate(entity.getNextDate())
.setPreviousRun(entity.getPreviousRun())
.setInfo(entity.getInfo())
.setPrimaryKey(entity.getPrimaryKey())
.setTimerState(entity.getTimerState())
.setPersistent(true);
timers.put(entity.getId(), builder.build(timerService));
unmarshaller.finish();
} catch (Exception e) {
ROOT_LOGGER.failToRestoreTimersFromFile(timerFile, e);
} finally {
if (in != null) {
try {