sylvain     01/12/26 14:00:34

  Modified:    scratchpad/src/org/apache/cocoon/treeprocessor
                        TreeProcessor.java
               scratchpad/src/org/apache/cocoon/treeprocessor/sitemap
                        SerializeNode.java
               src/org/apache/cocoon/sitemap Handler.java
                        SitemapManager.java
  Added:       src/org/apache/cocoon/components/source
                        DelayedRefreshSourceWrapper.java
  Removed:     src/org/apache/cocoon/components/source
                        DelayedLastModified.java
  Log:
  - redesign refresh delay as a Source wrapper,
  - set the default sitemap refresh delay to 1 sec.
  
  Revision  Changes    Path
  1.6       +6 -8      
xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/TreeProcessor.java
  
  Index: TreeProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/TreeProcessor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TreeProcessor.java        2001/12/20 16:17:54     1.5
  +++ TreeProcessor.java        2001/12/26 22:00:33     1.6
  @@ -35,7 +35,7 @@
   import org.apache.cocoon.components.pipeline.EventPipeline;
   import org.apache.cocoon.components.pipeline.StreamPipeline;
   import org.apache.cocoon.components.source.CocoonSourceFactory;
  -import org.apache.cocoon.components.source.DelayedLastModified;
  +import org.apache.cocoon.components.source.DelayedRefreshSourceWrapper;
   import org.apache.cocoon.components.source.SourceHandler;
   import org.apache.cocoon.components.source.URLSource;
   import org.apache.cocoon.components.url.URLFactory;
  @@ -49,7 +49,7 @@
    * Interpreted tree-traversal implementation of a pipeline assembly language.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Sylvain Wallez</a>
  - * @version CVS $Revision: 1.5 $ $Date: 2001/12/20 16:17:54 $
  + * @version CVS $Revision: 1.6 $ $Date: 2001/12/26 22:00:33 $
    */
   
   public class TreeProcessor extends AbstractLoggable implements ThreadSafe, 
Processor,
  @@ -91,8 +91,6 @@
       /** The source of the tree definition */
       protected Source source;
       
  -    protected DelayedLastModified sourceLastModified;
  -    
       /** Delay for <code>sourceLastModified</code>. */
       protected long lastModifiedDelay;
       
  @@ -268,7 +266,7 @@
   
           try {
               environment.setSourceHandler(this.sourceHandler);
  -            if (this.rootNode == null || this.sourceLastModified.get() > 
this.lastModified) {
  +            if (this.rootNode == null || this.source.getLastModified() > 
this.lastModified) {
                   setupRootNode(environment);
               }
               return this.rootNode.invoke(environment, context);
  @@ -281,7 +279,7 @@
           
           // Now that we entered the synchronized area, recheck what's already
           // been checked in process().
  -        if (this.rootNode != null && sourceLastModified.get() <= this.lastModified) 
{
  +        if (this.rootNode != null && source.getLastModified() <= this.lastModified) 
{
               // Nothing changed
               return;
           }
  @@ -290,8 +288,8 @@
           
           if (this.rootNode == null) {
               // First call : create source
  -            this.source = env.resolve(this.sourceName);
  -            this.sourceLastModified = new DelayedLastModified(this.source, 10000L);
  +            // FIXME : make the delay configurable
  +            this.source = new 
DelayedRefreshSourceWrapper(env.resolve(this.sourceName), 1000L);
               
           } else {
               // Dispose existing tree, we will build a new one.
  
  
  
  1.3       +10 -2     
xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/SerializeNode.java
  
  Index: SerializeNode.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/SerializeNode.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SerializeNode.java        2001/12/20 16:17:55     1.2
  +++ SerializeNode.java        2001/12/26 22:00:33     1.3
  @@ -8,6 +8,7 @@
   
   package org.apache.cocoon.treeprocessor.sitemap;
   
  +import org.apache.cocoon.Constants;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.components.pipeline.EventPipeline;
   import org.apache.cocoon.components.pipeline.StreamPipeline;
  @@ -20,7 +21,7 @@
   /**
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Sylvain Wallez</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/12/20 16:17:55 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/12/26 22:00:33 $
    */
   
   public class SerializeNode extends AbstractProcessingNode {
  @@ -44,9 +45,16 @@
           this.statusCode = statusCode;
       }
       
  -    public boolean invoke(Environment env, InvokeContext context)
  +    public final boolean invoke(Environment env, InvokeContext context)
         throws Exception {
           
  +        // Perform link translation if requested
  +        if (env.getObjectModel().containsKey(Constants.LINK_OBJECT)) {
  +            context.getEventPipeline().addTransformer(
  +                "!link-translator!", null, MapStackResolver.EMPTY_PARAMETERS
  +            );
  +        }
  +
           StreamPipeline pipeline = context.getStreamPipeline();
           
           if (this.mimeType == null) {
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/components/source/DelayedRefreshSourceWrapper.java
  
  Index: DelayedRefreshSourceWrapper.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.components.source;
  
  import org.apache.cocoon.environment.Source;
  import org.apache.cocoon.environment.ModifiableSource;
  import org.apache.avalon.excalibur.pool.Recyclable;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.xml.XMLizable;
  import org.xml.sax.InputSource;
  import java.io.IOException;
  import java.io.InputStream;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  
  /**
   * A wrapper around a <code>Source</code> that reduces the number of calls to
   * <code>Source.getLastModified()</code> which can be a costly operation.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Sylvain Wallez</a>
   * @version $Id: DelayedRefreshSourceWrapper.java,v 1.1 2001/12/26 22:00:33 sylvain 
Exp $
   */
  public final class DelayedRefreshSourceWrapper implements Source, ModifiableSource, 
XMLizable {
      
      private Source source;
      
      private long delay;
      
      private long nextCheckTime = 0;
      
      private long lastModified = 0;
      
      private boolean isModifiableSource;
      
      /**
       * Creates a wrapper for a <code>Source</code> which ensures that
       * <code>Source.getLastModified()</code> won't be called more than once per
       * <code>delay</code> milliseconds period.
       * 
       * @param source the wrapped <code>Source</code>
       * @param delay  the last-modified refresh delay, in milliseconds
       */
      public DelayedRefreshSourceWrapper(Source source, long delay) {
          this.source = source;
          this.delay = delay;
          this.isModifiableSource = source instanceof ModifiableSource;
      }
      
      /**
       * Get the last modification time for the wrapped <code>Source</code>. The
       * age of the returned information is guaranteed to be lower than or equal to
       * the delay specified in the constructor.
       *
       * @return the last modification time.
       */
      public final long getLastModified() {
          
          // Do we have to refresh the source ?
          if (System.currentTimeMillis() >= nextCheckTime) {
              // Yes
              this.refresh();
          }
          
          return this.lastModified;
      }
  
      /**
       * Force the refresh of the wrapped <code>Source</code>, even if the refresh 
period
       * isn't over, and starts a new period.
       */
      public final void refresh() {
   
          this.nextCheckTime = System.currentTimeMillis() + this.delay;
          // Refresh modifiable sources
          if (this.isModifiableSource) {
              ((ModifiableSource)this.source).refresh();
          }
          
          // Keep the last modified date
          this.lastModified = source.getLastModified();
      }
      
      public final long getContentLength() {
          return this.source.getContentLength();
      }
  
      public final InputStream getInputStream() throws ProcessingException, 
IOException {
          return this.source.getInputStream();
      }
  
      public final InputSource getInputSource() throws ProcessingException, 
IOException {
          return this.source.getInputSource();
      }
  
      public final String getSystemId() {
          return this.source.getSystemId();
      }
  
      public final void recycle() {
          this.source.recycle();
      }
  
      public final void toSAX(ContentHandler handler) throws SAXException, 
ProcessingException {
          this.source.toSAX(handler);
      }
  }
  
  
  
  1.25      +6 -8      xml-cocoon2/src/org/apache/cocoon/sitemap/Handler.java
  
  Index: Handler.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/Handler.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Handler.java      2001/12/11 21:49:33     1.24
  +++ Handler.java      2001/12/26 22:00:33     1.25
  @@ -25,9 +25,8 @@
   import org.apache.cocoon.components.pipeline.StreamPipeline;
   import org.apache.cocoon.components.source.CocoonSourceFactory;
   import org.apache.cocoon.components.source.SourceHandler;
  -import org.apache.cocoon.components.source.DelayedLastModified;
  +import org.apache.cocoon.components.source.DelayedRefreshSourceWrapper;
   import org.apache.cocoon.environment.Environment;
  -import org.apache.cocoon.environment.ModifiableSource;
   import org.apache.cocoon.environment.Source;
   import org.apache.cocoon.environment.SourceResolver;
   import org.xml.sax.SAXException;
  @@ -42,7 +41,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.24 $ $Date: 2001/12/11 21:49:33 $
  + * @version CVS $Revision: 1.25 $ $Date: 2001/12/26 22:00:33 $
    */
   public class Handler extends AbstractLoggable
   implements Runnable, Contextualizable, Composable, Processor, Disposable, 
SourceResolver {
  @@ -52,8 +51,7 @@
   
       /** the source of this sitemap */
       private String sourceFileName;
  -    private ModifiableSource source;
  -    private DelayedLastModified sourceLastModified;
  +    private Source source;
   
       /** the last error */
       private Exception exception;
  @@ -109,7 +107,7 @@
       protected boolean hasChanged() {
           if (available()) {
               if (check_reload) {
  -                return sitemap.modifiedSince(this.sourceLastModified.get());
  +                return sitemap.modifiedSince(this.source.getLastModified());
               }
               return false;
           }
  @@ -127,8 +125,8 @@
           SourceHandler oldSourceHandler = environment.getSourceHandler();
           try {
               environment.setSourceHandler(this.sourceHandler);
  -            this.source = 
(ModifiableSource)environment.resolve(this.sourceFileName);
  -            this.sourceLastModified = new DelayedLastModified(this.source, 
this.sitemapCheckDelay);
  +            this.source = new DelayedRefreshSourceWrapper(
  +                environment.resolve(this.sourceFileName), this.sitemapCheckDelay);
               this.contextSource = environment.resolve("");
           } finally {
               environment.setSourceHandler(oldSourceHandler);
  
  
  
  1.3       +4 -3      xml-cocoon2/src/org/apache/cocoon/sitemap/SitemapManager.java
  
  Index: SitemapManager.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/SitemapManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SitemapManager.java       2001/12/11 21:49:33     1.2
  +++ SitemapManager.java       2001/12/26 22:00:33     1.3
  @@ -38,7 +38,7 @@
    * to Java code.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Sylvain Wallez</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/12/11 21:49:33 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/12/26 22:00:33 $
    */
   public class SitemapManager extends Manager implements Processor, Configurable {
       
  @@ -63,17 +63,18 @@
           value = sconf.getAttribute("reload-method", "asynchron");
           this.reloadSitemapAsynchron = !(value != null && 
value.equalsIgnoreCase("synchron") == true);
           
  -        long checkDelay = sconf.getAttributeAsLong("check-delay", 10L);
  +        long checkDelay = sconf.getAttributeAsLong("check-delay", 1L);
           Handler.setSitemapCheckDelay(checkDelay * 1000L);
           
           getLogger().debug("Sitemap location = " + this.sitemapFileName);
           getLogger().debug("Checking sitemap reload = " + this.checkSitemapReload);
           getLogger().debug("Reloading sitemap asynchron = " + 
this.reloadSitemapAsynchron);
  -        getLogger().debug("Sitemap check delay = " + checkDelay + " seconds");
  +        getLogger().debug("Sitemap check delay = " + checkDelay + " sec");
           
           System.err.println("Sitemap location = " + this.sitemapFileName);
           System.err.println("Checking sitemap reload = " + this.checkSitemapReload);
           System.err.println("Reloading sitemap asynchron = " + 
this.reloadSitemapAsynchron);
  +        System.err.println("Sitemap check delay = " + checkDelay + " sec");
           
           // Read sitemap roles
           Parser p = null;
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to