incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r919826 - /sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
Date Sat, 06 Mar 2010 19:29:56 GMT
Author: cziegeler
Date: Sat Mar  6 19:29:56 2010
New Revision: 919826

URL: http://svn.apache.org/viewvc?rev=919826&view=rev
Log:
SLING-1426 : Spurious wakeups are not handled correctly

Modified:
    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/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=919826&r1=919825&r2=919826&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
Sat Mar  6 19:29:56 2010
@@ -1309,6 +1309,7 @@
 
         // if this is set after the synchronized block we have an error
         Boolean errorOccured = null;
+        // we have to use the same session for unlocking that we used for locking!
         synchronized ( this.backgroundLock ) {
             // get the parallel info and unlock
             final ParallelInfo parInfo = ParallelInfo.getParallelInfo(job);
@@ -1319,7 +1320,7 @@
                 this.parallelJobCount--;
                 this.backgroundLock.notify();
             }
-            // we have to use the same session for unlocking that we used for locking!
+            Node eventNode = null;
             try {
                 // we might get here asnyc while this service has already been shutdown!
                 if ( this.backgroundSession == null ) {
@@ -1330,51 +1331,46 @@
                     // check if the job has been cancelled
                     if ( !this.backgroundSession.itemExists(eventNodePath) ) {
                         errorOccured = true;
+                    } else {
+                        eventNode = (Node) this.backgroundSession.getItem(eventNodePath);
                     }
                 }
-                if ( errorOccured == null ) {
-                    synchronized ( this.deletedJobs ) {
-                        this.deletedJobs.add(eventNodePath);
-                    }
-                    final Node eventNode = (Node) this.backgroundSession.getItem(eventNodePath);
-                    // unlock node
-                    try {
-                        eventNode.unlock();
-                    } catch (RepositoryException e) {
-                        // if unlock fails, we silently ignore this
-                        this.ignoreException(e);
-                    }
-                    // update status in repository
+            } catch (RepositoryException re) {
+                this.logger.error("Unable to access repository to check job node.", re);
+                errorOccured = false;
+            }
+            if ( eventNode != null ) {
+                synchronized ( this.deletedJobs ) {
+                    this.deletedJobs.add(eventNodePath);
+                }
+                // unlock node
+                try {
+                    eventNode.unlock();
+                } catch (RepositoryException e) {
+                    // if unlock fails, we silently ignore this
+                    this.ignoreException(e);
+                }
+                // update status in repository
+                try {
                     if ( !reschedule ) {
-                        try {
-                            final String jobId = (String)job.getProperty(EventUtil.PROPERTY_JOB_ID);
-                            if ( jobId == null ) {
-                                // remove node from repository if no job id is set
-                                eventNode.remove();
-                            } else {
-                                // set finished date - if job id is set
-                                eventNode.setProperty(EventHelper.NODE_PROPERTY_FINISHED,
Calendar.getInstance());
-                            }
-                            this.backgroundSession.save();
-                        } catch (RepositoryException re) {
-                            // if an exception occurs, we just log
-                            this.logger.error("Exception during finished job update.", re);
+                        final String jobId = (String)job.getProperty(EventUtil.PROPERTY_JOB_ID);
+                        if ( jobId == null ) {
+                            // remove node from repository if no job id is set
+                            eventNode.remove();
+                        } else {
+                            // set finished date - if job id is set
+                            eventNode.setProperty(EventHelper.NODE_PROPERTY_FINISHED, Calendar.getInstance());
                         }
                     } else {
                         // update retry count and retries in the repository
-                        try {
-                            eventNode.setProperty(EventUtil.PROPERTY_JOB_RETRIES, (Integer)job.getProperty(EventUtil.PROPERTY_JOB_RETRIES));
-                            eventNode.setProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT, (Integer)job.getProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT));
-                            this.backgroundSession.save();
-                        } catch (RepositoryException re) {
-                            // if an exception occurs, we just log
-                            this.logger.error("Exception during job updating job rescheduling
information.", re);
-                        }
+                        eventNode.setProperty(EventUtil.PROPERTY_JOB_RETRIES, (Integer)job.getProperty(EventUtil.PROPERTY_JOB_RETRIES));
+                        eventNode.setProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT, (Integer)job.getProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT));
                     }
+                    this.backgroundSession.save();
+                } catch (RepositoryException re) {
+                    // if an exception occurs, we just log
+                    this.logger.error("Exception during finished job update.", re);
                 }
-            } catch (RepositoryException re) {
-                this.logger.error("Unable to access repository to check job node.", re);
-                errorOccured = false;
             }
         }
         // check for error
@@ -1387,16 +1383,8 @@
             final EventInfo putback = new EventInfo();
             putback.event = job;
             putback.nodePath = eventNodePath;
-            // if this is an own job queue, we simply signal the queue to continue
-            // it will pick up the event and either reschedule or wait
-            if ( job.getProperty(EventUtil.PROPERTY_JOB_QUEUE_NAME) != null ) {
-                checkForNotify(job, putback);
-            } else {
-                this.putBackIntoMainQueue(putback, false);
-            }
+            checkForNotify(job, putback);
         } else {
-            // if this is an own job queue, we simply signal the queue to continue
-            // it will pick up the event and continue with the next event
             checkForNotify(job, null);
         }
         // if we shouldn't reschedule - we always return true as everything went fine
@@ -1458,6 +1446,8 @@
     }
 
     private void checkForNotify(final Event job, final EventInfo info) {
+        // if this is an own job queue, we simply signal the queue to continue
+        // it will pick up the event and either reschedule or wait
         if ( job.getProperty(EventUtil.PROPERTY_JOB_QUEUE_NAME) != null ) {
             // we know the queue exists
             final JobBlockingQueue jobQueue;
@@ -1475,6 +1465,10 @@
                     jobQueue.freeSlot();
                 }
             }
+        } else {
+            if ( info != null ) {
+                this.putBackIntoMainQueue(info, false);
+            }
         }
     }
 



Mime
View raw message