incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1445582 - in /sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl: JcrInstaller.java WatchedFolder.java
Date Wed, 13 Feb 2013 13:22:14 GMT
Author: cziegeler
Date: Wed Feb 13 13:22:13 2013
New Revision: 1445582

URL: http://svn.apache.org/r1445582
Log:
SLING-2716 :  JCR Installer does not handle move events 

Modified:
    sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
    sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/WatchedFolder.java

Modified: sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java?rev=1445582&r1=1445581&r2=1445582&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
(original)
+++ sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
Wed Feb 13 13:22:13 2013
@@ -185,6 +185,8 @@ public class JcrInstaller implements Eve
     /** Write back enabled? */
     private boolean writeBack;
 
+    private EventListener moveEventListener;
+
     /** Convert Nodes to InstallableResources */
     static interface NodeConverter {
     	InstallableResource convertNode(Node n, int priority)
@@ -231,6 +233,33 @@ public class JcrInstaller implements Eve
                         null,
                         null,
                         true); // noLocal
+                // add special observation listener for move events
+                JcrInstaller.this.moveEventListener = new EventListener() {
+
+                    /**
+                     * @see javax.jcr.observation.EventListener#onEvent(javax.jcr.observation.EventIterator)
+                     */
+                    public void onEvent(final EventIterator events) {
+                        try {
+                            while (events.hasNext()) {
+                                final Event e = events.nextEvent();
+                                JcrInstaller.this.checkChanges(e.getIdentifier());
+                                JcrInstaller.this.checkChanges(e.getPath());
+                            }
+                        } catch (final RepositoryException re) {
+                            logger.warn("RepositoryException in onEvent", re);
+                        }
+                    }
+                };
+                session.getWorkspace().getObservationManager().addEventListener(
+                        moveEventListener,
+                        Event.NODE_MOVED,
+                        "/",
+                        true, // isDeep
+                        null,
+                        null,
+                        true); // noLocal
+
                 logger.debug("Watching for node events on / to detect removal/add of our
root folders");
 
 
@@ -370,9 +399,13 @@ public class JcrInstaller implements Eve
                     wfc.cleanup(session);
                 }
                 session.getWorkspace().getObservationManager().removeEventListener(this);
+                if ( moveEventListener != null ) {
+                    session.getWorkspace().getObservationManager().removeEventListener(moveEventListener);
+                    moveEventListener = null;
+                }
             }
         } catch (final RepositoryException e) {
-            logger.warn("Exception in deactivate()", e);
+            logger.warn("Exception in stop()", e);
         }
         if ( session != null ) {
             session.logout();
@@ -522,6 +555,18 @@ public class JcrInstaller implements Eve
     }
 
     /**
+     * Check for changes in any of the root folders
+     */
+    private void checkChanges(final String path) {
+        for(String root : roots) {
+            if (path.startsWith(root)) {
+                logger.info("Got event for root {}, scheduling scanning of new folders",
root);
+                updateFoldersListTimer.scheduleScan();
+            }
+        }
+    }
+
+    /**
      * @see javax.jcr.observation.EventListener#onEvent(javax.jcr.observation.EventIterator)
      */
     public void onEvent(final EventIterator it) {
@@ -532,12 +577,7 @@ public class JcrInstaller implements Eve
                 final Event e = it.nextEvent();
                 logger.debug("Got event {}", e);
 
-                for(String root : roots) {
-                    if (e.getPath().startsWith(root)) {
-                        logger.info("Got event for root {}, scheduling scanning of new folders",
root);
-                        updateFoldersListTimer.scheduleScan();
-                    }
-                }
+                this.checkChanges(e.getPath());
             }
         } catch(RepositoryException re) {
             logger.warn("RepositoryException in onEvent", re);

Modified: sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/WatchedFolder.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/WatchedFolder.java?rev=1445582&r1=1445581&r2=1445582&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/WatchedFolder.java
(original)
+++ sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/WatchedFolder.java
Wed Feb 13 13:22:13 2013
@@ -96,7 +96,7 @@ class WatchedFolder implements EventList
     	try {
 	    	session.getWorkspace().getObservationManager().removeEventListener(this);
     	} catch(RepositoryException re) {
-    		log.warn("RepositoryException in cleanup()", re);
+    		log.warn("RepositoryException in stop()", re);
     	}
     }
 



Mime
View raw message