Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 6112 invoked from network); 6 Mar 2010 19:30:38 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 6 Mar 2010 19:30:38 -0000 Received: (qmail 44148 invoked by uid 500); 6 Mar 2010 19:30:20 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 44105 invoked by uid 500); 6 Mar 2010 19:30:20 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 44098 invoked by uid 99); 6 Mar 2010 19:30:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Mar 2010 19:30:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Mar 2010 19:30:17 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A8BF32388A2D; Sat, 6 Mar 2010 19:29:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100306192956.A8BF32388A2D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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); + } } }