Author: sshyrkov
Date: Tue Jan 15 14:56:38 2008
New Revision: 19517

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D19517&repname=
=3Djahia
Log:
Added template deployment descriptor (templates.xml) observer to run each 6=
0 seconds (each 5 seconds if the developmentMode is set to 'true') and to r=
estart the JahiaTemplateManagerService in case changes are detected

Modified:
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/temp=
lates/JahiaTemplateManagerService.java
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/temp=
lates/TemplatePackageRegistry.java
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/settings/Sett=
ingsBean.java
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/config/ja=
hia.skeleton
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/spring/ap=
plicationcontext-services.xml

Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/service=
s/templates/JahiaTemplateManagerService.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/java/org/jahia/services/templates/JahiaTemplateManage=
rService.java&rev=3D19517&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/temp=
lates/JahiaTemplateManagerService.java (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/temp=
lates/JahiaTemplateManagerService.java Tue Jan 15 14:56:38 2008
@@ -420,13 +420,16 @@
 =

         // TODO validate template sets: count, package dependencies etc.
         templatePackageRegistry.validate();
-
+        =

         // update all page definitions
         try {
             pageDefinitionHelper.updateAllPageDefinitions();
         } catch (JahiaException ex) {
             logger.error("Error updating all page definitions", ex);
         }
+        =

+        // start template deployment descriptor watcher
+        templatePackageRegistry.startWatchdog();
 =

         logger.info("JahiaTemplateManagerService started successfully."
                 + " Total number of found template packages: "
@@ -435,12 +438,17 @@
 =

     public void stop() throws JahiaException {
         logger.info("Stopping JahiaTemplateManagerService ...");
+        =

+        // stop template deployment descriptor watcher
+        templatePackageRegistry.stopWatchdog();
+        =

         templatePackageRegistry.reset();
         Cache templateCache =3D ServicesRegistry.getInstance().getCacheSer=
vice()
                 .getCache(JahiaPageTemplateBaseService.PAGE_TEMPLATE_CACHE=
);
         if (templateCache !=3D null) {
             templateCache.flush();
         }
+        =

         logger.info("... JahiaTemplateManagerService stopped successfully"=
);
     }
 =


Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/service=
s/templates/TemplatePackageRegistry.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/java/org/jahia/services/templates/TemplatePackageRegi=
stry.java&rev=3D19517&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/temp=
lates/TemplatePackageRegistry.java (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/temp=
lates/TemplatePackageRegistry.java Tue Jan 15 14:56:38 2008
@@ -17,9 +17,15 @@
  */
 package org.jahia.services.templates;
 =

-import java.util.Iterator;
+import static org.jahia.services.templates.TemplateDeploymentDescriptorHel=
per.TEMPLATES_DEPLOYMENT_DESCRIPTOR_NAME;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
 import java.util.TreeMap;
 =

 import org.apache.commons.collections.list.UnmodifiableList;
@@ -27,8 +33,8 @@
 import org.apache.log4j.Logger;
 import org.jahia.data.templates.JahiaTemplateDef;
 import org.jahia.data.templates.JahiaTemplatesPackage;
-
-import edu.emory.mathcs.backport.java.util.LinkedList;
+import org.jahia.registries.ServicesRegistry;
+import org.jahia.settings.SettingsBean;
 =

 /**
  * Template packages registry service.
@@ -37,20 +43,59 @@
  */
 class TemplatePackageRegistry {
 =

+    private abstract class TemplateDescriptorWatcher extends TimerTask {
+        private Map<File, Long> timeStamps =3D new HashMap<File, Long>();
+
+        private File getTemplateDescriptor(JahiaTemplatesPackage pkg) {
+            return new File(new File(settingsBean.getJahiaTemplatesDiskPat=
h(),
+                    pkg.getRootFolder()), TEMPLATES_DEPLOYMENT_DESCRIPTOR_=
NAME);
+        }
+
+        public abstract void onChange(String packageName);
+
+        @Override
+        public void run() {
+            for (JahiaTemplatesPackage pkg : getAvailablePackages()) {
+                File templateDescriptor =3D getTemplateDescriptor(pkg);
+                if (templateDescriptor.isFile() && templateDescriptor.canR=
ead()) {
+                    if (timeStamps.containsKey(templateDescriptor)) {
+                        if (templateDescriptor.lastModified() !=3D timeSta=
mps
+                                .get(templateDescriptor)) {
+                            timeStamps.put(templateDescriptor,
+                                    templateDescriptor.lastModified());
+                            onChange(pkg.getName());
+                        }
+                    } else {
+                        timeStamps.put(templateDescriptor, templateDescrip=
tor
+                                .lastModified());
+                    }
+                } else {
+                    logger.warn("Template descriptor for template package =
'"
+                            + pkg.getName()
+                            + "' is not found or can not be read under: "
+                            + templateDescriptor);
+                }
+            }
+        }
+    }
+
     private static Logger logger =3D Logger
             .getLogger(TemplatePackageRegistry.class);
 =

-    private Map templatePackages =3D new TreeMap();
+    private Map<String, JahiaTemplatesPackage> registry =3D new TreeMap<St=
ring, JahiaTemplatesPackage>();
+
+    private SettingsBean settingsBean;
 =

-    private List templates;
+    private List<JahiaTemplatesPackage> templatePackages;
+
+    private Timer watcherScheduler;
 =

     /**
      * Builds a template package hierarchy, resolving inheritance.
      */
     public void buildHierarchy() {
-        for (Iterator iterator =3D templatePackages.values().iterator(); i=
terator
-                .hasNext();) {
-            resolveInheritance((JahiaTemplatesPackage) iterator.next());
+        for (JahiaTemplatesPackage pkg : registry.values()) {
+            resolveInheritance(pkg);
         }
     }
 =

@@ -63,7 +108,7 @@
      *         exists in the repository
      */
     public boolean contains(String packageName) {
-        return templatePackages.containsKey(packageName);
+        return registry.containsKey(packageName);
     }
 =

     /**
@@ -71,12 +116,13 @@
      * =

      * @return a list of all available template packages
      */
-    public List getAvailablePackages() {
-        if (null =3D=3D templates) {
-            templates =3D UnmodifiableList.decorate(new LinkedList(
-                    templatePackages.values()));
+    public List<JahiaTemplatesPackage> getAvailablePackages() {
+        if (null =3D=3D templatePackages) {
+            templatePackages =3D UnmodifiableList
+                    .decorate(new LinkedList<JahiaTemplatesPackage>(regist=
ry
+                            .values()));
         }
-        return templates;
+        return templatePackages;
     }
 =

     /**
@@ -85,7 +131,7 @@
      * @return the number of avalable template packages in the registry
      */
     public int getAvailablePackagesCount() {
-        return templatePackages.size();
+        return registry.size();
     }
 =

     /**
@@ -99,9 +145,8 @@
      *         repository
      */
     public JahiaTemplatesPackage lookup(String packageName) {
-        return (JahiaTemplatesPackage) (templatePackages
-                .containsKey(packageName) ? templatePackages.get(packageNa=
me)
-                : null);
+        return registry.containsKey(packageName) ? registry.get(packageNam=
e)
+                : null;
     }
 =

     /**
@@ -111,13 +156,13 @@
      *            the template package to add
      */
     public void register(JahiaTemplatesPackage templatePackage) {
-        templates =3D null;
-        templatePackages.put(templatePackage.getName(), templatePackage);
+        templatePackages =3D null;
+        registry.put(templatePackage.getName(), templatePackage);
     }
 =

     public void reset() {
-        templatePackages.clear();
-        templates =3D null;
+        registry.clear();
+        templatePackages =3D null;
     }
 =

     public void resolveInheritance(JahiaTemplatesPackage pkg) {
@@ -187,6 +232,53 @@
         }
     }
 =

+    public void setSettingsBean(SettingsBean settingsBean) {
+        this.settingsBean =3D settingsBean;
+    }
+
+    public void startWatchdog() {
+        long interval =3D settingsBean.isDevelopmentMode() ? 5000 : settin=
gsBean.getTemplatesObserverInterval();
+        if (interval <=3D 0) {
+            return;
+        }
+        =

+        logger
+                .info("Starting template deployment descriptor watchdog wi=
th interval "
+                        + interval + " ms");
+        TimerTask watchdog =3D new TemplateDescriptorWatcher() {
+
+            @Override
+            public void onChange(String packageName) {
+                logger
+                        .info("Template deployment descriptor changed for =
the package '"
+                                + packageName
+                                + "'. Restarting JahiaTemplateManagerServi=
ce");
+                JahiaTemplateManagerService service =3D ServicesRegistry
+                        .getInstance().getJahiaTemplateManagerService();
+                try {
+                    service.stop();
+                    service.start();
+                } catch (Exception ex) {
+                    logger
+                            .error(
+                                    "Unable to restart JahiaTemplateManage=
rService."
+                                            + " Skipping template deployme=
nt descriptor change",
+                                    ex);
+                }
+            }
+        };
+
+        stopWatchdog();
+        watcherScheduler =3D new Timer(true);
+        watcherScheduler.schedule(watchdog, interval, interval);
+    }
+
+    public void stopWatchdog() {
+        if (watcherScheduler !=3D null) {
+            watcherScheduler.cancel();
+        }
+    }
+
     /**
      * Performs a set of validation tests for deployed template packages.
      */
@@ -194,4 +286,4 @@
         // TODO check if at least one template set is present
         // TODO implement dependency (inheritance) validation for template=
 sets
     }
-}
+}
\ No newline at end of file

Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/setting=
s/SettingsBean.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/java/org/jahia/settings/SettingsBean.java&rev=3D19517=
&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/settings/Sett=
ingsBean.java (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/settings/Sett=
ingsBean.java Tue Jan 15 14:56:38 2008
@@ -113,7 +113,6 @@
 =

     // this is the list of jahia.properties autodeployer values...
     private int jahiaWebAppsAutoDeploy;
-    private int jahiaTemplatesAutoDeploy;
 =

     // this is the list of jahia.properties files values...
     private String jahiaFileRepositoryDiskPath;
@@ -491,13 +490,9 @@
 =

             // autodeployer...
             String webappAutoDeploy =3D getString("jahiaWebAppsAutoDeploy"=
);
-            String templateAutoDeploy =3D getString("jahiaTemplatesAutoDep=
loy");
             if (webappAutoDeploy !=3D null) {
                 jahiaWebAppsAutoDeploy =3D Integer.parseInt (webappAutoDep=
loy);
             }
-            if (templateAutoDeploy !=3D null) {
-                jahiaTemplatesAutoDeploy =3D Integer.parseInt (templateAut=
oDeploy);
-            }
             templatesObserverInterval =3D getLong("templates.observer.inte=
rval", 5000);
             webAppsObserverInterval =3D getLong("webapps.observer.interval=
", 5000);
 =

@@ -1466,15 +1461,6 @@
     } // end getJahiaWebAppsAutoDeploy
 =

     /**
-     * Used to get the templates autodeployer flag.
-     *
-     * @return  The templates autodeployer flag.
-     */
-    public int getJahiaTemplatesAutoDeploy() {
-        return jahiaTemplatesAutoDeploy;
-    }
-
-    /**
      * Used to know if ESI cache is activated
      *
      */

Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/con=
fig/jahia.skeleton
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/webapp/WEB-INF/etc/config/jahia.skeleton&rev=3D19517&=
repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/config/ja=
hia.skeleton (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/config/ja=
hia.skeleton Tue Jan 15 14:56:38 2008
@@ -367,14 +367,12 @@
 ######################################################################
 ### Templates Observer  ##############################################
 ######################################################################
-# The following section configured the service that checks for new
-# Jahia templates to deploy.
-
-jahiaTemplatesAutoDeploy                               =3D   1
-# Time in milliseconds between checks in the new_templates directory for n=
ew
-# templates to deploy. Set to -1 to deactivate file watching completely.
-templates.observer.interval                            =3D   5000
-templates.observer.checkmode                           =3D   ALL
+# Time in milliseconds between checks for the template deployment =

+# descriptor changes in order to restart the JahiaTemplateManagerService.
+# Set to -1 to deactivate changes detection completely.
+# Note, if "developmentMode" option is set to "true", this parameter
+# is ignored and the observer is started with the interval of 5 seconds. =

+templates.observer.interval                            =3D   60000
 =

 ######################################################################
 ### WebApps Observer  ################################################

Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/spr=
ing/applicationcontext-services.xml
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/webapp/WEB-INF/etc/spring/applicationcontext-services=
.xml&rev=3D19517&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/spring/ap=
plicationcontext-services.xml (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/WEB-INF/etc/spring/ap=
plicationcontext-services.xml Tue Jan 15 14:56:38 2008
@@ -1070,7 +1070,11 @@
         </property>
     </bean>
 =

-    <bean id=3D"org.jahia.services.templates.TemplatePackageRegistry" clas=
s=3D"org.jahia.services.templates.TemplatePackageRegistry"/>
+    <bean id=3D"org.jahia.services.templates.TemplatePackageRegistry" clas=
s=3D"org.jahia.services.templates.TemplatePackageRegistry">
+        <property name=3D"settingsBean">
+            <ref bean=3D"settingsBean" />
+        </property>
+    </bean>
 =

     <bean id=3D"JahiaTemplateManagerService" parent=3D"proxyTemplate">
         <property name=3D"target">

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to