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 2014/10/25 15:53:34 UTC

svn commit: r1634226 - /sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java

Author: cziegeler
Date: Sat Oct 25 13:53:34 2014
New Revision: 1634226

URL: http://svn.apache.org/r1634226
Log:
SLING-4096 : Jobs might stay unprocessed when topology changes

Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java?rev=1634226&r1=1634225&r2=1634226&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java Sat Oct 25 13:53:34 2014
@@ -27,7 +27,6 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.event.impl.jobs.config.JobManagerConfiguration;
-import org.apache.sling.event.impl.support.ResourceHelper;
 import org.apache.sling.event.jobs.Job;
 import org.apache.sling.event.jobs.NotificationConstants;
 import org.osgi.framework.BundleContext;
@@ -93,26 +92,29 @@ public class NewJobSender implements Eve
     public void handleEvent(final Event event) {
         logger.debug("Received event {}", event);
         final String path = (String) event.getProperty(SlingConstants.PROPERTY_PATH);
-        final String rt = (String) event.getProperty(SlingConstants.PROPERTY_RESOURCE_TYPE);
-        if ( ResourceHelper.RESOURCE_TYPE_JOB.equals(rt) && this.configuration.isLocalJob(path) ) {
+        if ( this.configuration.isLocalJob(path) ) {
             // get topic and id from path
             final int topicStart = this.configuration.getLocalJobsPath().length() + 1;
             final int topicEnd = path.indexOf('/', topicStart);
-            final String topic = path.substring(topicStart, topicEnd).replace('.', '/');
-            final String jobId = path.substring(topicEnd + 1);
-
-            // only job id and topic are guaranteed
-            final Dictionary<String, Object> properties = new Hashtable<String, Object>();
-            properties.put(NotificationConstants.NOTIFICATION_PROPERTY_JOB_ID, jobId);
-            properties.put(NotificationConstants.NOTIFICATION_PROPERTY_JOB_TOPIC, topic);
-
-            // we also set internally the queue name
-            final String queueName = this.configuration.getQueueConfigurationManager().getQueueInfo(topic).queueName;
-            properties.put(Job.PROPERTY_JOB_QUEUE_NAME, queueName);
-
-            final Event jobEvent = new Event(NotificationConstants.TOPIC_JOB_ADDED, properties);
-            // as this is send within handling an event, we do sync call
-            this.eventAdmin.sendEvent(jobEvent);
+            if ( topicEnd != -1 ) {
+                final String topic = path.substring(topicStart, topicEnd).replace('.', '/');
+                final String jobId = path.substring(topicEnd + 1);
+
+                if ( path.indexOf("_", topicEnd + 1) != -1 ) {
+                    // only job id and topic are guaranteed
+                    final Dictionary<String, Object> properties = new Hashtable<String, Object>();
+                    properties.put(NotificationConstants.NOTIFICATION_PROPERTY_JOB_ID, jobId);
+                    properties.put(NotificationConstants.NOTIFICATION_PROPERTY_JOB_TOPIC, topic);
+
+                    // we also set internally the queue name
+                    final String queueName = this.configuration.getQueueConfigurationManager().getQueueInfo(topic).queueName;
+                    properties.put(Job.PROPERTY_JOB_QUEUE_NAME, queueName);
+
+                    final Event jobEvent = new Event(NotificationConstants.TOPIC_JOB_ADDED, properties);
+                    // as this is send within handling an event, we do sync call
+                    this.eventAdmin.sendEvent(jobEvent);
+                }
+            }
         }
     }