You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2013/04/29 16:55:51 UTC

svn commit: r1477116 - in /sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl: dea/DistributedEventSender.java jobs/JobManagerImpl.java jobs/MaintenanceTask.java jobs/timed/TimedEventSender.java support/ResourceHelper.java

Author: cziegeler
Date: Mon Apr 29 14:55:50 2013
New Revision: 1477116

URL: http://svn.apache.org/r1477116
Log:
SLING-2829 : Be prepared to handle read failures in value map

Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventSender.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/timed/TimedEventSender.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventSender.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventSender.java?rev=1477116&r1=1477115&r2=1477116&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventSender.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventSender.java Mon Apr 29 14:55:50 2013
@@ -33,7 +33,6 @@ import org.apache.sling.api.resource.Log
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
-import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.event.impl.support.ResourceHelper;
 import org.apache.sling.event.jobs.JobUtil;
@@ -114,29 +113,34 @@ public class DistributedEventSender
      * @return The event object or <code>null</code>
      */
     private Event readEvent(final Resource eventResource) {
-        final ValueMap vm = ResourceUtil.getValueMap(eventResource);
-        final String topic = vm.get(EventConstants.EVENT_TOPIC, String.class);
-        final Map<String, Object> properties = ResourceHelper.cloneValueMap(vm);
-        // only send event if there are no read errors, otherwise discard it
-        if ( properties.get(ResourceHelper.PROPERTY_MARKER_READ_ERROR) == null ) {
-            properties.remove(EventConstants.EVENT_TOPIC);
+        try {
+            final ValueMap vm = ResourceHelper.getValueMap(eventResource);
+            final String topic = vm.get(EventConstants.EVENT_TOPIC, String.class);
+            final Map<String, Object> properties = ResourceHelper.cloneValueMap(vm);
+            // only send event if there are no read errors, otherwise discard it
+            if ( properties.get(ResourceHelper.PROPERTY_MARKER_READ_ERROR) == null ) {
+                properties.remove(EventConstants.EVENT_TOPIC);
 
-            try {
-                // special handling for job notification jobs for compatibility
-                if ( topic.startsWith("org/apache/sling/event/notification/job/") ) {
-                    final String jobTopic = (String)properties.get(JobUtil.NOTIFICATION_PROPERTY_JOB_TOPIC);
-                    if ( jobTopic != null) {
-                        final Event jobEvent = new Event(jobTopic, properties);
-                        properties.put(JobUtil.PROPERTY_NOTIFICATION_JOB, jobEvent);
+                try {
+                    // special handling for job notification jobs for compatibility
+                    if ( topic.startsWith("org/apache/sling/event/notification/job/") ) {
+                        final String jobTopic = (String)properties.get(JobUtil.NOTIFICATION_PROPERTY_JOB_TOPIC);
+                        if ( jobTopic != null) {
+                            final Event jobEvent = new Event(jobTopic, properties);
+                            properties.put(JobUtil.PROPERTY_NOTIFICATION_JOB, jobEvent);
+                        }
                     }
+                    final Event event = new Event(topic, properties);
+                    return event;
+                } catch (final IllegalArgumentException iae) {
+                    // this exception occurs if the topic is not correct (it should never happen,
+                    // but you never know)
+                    logger.error("Unable to read event: " + iae.getMessage(), iae);
                 }
-                final Event event = new Event(topic, properties);
-                return event;
-            } catch (final IllegalArgumentException iae) {
-                // this exception occurs if the topic is not correct (it should never happen,
-                // but you never know)
-                logger.error("Unable to read event: " + iae.getMessage(), iae);
             }
+        } catch (final InstantiationException ie) {
+            // something happened with the resource in the meanitime
+            this.ignoreException(ie);
         }
         return null;
     }

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java?rev=1477116&r1=1477115&r2=1477116&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java Mon Apr 29 14:55:50 2013
@@ -45,7 +45,6 @@ import org.apache.sling.api.resource.Que
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
-import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.discovery.TopologyEvent;
@@ -482,32 +481,37 @@ public class JobManagerImpl
     JobImpl readJob(final Resource resource) {
         JobImpl job = null;
         if ( resource != null ) {
-            final ValueMap vm = ResourceUtil.getValueMap(resource);
+            try {
+                final ValueMap vm = ResourceHelper.getValueMap(resource);
 
-            final String errorMessage = Utility.checkJobTopic(vm.get(JobUtil.PROPERTY_JOB_TOPIC));
-            if ( errorMessage == null ) {
-                final String topic = vm.get(JobUtil.PROPERTY_JOB_TOPIC, String.class);
-                final Map<String, Object> jobProperties = ResourceHelper.cloneValueMap(vm);
-
-                jobProperties.put(JobImpl.PROPERTY_RESOURCE_PATH, resource.getPath());
-                // convert to integers (JCR supports only long...)
-                jobProperties.put(Job.PROPERTY_JOB_RETRIES, vm.get(Job.PROPERTY_JOB_RETRIES, Integer.class));
-                jobProperties.put(Job.PROPERTY_JOB_RETRY_COUNT, vm.get(Job.PROPERTY_JOB_RETRY_COUNT, Integer.class));
-                jobProperties.put(Job.PROPERTY_JOB_PRIORITY, JobPriority.valueOf(vm.get(Job.PROPERTY_JOB_PRIORITY, String.class)));
-
-                job = new JobImpl(topic,
-                        (String)jobProperties.get(JobUtil.PROPERTY_JOB_NAME),
-                        (String)jobProperties.get(JobUtil.JOB_ID),
-                        jobProperties);
-            } else {
-                logger.warn(errorMessage + " : {}", vm);
-                // remove the job as the topic is invalid anyway
-                try {
-                    resource.getResourceResolver().delete(resource);
-                    resource.getResourceResolver().commit();
-                } catch ( final PersistenceException ignore) {
-                    this.ignoreException(ignore);
+                final String errorMessage = Utility.checkJobTopic(vm.get(JobUtil.PROPERTY_JOB_TOPIC));
+                if ( errorMessage == null ) {
+                    final String topic = vm.get(JobUtil.PROPERTY_JOB_TOPIC, String.class);
+                    final Map<String, Object> jobProperties = ResourceHelper.cloneValueMap(vm);
+
+                    jobProperties.put(JobImpl.PROPERTY_RESOURCE_PATH, resource.getPath());
+                    // convert to integers (JCR supports only long...)
+                    jobProperties.put(Job.PROPERTY_JOB_RETRIES, vm.get(Job.PROPERTY_JOB_RETRIES, Integer.class));
+                    jobProperties.put(Job.PROPERTY_JOB_RETRY_COUNT, vm.get(Job.PROPERTY_JOB_RETRY_COUNT, Integer.class));
+                    jobProperties.put(Job.PROPERTY_JOB_PRIORITY, JobPriority.valueOf(vm.get(Job.PROPERTY_JOB_PRIORITY, String.class)));
+
+                    job = new JobImpl(topic,
+                            (String)jobProperties.get(JobUtil.PROPERTY_JOB_NAME),
+                            (String)jobProperties.get(JobUtil.JOB_ID),
+                            jobProperties);
+                } else {
+                    logger.warn(errorMessage + " : {}", vm);
+                    // remove the job as the topic is invalid anyway
+                    try {
+                        resource.getResourceResolver().delete(resource);
+                        resource.getResourceResolver().commit();
+                    } catch ( final PersistenceException ignore) {
+                        this.ignoreException(ignore);
+                    }
                 }
+            } catch (final InstantiationException ie) {
+                // something happened with the resource in the meantime
+                this.ignoreException(ie);
             }
 
         }

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java?rev=1477116&r1=1477115&r2=1477116&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/MaintenanceTask.java Mon Apr 29 14:55:50 2013
@@ -34,7 +34,6 @@ import org.apache.sling.api.resource.Que
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
-import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.discovery.InstanceDescription;
 import org.apache.sling.event.impl.jobs.config.QueueConfigurationManager;
@@ -198,23 +197,29 @@ public class MaintenanceTask {
                                                 return;
                                             }
 
-                                            final ValueMap vm = ResourceUtil.getValueMap(rsrc);
-                                            final String targetId = caps.detectTarget(topicName, vm, info);
-
-                                            if ( targetId != null ) {
-                                                final String newPath = this.configuration.getAssginedJobsPath() + '/' + targetId + '/' + topicResource.getName() + rsrc.getPath().substring(topicResource.getPath().length());
-                                                final Map<String, Object> props = new HashMap<String, Object>(vm);
-                                                props.put(Job.PROPERTY_JOB_QUEUE_NAME, info.queueName);
-                                                props.put(Job.PROPERTY_JOB_TARGET_INSTANCE, targetId);
-                                                props.remove(Job.PROPERTY_JOB_STARTED_TIME);
-                                                try {
-                                                    ResourceHelper.getOrCreateResource(resolver, newPath, props);
-                                                    resolver.delete(rsrc);
-                                                    resolver.commit();
-                                                } catch ( final PersistenceException pe ) {
-                                                    this.ignoreException(pe);
-                                                    resolver.refresh();
+                                            try {
+                                                final ValueMap vm = ResourceHelper.getValueMap(rsrc);
+                                                final String targetId = caps.detectTarget(topicName, vm, info);
+
+                                                if ( targetId != null ) {
+                                                    final String newPath = this.configuration.getAssginedJobsPath() + '/' + targetId + '/' + topicResource.getName() + rsrc.getPath().substring(topicResource.getPath().length());
+                                                    final Map<String, Object> props = new HashMap<String, Object>(vm);
+                                                    props.put(Job.PROPERTY_JOB_QUEUE_NAME, info.queueName);
+                                                    props.put(Job.PROPERTY_JOB_TARGET_INSTANCE, targetId);
+                                                    props.remove(Job.PROPERTY_JOB_STARTED_TIME);
+                                                    try {
+                                                        ResourceHelper.getOrCreateResource(resolver, newPath, props);
+                                                        resolver.delete(rsrc);
+                                                        resolver.commit();
+                                                    } catch ( final PersistenceException pe ) {
+                                                        this.ignoreException(pe);
+                                                        resolver.refresh();
+                                                    }
                                                 }
+                                            } catch (final InstantiationException ie) {
+                                                // something happened with the resource in the meantime
+                                                this.ignoreException(ie);
+                                                resolver.refresh();
                                             }
                                         }
                                     }
@@ -237,19 +242,25 @@ public class MaintenanceTask {
                                             return;
                                         }
 
-                                        final ValueMap vm = ResourceUtil.getValueMap(rsrc);
-                                        final String newPath = this.configuration.getUnassignedJobsPath() + '/' + topicResource.getName() + rsrc.getPath().substring(topicResource.getPath().length());
-                                        final Map<String, Object> props = new HashMap<String, Object>(vm);
-                                        props.remove(Job.PROPERTY_JOB_QUEUE_NAME);
-                                        props.remove(Job.PROPERTY_JOB_TARGET_INSTANCE);
-                                        props.remove(Job.PROPERTY_JOB_STARTED_TIME);
-
                                         try {
-                                            ResourceHelper.getOrCreateResource(resolver, newPath, props);
-                                            resolver.delete(rsrc);
-                                            resolver.commit();
-                                        } catch ( final PersistenceException pe ) {
-                                            this.ignoreException(pe);
+                                            final ValueMap vm = ResourceHelper.getValueMap(rsrc);
+                                            final String newPath = this.configuration.getUnassignedJobsPath() + '/' + topicResource.getName() + rsrc.getPath().substring(topicResource.getPath().length());
+                                            final Map<String, Object> props = new HashMap<String, Object>(vm);
+                                            props.remove(Job.PROPERTY_JOB_QUEUE_NAME);
+                                            props.remove(Job.PROPERTY_JOB_TARGET_INSTANCE);
+                                            props.remove(Job.PROPERTY_JOB_STARTED_TIME);
+
+                                            try {
+                                                ResourceHelper.getOrCreateResource(resolver, newPath, props);
+                                                resolver.delete(rsrc);
+                                                resolver.commit();
+                                            } catch ( final PersistenceException pe ) {
+                                                this.ignoreException(pe);
+                                                resolver.refresh();
+                                            }
+                                        } catch (final InstantiationException ie) {
+                                            // something happened with the resource in the meantime
+                                            this.ignoreException(ie);
                                             resolver.refresh();
                                         }
                                     }
@@ -563,24 +574,29 @@ public class MaintenanceTask {
             resolver = this.resourceResolverFactory.getAdministrativeResourceResolver(null);
             final Resource jobResource = resolver.getResource(job.getResourcePath());
             if ( jobResource != null ) {
-                final ValueMap vm = ResourceUtil.getValueMap(jobResource);
-                final String newPath = this.configuration.getUniquePath(targetId, job.getTopic(), job.getId(), job.getProperties());
+                try {
+                    final ValueMap vm = ResourceHelper.getValueMap(jobResource);
+                    final String newPath = this.configuration.getUniquePath(targetId, job.getTopic(), job.getId(), job.getProperties());
 
-                final Map<String, Object> props = new HashMap<String, Object>(vm);
-                props.remove(Job.PROPERTY_JOB_QUEUE_NAME);
-                if ( targetId == null ) {
-                    props.remove(Job.PROPERTY_JOB_TARGET_INSTANCE);
-                } else {
-                    props.put(Job.PROPERTY_JOB_TARGET_INSTANCE, targetId);
-                }
-                props.remove(Job.PROPERTY_JOB_STARTED_TIME);
+                    final Map<String, Object> props = new HashMap<String, Object>(vm);
+                    props.remove(Job.PROPERTY_JOB_QUEUE_NAME);
+                    if ( targetId == null ) {
+                        props.remove(Job.PROPERTY_JOB_TARGET_INSTANCE);
+                    } else {
+                        props.put(Job.PROPERTY_JOB_TARGET_INSTANCE, targetId);
+                    }
+                    props.remove(Job.PROPERTY_JOB_STARTED_TIME);
 
-                try {
-                    ResourceHelper.getOrCreateResource(resolver, newPath, props);
-                    resolver.delete(jobResource);
-                    resolver.commit();
-                } catch ( final PersistenceException pe ) {
-                    this.ignoreException(pe);
+                    try {
+                        ResourceHelper.getOrCreateResource(resolver, newPath, props);
+                        resolver.delete(jobResource);
+                        resolver.commit();
+                    } catch ( final PersistenceException pe ) {
+                        this.ignoreException(pe);
+                    }
+                } catch (final InstantiationException ie) {
+                    // something happened with the resource in the meantime
+                    this.ignoreException(ie);
                 }
             }
         } catch (final LoginException ignore) {
@@ -656,86 +672,91 @@ public class MaintenanceTask {
     throws PersistenceException {
         final ResourceResolver resolver = jobResource.getResourceResolver();
 
-        final ValueMap vm = ResourceUtil.getValueMap(jobResource);
-        // check for binary properties
-        Map<String, Object> binaryProperties = new HashMap<String, Object>();
-        final ObjectInputStream ois = vm.get("slingevent:properties", ObjectInputStream.class);
-        if ( ois != null ) {
-            try {
-                int length = ois.readInt();
-                for(int i=0;i<length;i++) {
-                    final String key = (String)ois.readObject();
-                    final Object value = ois.readObject();
-                    binaryProperties.put(key, value);
-                }
-            } catch (final ClassNotFoundException cnfe) {
-                throw new PersistenceException("Class not found.", cnfe);
-            } catch (final java.io.InvalidClassException ice) {
-                throw new PersistenceException("Invalid class.", ice);
-            } catch (final IOException ioe) {
-                throw new PersistenceException("Unable to deserialize job properties.", ioe);
-            } finally {
+        try {
+            final ValueMap vm = ResourceHelper.getValueMap(jobResource);
+            // check for binary properties
+            Map<String, Object> binaryProperties = new HashMap<String, Object>();
+            final ObjectInputStream ois = vm.get("slingevent:properties", ObjectInputStream.class);
+            if ( ois != null ) {
                 try {
-                    ois.close();
+                    int length = ois.readInt();
+                    for(int i=0;i<length;i++) {
+                        final String key = (String)ois.readObject();
+                        final Object value = ois.readObject();
+                        binaryProperties.put(key, value);
+                    }
+                } catch (final ClassNotFoundException cnfe) {
+                    throw new PersistenceException("Class not found.", cnfe);
+                } catch (final java.io.InvalidClassException ice) {
+                    throw new PersistenceException("Invalid class.", ice);
                 } catch (final IOException ioe) {
-                    this.ignoreException(ioe);
+                    throw new PersistenceException("Unable to deserialize job properties.", ioe);
+                } finally {
+                    try {
+                        ois.close();
+                    } catch (final IOException ioe) {
+                        this.ignoreException(ioe);
+                    }
                 }
             }
-        }
-        final Map<String, Object> properties = ResourceHelper.cloneValueMap(vm);
 
-        properties.put(JobImpl.PROPERTY_BRIDGED_EVENT, true);
-        final String topic = (String)properties.remove("slingevent:topic");
-        properties.put(JobUtil.PROPERTY_JOB_TOPIC, topic);
+            final Map<String, Object> properties = ResourceHelper.cloneValueMap(vm);
 
-        properties.remove(Job.PROPERTY_JOB_QUEUE_NAME);
-        properties.remove(Job.PROPERTY_JOB_TARGET_INSTANCE);
-        // and binary properties
-        properties.putAll(binaryProperties);
-        properties.remove("slingevent:properties");
+            properties.put(JobImpl.PROPERTY_BRIDGED_EVENT, true);
+            final String topic = (String)properties.remove("slingevent:topic");
+            properties.put(JobUtil.PROPERTY_JOB_TOPIC, topic);
 
-        if ( !properties.containsKey(Job.PROPERTY_JOB_RETRIES) ) {
-            properties.put(Job.PROPERTY_JOB_RETRIES, 10); // we put a dummy value here; this gets updated by the queue
-        }
-        if ( !properties.containsKey(Job.PROPERTY_JOB_RETRY_COUNT) ) {
-            properties.put(Job.PROPERTY_JOB_RETRY_COUNT, 0);
-        }
-        properties.put(Job.PROPERTY_JOB_PRIORITY, JobPriority.NORM.name());
+            properties.remove(Job.PROPERTY_JOB_QUEUE_NAME);
+            properties.remove(Job.PROPERTY_JOB_TARGET_INSTANCE);
+            // and binary properties
+            properties.putAll(binaryProperties);
+            properties.remove("slingevent:properties");
 
-        final List<InstanceDescription> potentialTargets = caps.getPotentialTargets("/", null);
-        String targetId = null;
-        if ( potentialTargets != null && potentialTargets.size() > 0 ) {
-            final QueueInfo info = queueManager.getQueueInfo(topic);
-            logger.debug("Found queue {} for {}", info.queueConfiguration, topic);
-            // if queue is configured to drop, we drop
-            if ( info.queueConfiguration.getType() ==  QueueConfiguration.Type.DROP) {
-                resolver.delete(jobResource);
-                resolver.commit();
-                return;
+            if ( !properties.containsKey(Job.PROPERTY_JOB_RETRIES) ) {
+                properties.put(Job.PROPERTY_JOB_RETRIES, 10); // we put a dummy value here; this gets updated by the queue
             }
-            if ( info.queueConfiguration.getType() != QueueConfiguration.Type.IGNORE ) {
-                targetId = caps.detectTarget(topic, vm, info);
-                if ( targetId != null ) {
-                    properties.put(Job.PROPERTY_JOB_QUEUE_NAME, info.queueName);
-                    properties.put(Job.PROPERTY_JOB_TARGET_INSTANCE, targetId);
-                    properties.put(Job.PROPERTY_JOB_RETRIES, info.queueConfiguration.getMaxRetries());
-                    properties.put(Job.PROPERTY_JOB_PRIORITY, info.queueConfiguration.getPriority().name());
-                }
+            if ( !properties.containsKey(Job.PROPERTY_JOB_RETRY_COUNT) ) {
+                properties.put(Job.PROPERTY_JOB_RETRY_COUNT, 0);
             }
-        }
-
-        properties.put(Job.PROPERTY_JOB_CREATED_INSTANCE, "old:" + Environment.APPLICATION_ID);
-        properties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, ResourceHelper.RESOURCE_TYPE_JOB);
+            properties.put(Job.PROPERTY_JOB_PRIORITY, JobPriority.NORM.name());
 
-        final String jobId = this.configuration.getUniqueId(topic);
-        properties.put(JobUtil.JOB_ID, jobId);
-        properties.remove(Job.PROPERTY_JOB_STARTED_TIME);
+            final List<InstanceDescription> potentialTargets = caps.getPotentialTargets("/", null);
+            String targetId = null;
+            if ( potentialTargets != null && potentialTargets.size() > 0 ) {
+                final QueueInfo info = queueManager.getQueueInfo(topic);
+                logger.debug("Found queue {} for {}", info.queueConfiguration, topic);
+                // if queue is configured to drop, we drop
+                if ( info.queueConfiguration.getType() ==  QueueConfiguration.Type.DROP) {
+                    resolver.delete(jobResource);
+                    resolver.commit();
+                    return;
+                }
+                if ( info.queueConfiguration.getType() != QueueConfiguration.Type.IGNORE ) {
+                    targetId = caps.detectTarget(topic, vm, info);
+                    if ( targetId != null ) {
+                        properties.put(Job.PROPERTY_JOB_QUEUE_NAME, info.queueName);
+                        properties.put(Job.PROPERTY_JOB_TARGET_INSTANCE, targetId);
+                        properties.put(Job.PROPERTY_JOB_RETRIES, info.queueConfiguration.getMaxRetries());
+                        properties.put(Job.PROPERTY_JOB_PRIORITY, info.queueConfiguration.getPriority().name());
+                    }
+                }
+            }
 
-        final String newPath = this.configuration.getUniquePath(targetId, topic, jobId, vm);
-        this.logger.debug("Moving 'old' job from {} to {}", jobResource.getPath(), newPath);
+            properties.put(Job.PROPERTY_JOB_CREATED_INSTANCE, "old:" + Environment.APPLICATION_ID);
+            properties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, ResourceHelper.RESOURCE_TYPE_JOB);
 
-        ResourceHelper.getOrCreateResource(resolver, newPath, properties);
-        resolver.delete(jobResource);
-        resolver.commit();
+            final String jobId = this.configuration.getUniqueId(topic);
+            properties.put(JobUtil.JOB_ID, jobId);
+            properties.remove(Job.PROPERTY_JOB_STARTED_TIME);
+
+            final String newPath = this.configuration.getUniquePath(targetId, topic, jobId, vm);
+            this.logger.debug("Moving 'old' job from {} to {}", jobResource.getPath(), newPath);
+
+            ResourceHelper.getOrCreateResource(resolver, newPath, properties);
+            resolver.delete(jobResource);
+            resolver.commit();
+        } catch (final InstantiationException ie) {
+            throw new PersistenceException("Exception while reading reasource: " + ie.getMessage(), ie.getCause());
+        }
     }
 }

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/timed/TimedEventSender.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/timed/TimedEventSender.java?rev=1477116&r1=1477115&r2=1477116&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/timed/TimedEventSender.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/timed/TimedEventSender.java Mon Apr 29 14:55:50 2013
@@ -529,29 +529,34 @@ public class TimedEventSender
      */
     private ReadResult readEvent(final Resource eventResource) {
         if ( eventResource != null ) {
-            final ValueMap vm = ResourceUtil.getValueMap(eventResource);
-            final Map<String, Object> properties = ResourceHelper.cloneValueMap(vm);
-            String topic = (String)properties.get(EventConstants.EVENT_TOPIC);
-            if ( topic == null ) {
-                topic = (String)properties.remove("slingevent:topic");
-            }
-            final ReadResult result = new ReadResult();
-            if ( topic == null ) {
-                logger.warn("Resource at {} does not look like a timed event: {}", eventResource.getPath(), properties);
-                result.hasReadErrors = true;
-                return result;
-            }
-            result.hasReadErrors = properties.remove(ResourceHelper.PROPERTY_MARKER_READ_ERROR) != null;
-            properties.remove(EventConstants.EVENT_TOPIC);
-            properties.put(TimedEventStatusProvider.PROPERTY_EVENT_ID, topic.replace('/', '.') + '/' + eventResource.getName());
-
             try {
-                result.event = new Event(topic, properties);
-                return result;
-            } catch (final IllegalArgumentException iae) {
-                // this exception occurs if the topic is not correct (it should never happen,
-                // but you never know)
-                logger.error("Unable to read event: " + iae.getMessage(), iae);
+                final ValueMap vm = ResourceHelper.getValueMap(eventResource);
+                final Map<String, Object> properties = ResourceHelper.cloneValueMap(vm);
+                String topic = (String)properties.get(EventConstants.EVENT_TOPIC);
+                if ( topic == null ) {
+                    topic = (String)properties.remove("slingevent:topic");
+                }
+                final ReadResult result = new ReadResult();
+                if ( topic == null ) {
+                    logger.warn("Resource at {} does not look like a timed event: {}", eventResource.getPath(), properties);
+                    result.hasReadErrors = true;
+                    return result;
+                }
+                result.hasReadErrors = properties.remove(ResourceHelper.PROPERTY_MARKER_READ_ERROR) != null;
+                properties.remove(EventConstants.EVENT_TOPIC);
+                properties.put(TimedEventStatusProvider.PROPERTY_EVENT_ID, topic.replace('/', '.') + '/' + eventResource.getName());
+
+                try {
+                    result.event = new Event(topic, properties);
+                    return result;
+                } catch (final IllegalArgumentException iae) {
+                    // this exception occurs if the topic is not correct (it should never happen,
+                    // but you never know)
+                    logger.error("Unable to read event: " + iae.getMessage(), iae);
+                }
+            } catch (final InstantiationException ie) {
+                // something happened with the resource in the meanitime
+                this.ignoreException(ie);
             }
         }
         return null;

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java?rev=1477116&r1=1477115&r2=1477116&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java Mon Apr 29 14:55:50 2013
@@ -127,23 +127,40 @@ public abstract class ResourceHelper {
 
     public static final String PROPERTY_MARKER_READ_ERROR = ResourceHelper.class.getName() + "/ReadError";
 
-    public static Map<String, Object> cloneValueMap(final ValueMap vm) {
+    public static Map<String, Object> cloneValueMap(final ValueMap vm) throws InstantiationException {
         boolean hasReadError = false;
-        final Map<String, Object> result = new HashMap<String, Object>(vm);
-        for(final Map.Entry<String, Object> entry : result.entrySet()) {
-            if ( entry.getValue() instanceof InputStream ) {
-                final Object value = vm.get(entry.getKey(), Serializable.class);
-                if ( value != null ) {
-                    entry.setValue(value);
-                } else {
-                    hasReadError = true;
+        try {
+            final Map<String, Object> result = new HashMap<String, Object>(vm);
+            for(final Map.Entry<String, Object> entry : result.entrySet()) {
+                if ( entry.getValue() instanceof InputStream ) {
+                    final Object value = vm.get(entry.getKey(), Serializable.class);
+                    if ( value != null ) {
+                        entry.setValue(value);
+                    } else {
+                        hasReadError = true;
+                    }
                 }
             }
+            if ( hasReadError ) {
+                result.put(PROPERTY_MARKER_READ_ERROR, Boolean.TRUE);
+            }
+            return result;
+        } catch ( final IllegalArgumentException iae) {
+            // the JCR implementation might throw an IAE if something goes wrong
+            throw (InstantiationException)new InstantiationException(iae.getMessage()).initCause(iae);
         }
-        if ( hasReadError ) {
-            result.put(PROPERTY_MARKER_READ_ERROR, Boolean.TRUE);
+    }
+
+    public static ValueMap getValueMap(final Resource resource) throws InstantiationException {
+        final ValueMap vm = ResourceUtil.getValueMap(resource);
+        // trigger full loading
+        try {
+            vm.size();
+        } catch ( final IllegalArgumentException iae) {
+            // the JCR implementation might throw an IAE if something goes wrong
+            throw (InstantiationException)new InstantiationException(iae.getMessage()).initCause(iae);
         }
-        return result;
+        return vm;
     }
 
     public static void getOrCreateBasePath(final ResourceResolver resolver,