Search in sources :

Example 6 with ScheduleInfo

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();
    }
}
Also used : Calendar(java.util.Calendar) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) PersistenceException(org.apache.sling.api.resource.PersistenceException) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) ScheduleInfo(org.apache.sling.event.jobs.ScheduleInfo)

Aggregations

ScheduleInfo (org.apache.sling.event.jobs.ScheduleInfo)6 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 List (java.util.List)2 PersistenceException (org.apache.sling.api.resource.PersistenceException)2 InstanceDescription (org.apache.sling.discovery.InstanceDescription)2 InternalQueueConfiguration (org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration)2 TopologyCapabilities (org.apache.sling.event.impl.jobs.config.TopologyCapabilities)2 Queue (org.apache.sling.event.jobs.Queue)2 QueueConfiguration (org.apache.sling.event.jobs.QueueConfiguration)2 ScheduledJobInfo (org.apache.sling.event.jobs.ScheduledJobInfo)2 Statistics (org.apache.sling.event.jobs.Statistics)2 TopicStatistics (org.apache.sling.event.jobs.TopicStatistics)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 PrintWriter (java.io.PrintWriter)1 Serializable (java.io.Serializable)1 Calendar (java.util.Calendar)1