Changeset 6095

Show
Ignore:
Timestamp:
12/09/11 18:30:40 (6 months ago)
Author:
mtld
Message:

added experimental support for parallel target generation, added full support for depend.xml reloading, optimized logging

Location:
trunk
Files:
1 added
14 modified

Legend:

Unmodified
Added
Removed
  • trunk/pustefix-core/src/main/java/de/schlund/pfixxml/IncludePartsInfoFactory.java

    r5915 r6095  
    3636    } 
    3737     
     38    public void reset() { 
     39        urisToInfo.clear(); 
     40    } 
     41     
    3842} 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixxml/targets/AuxDependencyManager.java

    r5743 r6095  
    117117 
    118118        if (parent_path != null && parent_part != null && parent_theme != null) { 
    119             LOG.debug("*** Found another AuxDependency as Parent..."); 
     119            if(LOG.isDebugEnabled()) { 
     120                LOG.debug("*** Found another AuxDependency as Parent..."); 
     121            } 
    120122            parent = auxFactory.getAuxDependencyInclude(parent_path, parent_part, 
    121123                            parent_theme); 
     
    143145        if (part != null && part.equals("")) part = null; 
    144146        if (theme != null && theme.equals("")) theme = null; 
    145         LOG.info("Adding Dependency of type 'text' to Target '" + target.getTargetKey() + "':"); 
    146         LOG.info("*** [" + path.toURI().toString() + "][" + part + "][" + theme + "][" + 
    147                  ((parent_path == null)? "null" : parent_path.toURI().toString()) + "][" + parent_part + "][" + parent_theme + "]"); 
    148  
     147        if(LOG.isInfoEnabled()) { 
     148            LOG.info("Adding Dependency of type 'text' to Target '" + target.getTargetKey() + "':"); 
     149            LOG.info("*** [" + path.toURI().toString() + "][" + part + "][" + theme + "][" + 
     150                    ((parent_path == null)? "null" : parent_path.toURI().toString()) + "][" + parent_part + "][" + parent_theme + "]"); 
     151        } 
     152         
    149153        child = auxFactory.getAuxDependencyInclude(path, part, theme); 
    150154        parent = getParentDependency(parent_path, parent_part, parent_theme); 
     
    161165        AuxDependency parent = null; 
    162166 
    163         LOG.info("Adding Dependency of type 'text' to Target '" + target.getTargetKey() + "':"); 
    164         LOG.info("*** [" + path.toURI().toString() + "][" + 
    165                  ((parent_path == null)? "null" : parent_path.toURI().toString()) + "][" + parent_part + "][" + parent_theme + "]"); 
    166  
     167        if(LOG.isInfoEnabled()) { 
     168            LOG.info("Adding Dependency of type 'text' to Target '" + target.getTargetKey() + "':"); 
     169            LOG.info("*** [" + path.toURI().toString() + "][" + 
     170                    ((parent_path == null)? "null" : parent_path.toURI().toString()) + "][" + parent_part + "][" + parent_theme + "]"); 
     171        } 
     172         
    167173        child = auxFactory.getAuxDependencyImage(path); 
    168174        parent = getParentDependency(parent_path, parent_part, parent_theme); 
     
    178184        AuxDependency child  = null; 
    179185 
    180         LOG.info("Adding Dependency of type 'text' to Target '" + target.getTargetKey() + "':"); 
    181         LOG.info("*** [" + path.toURI().toString() + "]"); 
    182  
     186        if(LOG.isInfoEnabled()) { 
     187            LOG.info("Adding Dependency of type 'text' to Target '" + target.getTargetKey() + "':"); 
     188            LOG.info("*** [" + path.toURI().toString() + "]"); 
     189        } 
     190         
    183191        child = auxFactory.getAuxDependencyFile(path); 
    184192         
     
    193201        AuxDependency child  = null; 
    194202 
    195         LOG.info("Adding Dependency of type 'text' to Target '" + target.getTargetKey() + "':"); 
    196         LOG.info("*** [" + target.getTargetKey() + "]"); 
    197  
     203        if(LOG.isInfoEnabled()) { 
     204            LOG.info("Adding Dependency of type 'text' to Target '" + target.getTargetKey() + "':"); 
     205            LOG.info("*** [" + target.getTargetKey() + "]"); 
     206        } 
     207         
    198208        child = auxFactory.getAuxDependencyTarget(target.getTargetGenerator(), targetkey); 
    199209         
     
    229239 
    230240    public synchronized void saveAuxdepend() throws IOException  { 
    231         LOG.info("===> Trying to save aux info of Target '" + target.getTargetKey() + "'"); 
    232  
     241        if(LOG.isInfoEnabled()) { 
     242            LOG.info("===> Trying to save aux info of Target '" + target.getTargetKey() + "'"); 
     243        } 
     244         
    233245        FileResource       path   = getAuxFile(); 
    234246        FileResource       dir    = path.getParentAsFileResource(); 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixxml/targets/LeafTarget.java

    r5788 r6095  
    147147        long maxmodtime = ResourceUtil.getResource(getTargetKey()).lastModified(); 
    148148        NDC.push("    "); 
    149         TREE.debug("> " + getTargetKey()); 
     149        if(TREE.isDebugEnabled()) { 
     150            TREE.debug("> " + getTargetKey()); 
     151        } 
    150152 
    151153        for (Iterator<AuxDependency> i = this.getAuxDependencyManager().getChildren() 
     
    169171                // invalidate Memcache: 
    170172                storeValue(null); 
    171                 TREE.debug("  [" + getTargetKey() + ": updated leaf node...]"); 
     173                if(TREE.isDebugEnabled()) { 
     174                    TREE.debug("  [" + getTargetKey() + ": updated leaf node...]"); 
     175                } 
    172176                setModTime(maxmodtime); 
    173177            } catch (Exception e) { 
     
    175179            } 
    176180        } else { 
    177             TREE.debug("  [" + getTargetKey() + ": leaf node...]"); 
     181            if(TREE.isDebugEnabled()) { 
     182                TREE.debug("  [" + getTargetKey() + ": leaf node...]"); 
     183            } 
    178184        } 
    179185        NDC.pop(); 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixxml/targets/TargetDependencyRelation.java

    r5743 r6095  
    177177                                       + " for target " + target.getTargetKey() + " would result in a LOOP!"); 
    178178        } 
    179  
    180         LOG.debug("+++ Adding relations " + target.getTargetKey() + " <-> " + aux.toString() + " / " + parent.toString()); 
    181  
     179        if(LOG.isDebugEnabled()) { 
     180            LOG.debug("+++ Adding relations " + target.getTargetKey() + " <-> " + aux.toString() + " / " + parent.toString()); 
     181        } 
    182182        if (allauxs.get(aux) == null) { 
    183183            allauxs.put(aux, new TreeSet<Target>()); 
     
    218218 
    219219    public synchronized void resetRelation(Target target) { 
    220         LOG.debug("--- Removing all relations for " + target.getTargetKey()); 
    221  
     220        if(LOG.isDebugEnabled()) { 
     221            LOG.debug("--- Removing all relations for " + target.getTargetKey()); 
     222        } 
    222223        TreeSet<AuxDependency> auxsForTarget = alltargets.get(target); 
    223224 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixxml/targets/TargetGenerationReport.java

    r5743 r6095  
    1818package de.schlund.pfixxml.targets; 
    1919 
     20import java.io.File; 
    2021import java.util.ArrayList; 
     22import java.util.Iterator; 
     23import java.util.List; 
    2124 
    22 public class TargetGenerationReport { 
     25import java.util.logging.Level; 
     26import java.util.logging.Logger; 
     27 
     28public class TargetGenerationReport implements TargetGeneratorListener { 
    2329     
    24     private ArrayList<Exception> errors = new ArrayList<Exception>(); 
     30    private String LINE1 = "============================================================================================"; 
     31    private String LINE2 = "|----------------------------------------------------------------------------------"; 
     32     
     33    private Logger logger; 
     34     
     35    private List<TargetGenerationException> errors = new ArrayList<TargetGenerationException>(); 
     36     
     37    private long start; 
     38    private long end; 
     39     
     40    private int startedTargets; 
     41    private int finishedTargets; 
     42    private int failedTargets; 
    2543     
    2644    public TargetGenerationReport() { 
    2745    } 
    2846     
    29     public void addError(Exception e) { 
    30         errors.add(e); 
     47    public TargetGenerationReport(Logger logger) { 
     48        this.logger = logger; 
     49    } 
     50     
     51    public void start(TargetGenerator targetGen) { 
     52        start = System.currentTimeMillis(); 
     53        info("Start generating targets..."); 
     54    } 
     55     
     56    public void end(TargetGenerator targetGen) { 
     57        end = System.currentTimeMillis(); 
     58        info(LINE1); 
     59        info("Generated " + finishedTargets + " targets in " + (end - start) + "ms"); 
     60        if(failedTargets > 0) { 
     61            info("Failed to create " + failedTargets + " from " + startedTargets + " targets due to errors"); 
     62        } 
     63        if (errors.isEmpty()) { 
     64            info("No exceptions"); 
     65        } else { 
     66            info("Exceptions:"); 
     67            Iterator<TargetGenerationException> it = errors.iterator(); 
     68            if(it.hasNext()) { 
     69                info(LINE2); 
     70            } 
     71            while(it.hasNext()) { 
     72                String errorMsg = it.next().toStringRepresentation(); 
     73                String[] errorLines = errorMsg.split("\n"); 
     74                for(String errorLine: errorLines) { 
     75                    info(errorLine); 
     76                } 
     77                if(it.hasNext()) { 
     78                    info(LINE2); 
     79                } 
     80            } 
     81        } 
     82        info(LINE1); 
    3183    } 
    3284     
     
    3587    } 
    3688  
    37     @Override 
    38     public String toString() { 
    39         StringBuffer buf = new StringBuffer(255); 
    40         String prod_break = "'============================================================================================'\n"; 
    41         String ex_break = "|----------------------------------------------------------------------------------\n"; 
    42         if (errors.isEmpty()) { 
    43             StringBuffer sb = new StringBuffer(); 
    44             sb.append(prod_break); 
    45             sb.append("| No exceptions\n"); 
    46             sb.append(prod_break); 
    47             return sb.toString(); 
    48         } 
    49         buf.append(prod_break); 
    50         buf.append("| Exceptions: ").append("\n"); 
    51         for (int i = 0; i < errors.size(); i++) { 
    52             TargetGenerationException tgex = (TargetGenerationException) errors.get(i); 
    53                 String str = tgex.toStringRepresentation(); 
    54                 buf.append(str); 
    55                 if (errors.size() - 1 > i) 
    56                     buf.append(ex_break); 
    57             } 
    58             buf.append(prod_break); 
    59          
    60         return buf.toString(); 
     89    public void error(Target target, TargetGenerationException exception) { 
     90        failedTargets++; 
     91        errors.add(exception); 
     92        String path = target.getTargetGenerator().getDisccachedir().toURI().toString(); 
     93        error(">>>>> Error generating " + path + File.separator + target.getTargetKey() + " from " +  
     94                target.getXMLSource().getTargetKey() + " and " + target.getXSLSource().getTargetKey(), exception); 
    6195    } 
     96     
     97    public void start(Target target) { 
     98        startedTargets++; 
     99    } 
     100     
     101    public void end(Target target) { 
     102        finishedTargets++; 
     103        String path = target.getTargetGenerator().getDisccachedir().toURI().toString(); 
     104        debug(">>>>> Generated " + path + File.separator + target.getTargetKey() + " from " +  
     105                target.getXMLSource().getTargetKey() + " and " + target.getXSLSource().getTargetKey()); 
     106    } 
     107     
     108    protected void debug(String msg) { 
     109        logger.log(Level.FINE, msg); 
     110    } 
     111     
     112    protected void error(String msg, TargetGenerationException exception) { 
     113        logger.log(Level.SEVERE, msg, exception); 
     114    } 
     115     
     116    protected void info(String msg) { 
     117        logger.log(Level.INFO, msg); 
     118    } 
     119     
    62120} 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixxml/targets/TargetGenerator.java

    r6057 r6095  
    2222import java.io.IOException; 
    2323import java.io.StringReader; 
     24import java.lang.management.ManagementFactory; 
    2425import java.net.URI; 
    2526import java.net.URISyntaxException; 
     
    114115    private static final Logger LOG = Logger.getLogger(TargetGenerator.class); 
    115116 
    116     private TargetGenerationReport report = new TargetGenerationReport(); 
    117  
    118117    private PageTargetTree pagetree = new PageTargetTree(); 
    119118 
     
    157156    private IncludePartsInfoFactory includePartsInfo; 
    158157    private boolean parseIncludes = true; 
     158    private boolean parallel = false; 
    159159 
    160160    private Map<String, String> renderParams; 
     
    167167 
    168168    public TargetGenerator(final Resource confile, final FileResource cacheDir, final boolean parseIncludes) throws IOException, SAXException, XMLException { 
    169         this(confile, cacheDir, new SPCacheFactory().init(), new SiteMap(confile), parseIncludes);    
     169        this(confile, cacheDir, new SPCacheFactory().init(), new SiteMap(confile), parseIncludes, false);    
     170    } 
     171     
     172    public TargetGenerator(final Resource confile, final FileResource cacheDir, final boolean parseIncludes, final boolean parallel) throws IOException, SAXException, XMLException { 
     173        this(confile, cacheDir, new SPCacheFactory().init(), new SiteMap(confile), parseIncludes, parallel);    
    170174    } 
    171175     
    172176    public TargetGenerator(final Resource confile, final FileResource cacheDir, final SPCacheFactory cacheFactory, final SiteMap siteMap) throws IOException, SAXException, XMLException { 
    173         this(confile, cacheDir, cacheFactory, siteMap, true); 
    174     } 
    175          
    176     public TargetGenerator(final Resource confile, final FileResource cacheDir, final SPCacheFactory cacheFactory, final SiteMap siteMap, final boolean parseIncludes) throws IOException, SAXException, XMLException { 
     177        this(confile, cacheDir, cacheFactory, siteMap, true, false); 
     178    } 
     179         
     180    public TargetGenerator(final Resource confile, final FileResource cacheDir, final SPCacheFactory cacheFactory, final SiteMap siteMap, final boolean parseIncludes, final boolean parallel) throws IOException, SAXException, XMLException { 
    177181        this.config_path = confile; 
    178182        this.cacheDir = cacheDir; 
     
    180184        this.siteMap = siteMap; 
    181185        this.parseIncludes = parseIncludes; 
     186        this.parallel = parallel; 
    182187    } 
    183188         
     
    206211        pageInfoFactory = new PageInfoFactory(); 
    207212        includePartsInfo = new IncludePartsInfoFactory(); 
    208         //TODO: factory init on reload 
    209213        Meminfo meminfo = new Meminfo(); 
    210214        meminfo.print("TG: Before loading " + config_path.toString()); 
    211215        loadConfig(config_path); 
    212216        meminfo.print("TG: after loading targets for " + config_path.toString()); 
     217    } 
     218     
     219    private void reload() throws Exception { 
     220        pagetree = new PageTargetTree(); 
     221        alltargets.clear(); 
     222        includeDocumentFactory.reset(); 
     223        targetDependencyRelation.reset(); 
     224        auxDependencyFactory.reset(); 
     225        targetFactory.reset(); 
     226        sharedLeafFactory.reset(); 
     227        pageInfoFactory.reset(); 
     228        includePartsInfo.reset(); 
     229        loadConfig(config_path); 
    213230    } 
    214231     
     
    379396                } 
    380397            } 
    381             pagetree = new PageTargetTree(); 
    382             alltargets = new HashMap<String, Target>(); 
    383             loadConfig(this.config_path); 
     398            reload(); 
    384399            this.fireConfigurationChangeEvent(); 
    385400            return true; 
     
    10951110                        gen.generateAll(); 
    10961111                        System.out.println("---------- ...done [" + args[i] + "]"); 
    1097                         report.append(gen.getReportAsString()); 
    10981112                    } else { 
    10991113                        LOG.error("Couldn't read configfile '" + args[i] + "'"); 
     
    11141128 
    11151129    public void generateAll() throws Exception { 
     1130        notifyListenerStart(); 
     1131        if(parallel) { 
     1132            generateAllParallel(); 
     1133        } else { 
     1134            generateAllSerial(); 
     1135        } 
     1136        notifyListenerEnd(); 
     1137    } 
     1138     
     1139    private void generateAllSerial() throws Exception { 
    11161140        for (Iterator<String> e = getAllTargets().keySet().iterator(); e.hasNext();) { 
    11171141            Target current = getTarget(e.next()); 
    11181142            generateTarget(current); 
    1119             /* if all listeners want to stop,  
    1120              * there is no point in continuing ... */ 
    1121             if (needsToStop()) { 
    1122                 break; 
    1123             } 
     1143        } 
     1144    } 
     1145     
     1146    private void generateAllParallel() throws Exception { 
     1147        int processors = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors(); 
     1148        List<Target> genTargets = new ArrayList<Target>(); 
     1149        for (Iterator<String> e = getAllTargets().keySet().iterator(); e.hasNext();) { 
     1150            Target current = getTarget(e.next()); 
     1151            genTargets.add(current); 
     1152        } 
     1153        Thread[] genThreads = new Thread[processors]; 
     1154        for(int i=0; i<processors; i++) { 
     1155            Thread genThread = new GenThread(genTargets); 
     1156            genThread.start(); 
     1157            genThreads[i] = genThread; 
     1158        } 
     1159        for(int i=0; i<processors; i++) { 
     1160            genThreads[i].join(); 
    11241161        } 
    11251162    } 
     
    11271164    public void generateTarget(Target target) throws Exception { 
    11281165        if (target.getType() != TargetType.XML_LEAF && target.getType() != TargetType.XSL_LEAF) { 
    1129             String path = getDisccachedir().toURI().toString(); 
    1130             System.out.println(">>>>> Generating " + path + File.separator + target.getTargetKey() + " from " + target.getXMLSource().getTargetKey() + " and " + target.getXSLSource().getTargetKey()); 
    1131  
    11321166            boolean needs_update = false; 
    11331167            needs_update = target.needsUpdate(); 
    11341168            if (needs_update) { 
    11351169                try { 
     1170                    notifyListenerStart(target); 
    11361171                    target.getValue(); 
    1137                     notifyListenerTargetDone(target); 
    1138                 } catch (TargetGenerationException tgex) { 
    1139                     notifyListenerTargetException(target, tgex); 
    1140                     report.addError(tgex); 
    1141                     tgex.printStackTrace(); 
    1142                 } 
    1143             } else { 
    1144                 notifyListenerTargetDone(target); 
    1145             } 
    1146             System.out.println("done."); 
    1147         } else { 
    1148             notifyListenerTargetDone(target); 
    1149         } 
    1150     } 
    1151  
    1152     /** 
    1153      * This method checks, if a TargetGeneratorListener wants to stop, 
    1154      * if so he will get kicked out of the listener set.  
    1155      *  
    1156      * @return true if all listeners want to stop 
    1157      */ 
    1158     private boolean needsToStop() { 
    1159         boolean result = false; 
    1160         if (generationListeners.size() > 0) { 
    1161             result = true; 
    1162             for (Iterator<TargetGeneratorListener> it = generationListeners.iterator(); it.hasNext();) { 
    1163                 TargetGeneratorListener listener = it.next(); 
    1164                 if (listener.needsStop()) { 
    1165                     result = result && true; 
    1166                     it.remove(); 
    1167                 } else { 
    1168                     result = false; 
    1169                 } 
    1170             } 
    1171         } 
    1172         return result; 
    1173     } 
    1174  
    1175     /** 
    1176      * This calls the finishedTarget method of all registered listeners 
    1177      * @param target the finished target 
    1178      */ 
    1179     private void notifyListenerTargetDone(Target target) { 
    1180         for (Iterator<TargetGeneratorListener> it = generationListeners.iterator(); it.hasNext();) { 
    1181             TargetGeneratorListener listener = it.next(); 
    1182             listener.finishedTarget(target); 
    1183         } 
    1184     } 
    1185  
    1186     /** 
    1187      * This calls the generationException method of all registered listeners 
    1188      * @param target the finished target 
    1189      * @param tgex the exception! 
    1190      */ 
    1191     private void notifyListenerTargetException(Target target, TargetGenerationException tgex) { 
    1192         for (Iterator<TargetGeneratorListener> it = generationListeners.iterator(); it.hasNext();) { 
    1193             TargetGeneratorListener listener = it.next(); 
    1194             listener.generationException(target, tgex); 
     1172                    notifyListenerEnd(target); 
     1173                } catch (TargetGenerationException e) { 
     1174                    notifyListenerError(target, e); 
     1175                } 
     1176            } 
     1177        } 
     1178    } 
     1179 
     1180    private void notifyListenerStart() { 
     1181        for(TargetGeneratorListener listener: generationListeners) { 
     1182            listener.start(this); 
     1183        } 
     1184    } 
     1185     
     1186    private void notifyListenerEnd() { 
     1187        for(TargetGeneratorListener listener: generationListeners) { 
     1188            listener.end(this); 
     1189        } 
     1190    } 
     1191     
     1192    private void notifyListenerStart(Target target) { 
     1193        for(TargetGeneratorListener listener: generationListeners) { 
     1194            listener.start(target); 
     1195        } 
     1196    } 
     1197     
     1198    private void notifyListenerEnd(Target target) { 
     1199        for(TargetGeneratorListener listener: generationListeners) { 
     1200            listener.end(target); 
     1201        } 
     1202    } 
     1203 
     1204    private void notifyListenerError(Target target, TargetGenerationException e) { 
     1205        for(TargetGeneratorListener listener: generationListeners) { 
     1206            listener.error(target, e); 
    11951207        } 
    11961208    } 
     
    12201232    } 
    12211233     
    1222     /** 
    1223      * @return report containing sensilbe information after {@link #generateAll()}, not null 
    1224      */ 
    1225     public String getReportAsString() { 
    1226         return report.toString(); 
    1227     } 
    1228  
    1229     public boolean errorsReported() { 
    1230         return report.hasError(); 
    1231     } 
    1232      
    1233     public void resetGenerationReport() { 
    1234         report = new TargetGenerationReport(); 
    1235     } 
    1236  
    12371234    //-- 
    12381235 
     
    12871284    } 
    12881285 
     1286     
     1287    private class GenThread extends Thread { 
     1288         
     1289        private List<Target> genTargets; 
     1290         
     1291        GenThread(List<Target> genTargets) { 
     1292            this.genTargets = genTargets; 
     1293        } 
     1294         
     1295        @Override 
     1296        public void run() { 
     1297            Target genTarget = null; 
     1298            do { 
     1299            synchronized(genTargets) { 
     1300                if(!genTargets.isEmpty()) { 
     1301                    genTarget = genTargets.remove(0); 
     1302                } else { 
     1303                    genTarget = null; 
     1304                } 
     1305            } 
     1306            if(genTarget != null) { 
     1307                try { 
     1308                    generateTarget(genTarget); 
     1309                } catch(Exception x) { 
     1310                    throw new RuntimeException("Error generating target " + genTarget.getTargetKey(), x); 
     1311                } 
     1312            } else { 
     1313                break; 
     1314            } 
     1315            } while(genTarget != null); 
     1316        } 
     1317         
     1318    } 
    12891319} 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixxml/targets/TargetGeneratorListener.java

    r4517 r6095  
    2020 
    2121 
    22 /** 
    23  * @author Niels Schelbach 
    24  * 23.04.2004 
    25  */ 
    2622public interface TargetGeneratorListener { 
    2723     
     24    public void start(TargetGenerator targetGen); 
     25    public void end(TargetGenerator targetGen); 
    2826     
    29     public void finishedTarget(Target target); 
    30     public void abortedTargetGeneration(Target target); 
    31     public void generationException(Target target, TargetGenerationException exception); 
    32  
    33     public boolean needsStop(); 
     27    public void start(Target target); 
     28    public void end(Target target); 
     29     
     30    public void error(Target target, TargetGenerationException exception); 
    3431 
    3532} 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixxml/targets/TargetGeneratorRunner.java

    r5875 r6095  
    33import java.io.File; 
    44import java.io.FileInputStream; 
    5 import java.io.Writer; 
    65import java.net.URI; 
    76import java.util.ArrayList; 
     
    4847    private TenantInfo tenantInfo; 
    4948    private Resource confFile; 
    50      
    51     public boolean run(File docroot, File cache, String mode, Writer output, String logLevel) throws Exception { 
     49         
     50    public boolean run(File docroot, File cache, String mode, boolean parallel, java.util.logging.Logger reportLogger) throws Exception { 
    5251         
    5352        if(!docroot.exists()) throw new Exception("TargetGenerator docroot " + docroot.getAbsolutePath() + " doesn't exist"); 
     
    5958        if(projectConfigLocation == null) throw new Exception("Can't get project config location from web.xml"); 
    6059         
    61         ConsoleAppender appender = new ConsoleAppender(new PatternLayout("[%p] %c - %m\n")); 
    62         Logger logger=Logger.getRootLogger(); 
    63         logger.setLevel(Level.toLevel(logLevel)); 
    64         logger.addAppender(appender); 
     60        Logger rootLogger = Logger.getRootLogger(); 
     61        rootLogger.setLevel(Level.toLevel("error")); 
     62        ConsoleAppender rootAppender = new ConsoleAppender(new PatternLayout("[%p] %c - %m\n")); 
     63        rootLogger.addAppender(rootAppender); 
    6564         
    6665        Properties props = new Properties(); 
     
    8584        FileResource cacheDir = ResourceUtil.getFileResource(cache.toURI()); 
    8685         
    87         try {  
    88             TargetGenerator gen = new TargetGenerator(confFile, cacheDir, true); 
    89             gen.setIsGetModTimeMaybeUpdateSkipped(false); 
     86        try { 
     87            TargetGenerator gen = new TargetGenerator(confFile, cacheDir, true, parallel); 
     88            gen.setIsGetModTimeMaybeUpdateSkipped(true); 
    9089            gen.setTenantInfo(tenantInfo); 
    9190            gen.afterPropertiesSet(); 
     91            TargetGenerationReport report = new TargetGenerationReport(reportLogger); 
     92            gen.addListener(report); 
    9293            gen.generateAll(); 
    93             output.write(gen.getReportAsString()); 
    94             return !gen.errorsReported(); 
     94            return !report.hasError(); 
    9595        } catch(Exception x) { 
    9696            throw new Exception("Generating targets failed", x); 
  • trunk/pustefix-core/src/main/java/de/schlund/pfixxml/targets/TargetImpl.java

    r5743 r6095  
    127127     * @see de.schlund.pfixxml.targets.Target#getValue() 
    128128     */ 
    129     public Object getValue() throws TargetGenerationException { 
     129    public synchronized Object getValue() throws TargetGenerationException { 
    130130        // Idea: if skip_getmodtimemaybeupdate is set we do not need to call getModeTimeMaybeUpdate 
    131131        // but: if the target is not in disk-cache (has not been generated) we must call 
     
    134134        if (generator.isGetModTimeMaybeUpdateSkipped()) { 
    135135            // skip getModTimeMaybeUpdate! 
    136             LOG.debug("skip_getmodtimemaybeupdate is true. Trying to skip getModTimeMaybeUpdate..."); 
     136            if(LOG.isDebugEnabled()) { 
     137                LOG.debug("skip_getmodtimemaybeupdate is true. Trying to skip getModTimeMaybeUpdate..."); 
     138            } 
    137139            if (!onceLoaded) { 
    138140                // do test for exists here! 
     
    142144                } 
    143145                if (thefile==null || !thefile.exists()) { // Target has not been loaded once and it doesn't exist in disk cache 
    144                     LOG.debug("Cant't skip getModTimeMaybeUpdated because it has not been loaded " + 
    145                               "and doesn't even exist in disk cache! Generating now !!"); 
     146                    if(LOG.isDebugEnabled()) { 
     147                        LOG.debug("Cant't skip getModTimeMaybeUpdated because it has not been loaded " + 
     148                                "and doesn't even exist in disk cache! Generating now !!"); 
     149                    } 
    146150                    try { 
    147151                        getModTimeMaybeUpdate(); 
     
    153157                    } 
    154158                } else { 
    155                     LOG.debug("Target exists in disc cache, using it..."); 
     159                    if(LOG.isDebugEnabled()) { 
     160                        LOG.debug("Target exists in disc cache, using it..."); 
     161                    } 
    156162                } 
    157             } else { // target generated -> nop  
    158                 LOG.debug("Target has already been loaded, reusing it..."); 
     163            } else { // target generated -> nop 
     164                if(LOG.isDebugEnabled()) { 
     165                    LOG.debug("Target has already been loaded, reusing it..."); 
     166                } 
    159167            } 
    160168        } else { // do not skip getModTimeMaybeUpdate  
    161             LOG.debug("Skipping getModTimeMaybeUpdate disabled in TargetGenerator!"); 
     169            if(LOG.isDebugEnabled()) { 
     170                LOG.debug("Skipping getModTimeMaybeUpdate disabled in TargetGenerator!"); 
     171            } 
    162172            try { 
    163173                getModTimeMaybeUpdate(); 
     
    215225                obj = getValueFromSPCache(); 
    216226                if (obj == null || isDiskCacheNewerThenMemCache()) { 
    217                     if (LOG.isDebugEnabled()) { 
    218                         if (LOG.isDebugEnabled() && isDiskCacheNewerThenMemCache()) { 
    219                             LOG.debug( 
     227                    if (LOG.isDebugEnabled() && isDiskCacheNewerThenMemCache()) { 
     228                        LOG.debug( 
    220229                                "File in disk cache is newer then in memory cache. Rereading target from disk..."); 
    221                         } 
    222230                    } 
    223231                     
  • trunk/pustefix-core/src/main/java/de/schlund/pfixxml/targets/VirtualTarget.java

    r5966 r6095  
    128128     */ 
    129129    @Override 
    130     public boolean needsUpdate() throws Exception { 
     130    public synchronized boolean needsUpdate() throws Exception { 
    131131        long mymodtime = getModTime(); 
    132132        long xmlmod; 
     
    228228        long tmpmodtime; 
    229229        NDC.push("    "); 
    230         TREE.debug("> " + getTargetKey()); 
     230        if(TREE.isDebugEnabled()) { 
     231            TREE.debug("> " + getTargetKey()); 
     232        } 
    231233        maxmodtime = ((TargetImpl) getXMLSource()).getModTimeMaybeUpdate(); 
    232234        // if (maxmodtime > currmodtime) { 
     
    276278                    try { 
    277279                        generateValue(); 
    278                         TREE.debug("  [" + getTargetKey() + ": generated...]"); 
     280                        if(TREE.isDebugEnabled()) { 
     281                            TREE.debug("  [" + getTargetKey() + ": generated...]"); 
     282                        } 
    279283                    } catch (TransformerException e) { 
    280284                        LOG.error("Error when generating: " + getTargetKey() 
     
    309313            } 
    310314        } else { 
    311             TREE.debug("  [" + getTargetKey() + ": skipping...]"); 
     315            if(TREE.isDebugEnabled()) { 
     316                TREE.debug("  [" + getTargetKey() + ": skipping...]"); 
     317            } 
    312318        } 
    313319        NDC.pop(); 
  • trunk/pustefix-core/src/main/java/org/pustefixframework/container/spring/http/PustefixHandlerMapping.java

    r5393 r6095  
    7070    } 
    7171     
     72    public void reload() { 
     73        initApplicationContext(); 
     74    } 
     75     
    7276} 
  • trunk/pustefix-core/src/main/java/org/pustefixframework/http/AbstractPustefixXMLRequestHandler.java

    r6087 r6095  
    5151import org.pustefixframework.config.contextxmlservice.AbstractXMLServletConfig; 
    5252import org.pustefixframework.config.contextxmlservice.ServletManagerConfig; 
     53import org.pustefixframework.container.spring.http.PustefixHandlerMapping; 
    5354import org.springframework.context.ApplicationContext; 
    5455import org.springframework.context.ApplicationContextAware; 
     
    496497        } 
    497498         
     499        if(!generator.isGetModTimeMaybeUpdateSkipped()) { 
     500            synchronized(this) { 
     501                try { 
     502                    boolean reloaded = generator.tryReinit(); 
     503                    if(reloaded) { 
     504                        PustefixHandlerMapping handlerMapping = (PustefixHandlerMapping)applicationContext.getBean(PustefixHandlerMapping.class.getName()); 
     505                        handlerMapping.reload(); 
     506                    } 
     507                } catch(Exception x) { 
     508                    throw new PustefixCoreException(x); 
     509                } 
     510            } 
     511        } 
     512         
    498513        if (spdoc.getResponseError() == HttpServletResponse.SC_NOT_FOUND && spdoc.getDocument() != null) { 
    499514            String stylesheet = extractStylesheetFromSPDoc(spdoc, preq); 
  • trunk/pustefix-plugins/pustefix-generate-plugin/pom.xml

    r6094 r6095  
    3434      <version>1.5.1</version> 
    3535    </dependency> 
    36     <dependency> 
    37       <groupId>org.pustefixframework</groupId> 
    38       <artifactId>pustefix-core</artifactId> 
    39       <version>0.18.5-SNAPSHOT</version> 
    40     </dependency> 
    4136  </dependencies> 
    4237 
  • trunk/pustefix-plugins/pustefix-generate-plugin/src/main/java/org/pustefixframework/maven/plugins/GenerateMojo.java

    r6080 r6095  
    1919 
    2020import java.io.File; 
    21 import java.io.StringWriter; 
    22 import java.io.Writer; 
    2321import java.lang.reflect.Method; 
    2422import java.net.URL; 
    2523import java.net.URLClassLoader; 
    2624import java.util.List; 
     25import java.util.logging.Level; 
     26import java.util.logging.Logger; 
    2727 
    2828import org.apache.maven.plugin.AbstractMojo; 
     
    5656     
    5757    /** 
    58      * @parameter default-value="error" 
     58     * @parameter default-value=true 
    5959     * @required 
    6060     */ 
    61     private String loglevel; 
     61    private boolean parallel; 
    6262 
    6363    /** @parameter default-value="${project}" */ 
     
    7474         
    7575        File cache = new File(webappdir, ".cache"); 
    76  
     76         
     77        Logger reportLogger = new GenerateReportLogger(getLog()); 
     78        if(getLog().isDebugEnabled()) { 
     79            reportLogger.setLevel(Level.FINE); 
     80        } else if(getLog().isInfoEnabled()) { 
     81            reportLogger.setLevel(Level.INFO); 
     82        } else if(getLog().isWarnEnabled()) { 
     83            reportLogger.setLevel(Level.WARNING); 
     84        } else if(getLog().isErrorEnabled()) { 
     85            reportLogger.setLevel(Level.SEVERE); 
     86        } 
     87         
    7788        URLClassLoader loader = getProjectRuntimeClassLoader(); 
    7889        ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); 
    7990        try { 
    8091            Class<?> generator = Class.forName("de.schlund.pfixxml.targets.TargetGeneratorRunner", true, loader); 
    81             Method meth = 
    82                     generator.getMethod("run", File.class, File.class, String.class, 
    83                             Writer.class, String.class); 
     92            Method meth = generator.getMethod("run", File.class, File.class, String.class, boolean.class, Logger.class); 
    8493            Object instance = generator.newInstance(); 
    85             StringWriter output = new StringWriter(); 
    8694            Thread.currentThread().setContextClassLoader(loader); 
    87             boolean ok = 
    88                     (Boolean) meth.invoke(instance, docroot, cache, "prod", output, loglevel); 
    89             getLog().info(output.toString()); 
     95            boolean ok = (Boolean) meth.invoke(instance, docroot, cache, "prod", parallel, reportLogger); 
    9096            if (!ok) 
    9197                throw new MojoExecutionException("Target generation errors occurred.");