use of org.apache.sling.event.jobs.ScheduleInfo in project sling by apache.
the class ScheduledJobHandler method updateSchedule.
public void updateSchedule(final String scheduleName, final Collection<ScheduleInfo> scheduleInfo) {
final ResourceResolver resolver = configuration.createResourceResolver();
try {
final String scheduleKey = ResourceHelper.filterName(scheduleName);
final StringBuilder sb = new StringBuilder(configuration.getScheduledJobsPath(true));
sb.append(scheduleKey);
final String path = sb.toString();
final Resource rsrc = resolver.getResource(path);
// This is an update, if we can't find the resource we ignore it
if (rsrc != null) {
final Calendar now = Calendar.getInstance();
// update holder first
synchronized (scheduledJobs) {
final Holder h = scheduledJobs.get(scheduleKey);
if (h != null) {
h.created = now;
}
}
final ModifiableValueMap mvm = rsrc.adaptTo(ModifiableValueMap.class);
mvm.put(Job.PROPERTY_JOB_CREATED, now);
final String[] infoArray = new String[scheduleInfo.size()];
int index = 0;
for (final ScheduleInfo si : scheduleInfo) {
infoArray[index] = ((ScheduleInfoImpl) si).getSerializedString();
index++;
}
mvm.put(ResourceHelper.PROPERTY_SCHEDULE_INFO, infoArray);
try {
resolver.commit();
} catch (final PersistenceException pe) {
logger.warn("Unable to update scheduled job " + scheduleName, pe);
}
}
} finally {
resolver.close();
}
}
Aggregations