You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2001/05/09 17:25:25 UTC

cvs commit: xml-cocoon/src/org/apache/cocoon/generation HTMLGenerator.java

cziegeler    01/05/09 08:25:22

  Modified:    src/org/apache/cocoon/generation Tag: xml-cocoon2
                        HTMLGenerator.java
  Log:
  Made HTMLGenerator cacheable
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.20  +80 -3     xml-cocoon/src/org/apache/cocoon/generation/Attic/HTMLGenerator.java
  
  Index: HTMLGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/HTMLGenerator.java,v
  retrieving revision 1.1.2.19
  retrieving revision 1.1.2.20
  diff -u -r1.1.2.19 -r1.1.2.20
  --- HTMLGenerator.java	2001/04/30 14:17:22	1.1.2.19
  +++ HTMLGenerator.java	2001/05/09 15:25:08	1.1.2.20
  @@ -11,25 +11,102 @@
   import java.io.BufferedOutputStream;
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
  +import java.io.File;
   import java.io.IOException;
   import java.net.URL;
  +import java.util.Map;
  +import org.apache.avalon.excalibur.pool.Poolable;
   import org.apache.avalon.framework.component.Component;
  +import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.ResourceNotFoundException;
   import org.apache.cocoon.Roles;
  +import org.apache.cocoon.caching.Cacheable;
  +import org.apache.cocoon.caching.CacheValidity;
  +import org.apache.cocoon.caching.TimeStampCacheValidity;
   import org.apache.cocoon.components.parser.Parser;
   import org.apache.cocoon.components.url.URLFactory;
  +import org.apache.cocoon.util.HashUtil;
   import org.apache.cocoon.xml.dom.DOMStreamer;
  -import org.apache.avalon.excalibur.pool.Poolable;
   import org.w3c.tidy.Tidy;
  +import org.xml.sax.EntityResolver;
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   
   /**
    * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
  - * @version CVS $Revision: 1.1.2.19 $ $Date: 2001/04/30 14:17:22 $
  + * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  + * @version CVS $Revision: 1.1.2.20 $ $Date: 2001/05/09 15:25:08 $
    */
  -public class HTMLGenerator extends ComposerGenerator implements Poolable {
  +public class HTMLGenerator extends ComposerGenerator implements Cacheable {
  +
  +    /** The system ID of the input source */
  +    private String      systemID;
  +    /** Last modification date of the source */
  +    private long        lastModificationDate;
  +
  +    /**
  +     * Recycle this component.
  +     * All instance variables are set to <code>null</code>.
  +     */
  +    public void recycle() {
  +        super.recycle();
  +        this.systemID = null;
  +    }
  +
  +    /**
  +     * Setup the html generator.
  +     * Try to get the last modification date of the source for caching.
  +     */
  +    public void setup(EntityResolver resolver, Map objectModel, String src, Parameters par)
  +    throws ProcessingException, SAXException, IOException {
  +        super.setup(resolver, objectModel, src, par);
  +        InputSource inputSource = super.resolver.resolveEntity(null, super.source);
  +        this.systemID = inputSource.getSystemId();
  +        if (this.systemID.startsWith("file:") == true) {
  +            File xmlFile = new File(this.systemID.substring("file:".length()));
  +            this.lastModificationDate = xmlFile.lastModified();
  +        } else {
  +            try {
  +                java.net.URL u= new java.net.URL(this.systemID);
  +                java.net.URLConnection conn = u.openConnection();
  +                this.lastModificationDate = u.openConnection().getLastModified();
  +            } catch (java.net.MalformedURLException local) {
  +                // we ignore this at this stage
  +                this.lastModificationDate = 0; // no caching!
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Generate the unique key.
  +     * This key must be unique inside the space of this component.
  +     * This method must be invoked before the generateValidity() method.
  +     *
  +     * @return The generated key or <code>0</code> if the component
  +     *              is currently not cacheable.
  +     */
  +    public long generateKey() {
  +        if (this.lastModificationDate != 0) {
  +            return HashUtil.hash(this.systemID);
  +        }
  +        return 0;
  +    }
  +
  +    /**
  +     * Generate the validity object.
  +     * Before this method can be invoked the generateKey() method
  +     * must be invoked.
  +     *
  +     * @return The generated validity object or <code>null</code> if the
  +     *         component is currently not cacheable.
  +     */
  +    public CacheValidity generateValidity() {
  +        if (this.lastModificationDate != 0) {
  +            return new TimeStampCacheValidity(this.lastModificationDate);
  +        }
  +        return null;
  +    }
   
       /**
        * Generate XML data.
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


AW: [WARNING] Re: cvs commit: xml-cocoon/src/org/apache/cocoon/generation HTMLGenerator.java

Posted by Carsten Ziegeler <cz...@sundn.de>.
Sorry wasn't finished when my mailer send the mail,
so here again the whole message (Strange what happens
if you accidentally press escape...)

> Berin Loritsch wrote:
> 
> cziegeler@apache.org wrote:
> > 
> > cziegeler    01/05/09 08:25:22
> > 
> >   Modified:    src/org/apache/cocoon/generation Tag: xml-cocoon2
> >                         HTMLGenerator.java
>   Log:
> >   Made HTMLGenerator cacheable
> 
> >   -public class HTMLGenerator extends ComposerGenerator 
> implements Poolable {
> >   +public class HTMLGenerator extends ComposerGenerator 
> implements Cacheable {
> 
> PLEASE:
> 
> Do not confuse the difference between a Component that is 
> Poolable and one that is Cacheable!
> Sitemap Components are NOT Threadsafe, so they must either be 
> Poolable or SingleThreaded.
> Avalon Excalibur's Component Management Framework (which Cocoon 
> incidently uses), defaults
> to SingleThreaded (or FACTORY based creation) handling of 
> objects, in effect becoming
> SingleThreaded.  That means that for every request, a new 
> HTMLGenerator is created--instead
> of using a previously created one.
> 
> Cacheing is the process of checking if the requested resource (or 
> file) has been changed,
> and if not using the cached version.
> 
> POOLING AND CACHEING ARE DIFFERENT CONCERNS.
> 
> If you remove the Poolable interface from HTMLGenerator, in 
> essence you are saying
> that you want to instantiate, set the Logger, configure, setup 
> the sitemap component,
> perform cache checks, generate, and decommission the 
> HTMLGenerator for EACH request.
> By pooling, we only setup the sitemap component, perform cache 
> checks, and generate
> for each request.
> 
Yes, I really know the difference between Poolable and Cacheable.
BUT most components (e.g. all Generators, Transformers and Serializers)
extends the AbstractXMLProducer which is Recyclable!!!! 
So there is no need for all these components to declare the
Poolable interface by itself. 
I removed it as I found it very confusing to extend a base class
which is Recyclable and declare myself again(!) Poolable. If I do
that I it is very easy to forget to implement the recycle() method
in the subclass.

So personally I am +2 to remove the "implements Poolable" from
the classes again. What do you think?


Carsten 

Open Source Group                        sunShine - b:Integrated
================================================================
Carsten Ziegeler, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
www.sundn.de                          mailto: cziegeler@sundn.de 
================================================================



---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


AW: [WARNING] Re: cvs commit: xml-cocoon/src/org/apache/cocoon/generation HTMLGenerator.java

Posted by Carsten Ziegeler <cz...@sundn.de>.
> Berin Loritsch wrote:
> 
> cziegeler@apache.org wrote:
> > 
> > cziegeler    01/05/09 08:25:22
> > 
> >   Modified:    src/org/apache/cocoon/generation Tag: xml-cocoon2
> >                         HTMLGenerator.java
> >   Log:
> >   Made HTMLGenerator cacheable
> 
> >   -public class HTMLGenerator extends ComposerGenerator 
> implements Poolable {
> >   +public class HTMLGenerator extends ComposerGenerator 
> implements Cacheable {
> 
> PLEASE:
> 
> Do not confuse the difference between a Component that is 
> Poolable and one that is Cacheable!
> Sitemap Components are NOT Threadsafe, so they must either be 
> Poolable or SingleThreaded.
> Avalon Excalibur's Component Management Framework (which Cocoon 
> incidently uses), defaults
> to SingleThreaded (or FACTORY based creation) handling of 
> objects, in effect becoming
> SingleThreaded.  That means that for every request, a new 
> HTMLGenerator is created--instead
> of using a previously created one.
> 
> Cacheing is the process of checking if the requested resource (or 
> file) has been changed,
> and if not using the cached version.
> 
> POOLING AND CACHEING ARE DIFFERENT CONCERNS.
> 
> If you remove the Poolable interface from HTMLGenerator, in 
> essence you are saying
> that you want to instantiate, set the Logger, configure, setup 
> the sitemap component,
> perform cache checks, generate, and decommission the 
> HTMLGenerator for EACH request.
> By pooling, we only setup the sitemap component, perform cache 
> checks, and generate
> for each request.
> 
Yes, I really know the difference between Poolable and Cacheable.
BUT most components (e.g. all Generators, Transformers and Serializers)
extends the AbstractXMLProducer which is Recyclable!!!! 
So there is no need for all these components to declare the
Poolable interface by itself. 
I removed it as I found it very confusing the extend a base class
which is Recyclable and declare m


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


[WARNING] Re: cvs commit: xml-cocoon/src/org/apache/cocoon/generation HTMLGenerator.java

Posted by Berin Loritsch <bl...@apache.org>.
cziegeler@apache.org wrote:
> 
> cziegeler    01/05/09 08:25:22
> 
>   Modified:    src/org/apache/cocoon/generation Tag: xml-cocoon2
>                         HTMLGenerator.java
>   Log:
>   Made HTMLGenerator cacheable

>   -public class HTMLGenerator extends ComposerGenerator implements Poolable {
>   +public class HTMLGenerator extends ComposerGenerator implements Cacheable {

PLEASE:

Do not confuse the difference between a Component that is Poolable and one that is Cacheable!
Sitemap Components are NOT Threadsafe, so they must either be Poolable or SingleThreaded.
Avalon Excalibur's Component Management Framework (which Cocoon incidently uses), defaults
to SingleThreaded (or FACTORY based creation) handling of objects, in effect becoming
SingleThreaded.  That means that for every request, a new HTMLGenerator is created--instead
of using a previously created one.

Cacheing is the process of checking if the requested resource (or file) has been changed,
and if not using the cached version.

POOLING AND CACHEING ARE DIFFERENT CONCERNS.

If you remove the Poolable interface from HTMLGenerator, in essence you are saying
that you want to instantiate, set the Logger, configure, setup the sitemap component,
perform cache checks, generate, and decommission the HTMLGenerator for EACH request.
By pooling, we only setup the sitemap component, perform cache checks, and generate
for each request.

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org