Author: bdelacretaz
Date: Wed Jul 30 06:52:40 2008
New Revision: 681030

URL: http://svn.apache.org/viewvc?rev=681030&view=rev
Log:
SLING-587 - new 'bundles' folders are now detected inside /libs and /apps, as 
long as those two folders exist when the service starts

Added:
    
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolderCreationListener.java
   (with props)
Modified:
    
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundleNodeProcessor.java
    
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolder.java
    
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/ConfigNodeProcessor.java
    
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/JcrBundlesConstants.java
    
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/JcrBundlesManager.java

Modified: 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundleNodeProcessor.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundleNodeProcessor.java?rev=681030&r1=681029&r2=681030&view=diff
==============================================================================
--- 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundleNodeProcessor.java
 (original)
+++ 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundleNodeProcessor.java
 Wed Jul 30 06:52:40 2008
@@ -18,7 +18,7 @@
  */
 package org.apache.sling.jcr.jcrbundles;
 
-import static 
org.apache.sling.jcr.jcrbundles.JcrBundlesConstants.JCRBUNDLES_NAME_PREFIX;
+import static 
org.apache.sling.jcr.jcrbundles.JcrBundlesConstants.JCRBUNDLES_LOCATION_PREFIX;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -164,6 +164,6 @@
     }
     
     protected String getBundleLocation(String bundleNodePath) {
-       return JCRBUNDLES_NAME_PREFIX + bundleNodePath;
+       return JCRBUNDLES_LOCATION_PREFIX + bundleNodePath;
     }
 }
\ No newline at end of file

Modified: 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolder.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolder.java?rev=681030&r1=681029&r2=681030&view=diff
==============================================================================
--- 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolder.java
 (original)
+++ 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolder.java
 Wed Jul 30 06:52:40 2008
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.jcr.jcrbundles;
 
+import static 
org.apache.sling.jcr.jcrbundles.JcrBundlesConstants.BUNDLES_NODENAME;
 import static 
org.apache.sling.jcr.jcrbundles.JcrBundlesConstants.STATUS_BASE_PATH;
 import java.util.HashSet;
 import java.util.List;
@@ -55,12 +56,6 @@
     /** List of processors for our bundles and configs */
     private final List<NodeProcessor> processors;
 
-    /** Only folders having this name can contain bundles and configs */
-    public static final String BUNDLES_NODENAME = "bundles";
-    
-    /** Only folders having this type can contain bundles and configs */
-    public static final String BUNDLES_NODETYPE = "nt:hierarchyNode";
-    
     /** Create a BundlesFolder on the given Repository, at the
      *  given path
      */
@@ -143,10 +138,6 @@
             Set<BundlesFolder> setToUpdate, List<NodeProcessor> processors) 
     throws RepositoryException {
         if(n.getName().equals(BUNDLES_NODENAME)) {
-            /*
-            if(!n.isNodeType(BUNDLES_NODETYPE)) {
-                log.debug("{} node does not have {} type, ignored", 
n.getPath(), BUNDLES_NODETYPE);
-            }*/
             setToUpdate.add(new BundlesFolder(r, n.getPath(), processors));
         }
         final NodeIterator it = n.getNodes();
@@ -192,7 +183,7 @@
             final Node n = session.getRootNode().getNode(relPath(statusPath));
             processNode(n, flags, true);
         } else {
-               log.info("Status folder {} does not exist, checkDeletions does 
nothing");
+               log.info("Status folder {} does not exist, checkDeletions does 
nothing", statusPath);
         }
     }
     

Added: 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolderCreationListener.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolderCreationListener.java?rev=681030&view=auto
==============================================================================
--- 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolderCreationListener.java
 (added)
+++ 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolderCreationListener.java
 Wed Jul 30 06:52:40 2008
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.jcrbundles;
+
+import static 
org.apache.sling.jcr.jcrbundles.JcrBundlesConstants.BUNDLES_NODENAME;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** EventListener that collects the paths of new "bundles"
+ *  nodes.
+ */
+class BundlesFolderCreationListener implements EventListener {
+    protected final Logger log = LoggerFactory.getLogger(this.getClass());
+    private Set<String> paths = new HashSet<String>();
+    
+    /** Return our saved paths and clear the list */
+    Set<String> getAndClearPaths() {
+        synchronized(paths) {
+            Set<String> result = paths; 
+            paths = new HashSet<String>();
+            return result;
+        }
+    }
+    
+    /** Store the paths of new "bundles" nodes */
+    public void onEvent(EventIterator it) {
+        try {
+            while(it.hasNext()) {
+                final Event e = it.nextEvent();
+                if(e.getPath().endsWith("/" + BUNDLES_NODENAME)) {
+                    synchronized(paths) {
+                        paths.add(e.getPath());
+                    }
+                }
+            }
+        } catch(RepositoryException re) {
+            log.warn("RepositoryException in onEvent", re);
+        }
+    }
+
+}

Propchange: 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolderCreationListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/BundlesFolderCreationListener.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/ConfigNodeProcessor.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/ConfigNodeProcessor.java?rev=681030&r1=681029&r2=681030&view=diff
==============================================================================
--- 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/ConfigNodeProcessor.java
 (original)
+++ 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/ConfigNodeProcessor.java
 Wed Jul 30 06:52:40 2008
@@ -21,8 +21,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Calendar;
-import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Properties;

Modified: 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/JcrBundlesConstants.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/JcrBundlesConstants.java?rev=681030&r1=681029&r2=681030&view=diff
==============================================================================
--- 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/JcrBundlesConstants.java
 (original)
+++ 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/JcrBundlesConstants.java
 Wed Jul 30 06:52:40 2008
@@ -20,6 +20,13 @@
 
 /** Constants for this module */
 public class JcrBundlesConstants {
+    
+    /** Where to store our status data */
        public static final String STATUS_BASE_PATH = 
"/system/sling/jcrbundles/status";
-       public static final String JCRBUNDLES_NAME_PREFIX = "jcrbundles:";
+       
+       /** Prefix used for the OSGi Location field of bundles that we install 
*/
+       public static final String JCRBUNDLES_LOCATION_PREFIX = "jcrbundles:";
+       
+    /** Only folders having this name can contain bundles and configs */
+    public static final String BUNDLES_NODENAME = "bundles";
 }

Modified: 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/JcrBundlesManager.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/JcrBundlesManager.java?rev=681030&r1=681029&r2=681030&view=diff
==============================================================================
--- 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/JcrBundlesManager.java
 (original)
+++ 
incubator/sling/whiteboard/jcrbundles/src/main/java/org/apache/sling/jcr/jcrbundles/JcrBundlesManager.java
 Wed Jul 30 06:52:40 2008
@@ -18,7 +18,9 @@
  */
 package org.apache.sling.jcr.jcrbundles;
 
+import static 
org.apache.sling.jcr.jcrbundles.JcrBundlesConstants.BUNDLES_NODENAME;
 import static 
org.apache.sling.jcr.jcrbundles.JcrBundlesConstants.STATUS_BASE_PATH;
+
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -29,6 +31,7 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.observation.Event;
 
 import org.apache.sling.jcr.api.SlingRepository;
 import org.osgi.service.cm.ConfigurationAdmin;
@@ -76,6 +79,10 @@
     /** @scr.reference */
     private ConfigurationAdmin cadmin;
 
+    /** Listeners for new BundleFolders under our bundleRoots */
+    private List<BundlesFolderCreationListener> listeners = new 
LinkedList<BundlesFolderCreationListener>();
+    
+    private Session session;
     protected final Logger log = LoggerFactory.getLogger(this.getClass());
     private boolean running;
     
@@ -109,7 +116,17 @@
             folders.addAll(BundlesFolder.findBundlesFolders(repository, 
rootPath, processors));
         }
         
-        // TODO: should listen for any new "bundles" folders created after 
activation
+        // Listen for any new "bundles" folders created after activation
+        session = 
repository.loginAdministrative(repository.getDefaultWorkspace());
+        final int eventTypes = Event.NODE_ADDED;
+        final boolean isDeep = true;
+        final boolean noLocal = true;
+        for(String path : this.bundleRoots) {
+            final BundlesFolderCreationListener bfc = new 
BundlesFolderCreationListener();
+            listeners.add(bfc);
+            
session.getWorkspace().getObservationManager().addEventListener(bfc, 
eventTypes, path, 
+                    isDeep, null, null, noLocal);
+        }
         
         // start queue processing
         final Thread t = new Thread(this, getClass().getSimpleName() + "_" + 
System.currentTimeMillis());
@@ -126,11 +143,26 @@
             try {
                 bf.cleanup();
             } catch(RepositoryException e) {
-                log.warn("RepositoryException in deactivate", e);
+                log.warn("RepositoryException in deactivate/cleanup", e);
             }
         }
         
         folders.clear();
+        
+        if(session != null) {
+            try {
+                for(BundlesFolderCreationListener bfc : listeners) {
+                    
session.getWorkspace().getObservationManager().removeEventListener(bfc);
+                }
+            } catch(RepositoryException re) {
+                log.warn("RepositoryException in 
deactivate()/removeEventListener", re);
+            }
+            
+            listeners.clear();
+            
+            session.logout();
+            session = null;
+        }
     }
     
     /** Scan paths once their timer expires */
@@ -187,6 +219,16 @@
     
     /** Run one cycle of processing our scanTimes queue */
     void runOneCycle(Session s) throws Exception {
+        
+        // Add new bundle folders that onEvent created
+        for(BundlesFolderCreationListener bfc : listeners) {
+            for(String path : bfc.getAndClearPaths()) {
+                log.info("New \"" + BUNDLES_NODENAME + "\" node was detected 
at {}, creating BundlesFolder to watch it", path);
+                folders.add(new BundlesFolder(repository, path, processors));
+            }
+        }
+        
+        // Let ouf BundlesFolders do their work
        final Map<String, Boolean> flags = new HashMap<String, Boolean>();
        
         for(BundlesFolder bf : folders) {
@@ -204,4 +246,5 @@
                padmin.refreshPackages(null);
        }
     }
-}
\ No newline at end of file
+    
+ }
\ No newline at end of file


Reply via email to