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 2010/02/04 09:16:17 UTC

svn commit: r906395 - in /sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event: EventUtil.java impl/JobEventHandler.java

Author: cziegeler
Date: Thu Feb  4 08:16:17 2010
New Revision: 906395

URL: http://svn.apache.org/viewvc?rev=906395&view=rev
Log:
SLING-1349 :  Check if parallel property for jobs has value false

Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java?rev=906395&r1=906394&r2=906395&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java Thu Feb  4 08:16:17 2010
@@ -71,7 +71,11 @@
     /** The property for the unique event id. Value is of type String (This is optional). */
     public static final String PROPERTY_JOB_ID = "event.job.id";
 
-    /** The property to set if a job can be run parallel to any other job. */
+    /** The property to set if a job can be run parallel to any other job.
+     * For now the property should only contain the values <code>true</code>
+     * or <code>false</code> as a string value.
+     * We might want to use different values in the future for enhanced
+     * parallel job handling. */
     public static final String PROPERTY_JOB_PARALLEL = "event.job.parallel";
 
     /** The property to set if a job should only be run on the same app it has been created. */

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=906395&r1=906394&r2=906395&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java Thu Feb  4 08:16:17 2010
@@ -723,8 +723,7 @@
                      && !this.backgroundSession.itemExists(info.nodePath + "/" + EventHelper.NODE_PROPERTY_FINISHED)) {
                     final Event event = info.event;
                     final String jobTopic = (String)event.getProperty(EventUtil.PROPERTY_JOB_TOPIC);
-                    final boolean parallelProcessing = event.getProperty(EventUtil.PROPERTY_JOB_QUEUE_NAME) != null
-                                                    || event.getProperty(EventUtil.PROPERTY_JOB_PARALLEL) != null;
+                    final boolean parallelProcessing = this.useParallelProcessing(event);
 
                     // check how we can process this job
                     // if parallel processing is allowed, we can just process
@@ -983,8 +982,7 @@
      * @param isMainQueue Is this the main queue?
      */
     private void processJob(Event event, Node eventNode, boolean isMainQueue)  {
-        final boolean parallelProcessing = event.getProperty(EventUtil.PROPERTY_JOB_QUEUE_NAME) != null
-                                           || event.getProperty(EventUtil.PROPERTY_JOB_PARALLEL) != null;
+        final boolean parallelProcessing = this.useParallelProcessing(event);
         final String jobTopic = (String)event.getProperty(EventUtil.PROPERTY_JOB_TOPIC);
         logger.debug("Starting job {}", event);
         boolean unlock = true;
@@ -1288,8 +1286,7 @@
         } else {
             this.sendNotification(EventUtil.TOPIC_JOB_FINISHED, job);
         }
-        final boolean parallelProcessing = job.getProperty(EventUtil.PROPERTY_JOB_QUEUE_NAME) != null
-                                        || job.getProperty(EventUtil.PROPERTY_JOB_PARALLEL) != null;
+        final boolean parallelProcessing = this.useParallelProcessing(job);
         EventInfo putback = null;
         // we have to use the same session for unlocking that we used for locking!
         synchronized ( this.backgroundLock ) {
@@ -1663,6 +1660,34 @@
         }
     }
 
+    /**
+     * Check if the job should be handled in parallel.
+     * For improved processing we first check if a job queue name is set
+     * and always return true. This is a pure implementation thing!
+     * If the parallel property is set and is a boolean object, we return
+     * its value; if it is any other object we use its string value
+     * and return false if the string value is either "no" or "false".
+     * If any other value is set we return true, if the property is not
+     * set we return false.
+     */
+    private boolean useParallelProcessing(final Event job) {
+        if ( job.getProperty(EventUtil.PROPERTY_JOB_QUEUE_NAME) != null ) {
+            return true;
+        }
+        final Object value = job.getProperty(EventUtil.PROPERTY_JOB_PARALLEL);
+        if ( value != null ) {
+            if ( value instanceof Boolean ) {
+                return ((Boolean)value).booleanValue();
+            }
+            final String strValue = value.toString();
+            if ( "no".equalsIgnoreCase(strValue) || "false".equalsIgnoreCase(strValue) ) {
+                return false;
+            }
+            return true;
+        }
+        return false;
+    }
+
     private static final class StartedJobInfo {
         public final Event event;
         public final String nodePath;