sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r998952 - in /sling/trunk/bundles/extensions/event/src: main/java/org/apache/sling/event/impl/JobEventHandler.java test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
Date Mon, 20 Sep 2010 15:08:53 GMT
Author: cziegeler
Date: Mon Sep 20 15:08:53 2010
New Revision: 998952

URL: http://svn.apache.org/viewvc?rev=998952&view=rev
Log:
SLING-1788 : Fail early if loaded job should not be processed on the current app node

Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
    sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.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=998952&r1=998951&r2=998952&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
Mon Sep 20 15:08:53 2010
@@ -228,7 +228,7 @@ public class JobEventHandler
 
     /**
      * Activate this component.
-     * @param context
+     * @param context The component context.
      */
     protected void activate(final ComponentContext context) {
         @SuppressWarnings("unchecked")
@@ -581,7 +581,7 @@ public class JobEventHandler
         // for another application node
         final String appId = (String)info.event.getProperty(EventUtil.PROPERTY_APPLICATION);
         if ( info.event.getProperty(EventUtil.PROPERTY_JOB_RUN_LOCAL) != null
-            && appId != null && !this.applicationId.equals(appId) ) {
+            && !this.applicationId.equals(appId) ) {
             if ( logger.isDebugEnabled() ) {
                  logger.debug("Discarding job {} : local job for a different application
node.", EventUtil.toString(info.event));
             }
@@ -1247,26 +1247,45 @@ public class JobEventHandler
         return eventCreated;
     }
 
+    /**
+     * Try to load a job from an event node in the repository.
+     * @param eventNode       The node to read the event from
+     * @param unloadedJobSet  The set of unloaded jobs - if loading fails, the node path
is added here
+     * @return <code>true</code> If the job can be loaded.
+     */
     private boolean tryToLoadJob(final Node eventNode, final Set<String> unloadedJobSet)
{
         try {
+            // first check: node should be unlocked (= not processed by any other cluster
node)
+            //              job should not be finished
             if ( !eventNode.isLocked() && !eventNode.hasProperty(EventHelper.NODE_PROPERTY_FINISHED))
{
                 final String nodePath = eventNode.getPath();
-                try {
-                    final Event event = this.readEvent(eventNode);
-                    final EventInfo info = new EventInfo();
-                    info.event = event;
-                    info.nodePath = nodePath;
-                    this.queueJob(info);
-                } catch (ClassNotFoundException cnfe) {
-                    // store path for lazy loading
-                    synchronized ( unloadedJobSet ) {
-                        unloadedJobSet.add(nodePath);
+                boolean isNonLocal = false;
+                // second check: is this a job that should only run on the instance that
it was created on?
+                if ( eventNode.hasProperty(EventUtil.PROPERTY_JOB_RUN_LOCAL) &&
+                     !eventNode.getProperty(EventHelper.NODE_PROPERTY_APPLICATION).getString().equals(this.applicationId))
{
+                    isNonLocal = true;
+                    if ( logger.isDebugEnabled() ) {
+                         logger.debug("Discarding job at {} : local job for a different application
node.", nodePath);
                     }
-                    this.ignoreException(cnfe);
-                } catch (RepositoryException re) {
-                    this.logger.error("Unable to load stored job from " + nodePath, re);
                 }
-                return true;
+                if ( !isNonLocal ) {
+                    try {
+                        final Event event = this.readEvent(eventNode);
+                        final EventInfo info = new EventInfo();
+                        info.event = event;
+                        info.nodePath = nodePath;
+                        this.queueJob(info);
+                    } catch (ClassNotFoundException cnfe) {
+                        // store path for lazy loading
+                        synchronized ( unloadedJobSet ) {
+                            unloadedJobSet.add(nodePath);
+                        }
+                        this.ignoreException(cnfe);
+                    } catch (RepositoryException re) {
+                        this.logger.error("Unable to load stored job from " + nodePath, re);
+                    }
+                    return true;
+                }
             }
         } catch (RepositoryException re) {
             this.logger.error("Unable to load stored job from " + eventNode, re);

Modified: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java?rev=998952&r1=998951&r2=998952&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
(original)
+++ sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
Mon Sep 20 15:08:53 2010
@@ -77,6 +77,9 @@ public abstract class AbstractRepository
     }
 
     @org.junit.AfterClass public static void shutdownRepository() throws Exception {
+        if ( session != null ) {
+            session.logout();
+        }
         RepositoryTestUtil.stopRepository();
     }
 



Mime
View raw message