cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon Cocoon.java
Date Fri, 13 Sep 2002 06:46:30 GMT
cziegeler    2002/09/12 23:46:30

  Modified:    src/java/org/apache/cocoon/components/pipeline
                        AbstractProcessingPipeline.java
               src/java/org/apache/cocoon/environment/http
                        HttpEnvironment.java
               src/java/org/apache/cocoon/components/treeprocessor/sitemap
                        PipelineNode.java
               src/java/org/apache/cocoon/environment
                        AbstractEnvironment.java Environment.java
               .        changes.xml
               src/java/org/apache/cocoon/components/pipeline/impl
                        AbstractCachingProcessingPipeline.java
               src/java/org/apache/cocoon Cocoon.java
  Log:
  Updated buffering of output - it's now configurable
  
  Revision  Changes    Path
  1.22      +15 -5     xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
  
  Index: AbstractProcessingPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- AbstractProcessingPipeline.java	9 Sep 2002 12:00:41 -0000	1.21
  +++ AbstractProcessingPipeline.java	13 Sep 2002 06:46:29 -0000	1.22
  @@ -62,7 +62,6 @@
   import org.apache.cocoon.ConnectionResetException;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.CocoonComponentManager;
  -import org.apache.cocoon.components.pipeline.OutputComponentSelector;
   import org.apache.cocoon.components.treeprocessor.ProcessingNode;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.environment.ObjectModelHelper;
  @@ -74,6 +73,8 @@
   import org.apache.cocoon.xml.XMLConsumer;
   import org.apache.cocoon.xml.XMLProducer;
   import org.xml.sax.SAXException;
  +import sun.tools.tree.ThisExpression;
  +
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
   import java.io.OutputStream;
  @@ -142,6 +143,12 @@
       /** Configured Expires value */
       protected long configuredExpires;
   
  +    /** Configured Output Buffer Size */
  +    protected int  configuredOutputBufferSize;
  +    
  +    /** Output Buffer Size */
  +    protected int  outputBufferSize;
  +
       /**
        * Composable Interface
        */
  @@ -168,6 +175,7 @@
           if (expiresValue != null) {
               this.configuredExpires = this.parseExpires(expiresValue);
           }
  +        this.configuredOutputBufferSize = params.getParameterAsInteger("outputBufferSize",
-1);
       }
   
       /**
  @@ -180,6 +188,8 @@
           } else {
               this.expires = this.configuredExpires;
           }
  +        this.outputBufferSize = params.getParameterAsInteger("outputBufferSize",
  +                                                              this.configuredOutputBufferSize);
       }
   
       /**
  @@ -467,7 +477,7 @@
                   return true;
               }
               try {
  -                return this.processReader(environment, environment.getOutputStream());
  +                return this.processReader(environment, environment.getOutputStream(this.outputBufferSize));
               } catch (IOException ioe) {
                   throw new ProcessingException("Processing of reader pipeline failed.",
ioe);
               }
  @@ -498,10 +508,10 @@
                       this.generator.generate();
                       byte[] data = os.toByteArray();
                       environment.setContentLength(data.length);
  -                    environment.getOutputStream().write(data);
  +                    environment.getOutputStream(0).write(data);
                   } else {
                       // set the output stream
  -                    this.serializer.setOutputStream(environment.getOutputStream());
  +                    this.serializer.setOutputStream(environment.getOutputStream(this.outputBufferSize));
                       // execute the pipeline:
                       this.generator.generate();
                   }
  
  
  
  1.15      +19 -16    xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java
  
  Index: HttpEnvironment.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- HttpEnvironment.java	12 Sep 2002 14:14:36 -0000	1.14
  +++ HttpEnvironment.java	13 Sep 2002 06:46:29 -0000	1.15
  @@ -256,20 +256,23 @@
        * the error has already output some data.
        *
        * @return true if the response was successfully reset
  -    */
  -/*    public boolean tryResetResponse() {
  -        try {
  -            if ( !this.response.isCommitted() ) {
  -                this.response.reset();
  -                getLogger().debug("Response successfully reset");
  -                return true;
  +     */
  +    public boolean tryResetResponse() {
  +        if (!super.tryResetResponse()) {
  +            try {
  +                if (!this.response.isCommitted()) {
  +                    this.response.reset();
  +                    getLogger().debug("Response successfully reset");
  +                    return true;
  +                }
  +            } catch (Exception e) {
  +                // Log the error, but don't transmit it
  +                getLogger().warn("Problem resetting response", e);
               }
  -        } catch(Exception e) {
  -            // Log the error, but don't transmit it
  -            getLogger().warn("Problem resetting response", e);
  +            getLogger().debug("Response wasn't reset");
  +            return false;
           }
  -        getLogger().debug("Response wasn't reset");
  -        return false;
  -    }*/
  -
  +        return true;
  +    }
  +    
   }
  
  
  
  1.16      +2 -2      xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java
  
  Index: PipelineNode.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- PipelineNode.java	12 Sep 2002 14:14:36 -0000	1.15
  +++ PipelineNode.java	13 Sep 2002 06:46:29 -0000	1.16
  @@ -187,7 +187,7 @@
           try {
               // Try to reset the response to avoid mixing already produced output
               // and error page.
  -            env.resetResponse();
  +            env.tryResetResponse();
   
               // Build a new context
               errorContext = new InvokeContext();
  
  
  
  1.29      +29 -18    xml-cocoon2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
  
  Index: AbstractEnvironment.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- AbstractEnvironment.java	12 Sep 2002 14:27:50 -0000	1.28
  +++ AbstractEnvironment.java	13 Sep 2002 06:46:29 -0000	1.29
  @@ -434,13 +434,34 @@
       }
   
       /**
  -     * Get the OutputStream
  +     * Get the output stream where to write the generated resource.
  +     * @deprecated Use {@link #getOutputStream(int)} instead.
        */
       public OutputStream getOutputStream() throws IOException {
  -        if (this.secureOutputStream == null) {
  -            this.secureOutputStream = new BufferedOutputStream(this.outputStream);
  -        }
  -        return this.secureOutputStream;
  +        // by default we use the complete buffering output stream
  +        return this.getOutputStream(-1);
  +    }
  +
  +    /**
  +     * Get the output stream where to write the generated resource.
  +     * The returned stream is buffered by the environment. If the
  +     * buffer size is -1 then the complete output is buffered.
  +     * If the buffer size is 0, no buffering takes place.
  +     * This method replaces {@link #getOutputStream()}.
  +     */
  +    public OutputStream getOutputStream(int bufferSize) 
  +    throws IOException {
  +        if (bufferSize == -1) {
  +            if (this.secureOutputStream == null) {
  +                this.secureOutputStream = new BufferedOutputStream(this.outputStream);
  +            }
  +            return this.secureOutputStream;
  +        } else if (bufferSize == 0) {
  +            return this.outputStream;
  +        } else {
  +            this.outputStream = new java.io.BufferedOutputStream(this.outputStream, bufferSize);
  +            return this.outputStream;
  +        }            
       }
   
       /**
  @@ -448,24 +469,14 @@
        * a higher chance to produce clean output if the pipeline that raised
        * the error has already output some data.
        *
  -     * @deprecated This is obsoleted by {@link #resetResponse}
        * @return true if the response was successfully reset
       */
       public boolean tryResetResponse() {
  -        this.resetResponse();
  -        return true;
  -    }
  -
  -    /**
  -     * Reset the response. This allows error handlers to have
  -     * a higher chance to produce clean output if the pipeline that raised
  -     * the error has already output some data.
  -     *
  -     */
  -    public void resetResponse() {
           if (this.secureOutputStream != null) {
               this.secureOutputStream.clearBuffer();
  +            return true;
           }
  +        return false;
       }
   
       /**
  
  
  
  1.14      +13 -10    xml-cocoon2/src/java/org/apache/cocoon/environment/Environment.java
  
  Index: Environment.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/Environment.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Environment.java	12 Sep 2002 14:14:36 -0000	1.13
  +++ Environment.java	13 Sep 2002 06:46:29 -0000	1.14
  @@ -166,10 +166,20 @@
   
       /**
        * Get the output stream where to write the generated resource.
  +     * @deprecated Use {@link #getOutputStream(int)} instead.
        */
       OutputStream getOutputStream() throws IOException;
   
       /**
  +     * Get the output stream where to write the generated resource.
  +     * The returned stream is buffered by the environment. If the
  +     * buffer size is -1 then the complete output is buffered.
  +     * If the buffer size is 0, no buffering takes place.
  +     * This method replaces {@link #getOutputStream()}.
  +     */
  +    OutputStream getOutputStream(int bufferSize) throws IOException;
  +
  +    /**
        * Get the underlying object model
        */
       Map getObjectModel();
  @@ -213,7 +223,7 @@
        * if no object is bound under the name.
        *
        * @param name                a string specifying the name of the object
  -     * @return                        the object with the specified name
  +     * @return                    the object with the specified name
        */
       Object getAttribute(String name);
   
  @@ -238,19 +248,12 @@
        * Reset the response if possible. This allows error handlers to have
        * a higher chance to produce clean output if the pipeline that raised
        * the error has already output some data.
  +     * If a buffered output stream is used, resetting is always successful.
        *
  -     * @deprecated This is obsoleted by {@link #resetResponse}
        * @return true if the response was successfully reset
        */
       boolean tryResetResponse();
   
  -    /**
  -     * Reset the response. This allows error handlers to have
  -     * a higher chance to produce clean output if the pipeline that raised
  -     * the error has already output some data.
  -     *
  -     */
  -    void resetResponse();
   
       /**
        * Commit the response
  
  
  
  1.246     +6 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.245
  retrieving revision 1.246
  diff -u -r1.245 -r1.246
  --- changes.xml	11 Sep 2002 12:44:09 -0000	1.245
  +++ changes.xml	13 Sep 2002 06:46:29 -0000	1.246
  @@ -40,6 +40,11 @@
    </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="CZ" type="add">
  +   Added configurable buffering of the output. This removes all the problems
  +   with error handler and already committed responses etc. A new pipeline
  +   parameter "outputBufferSize" controlls the behaviour.
  +  </action>
     <action dev="SW" type="fix">
       AbstractServerPages used static fields for dependency tracking, which caused
       either non-modified XSPs to be recompiled, or modified XSPs not to be recompiled.
  
  
  
  1.7       +20 -5     xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
  
  Index: AbstractCachingProcessingPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractCachingProcessingPipeline.java	9 Sep 2002 12:00:41 -0000	1.6
  +++ AbstractCachingProcessingPipeline.java	13 Sep 2002 06:46:29 -0000	1.7
  @@ -204,7 +204,7 @@
               return super.processXMLPipeline( environment );
           } else if (this.cachedResponse != null && this.completeResponseIsCached)
{
               try {
  -                final OutputStream outputStream = environment.getOutputStream();
  +                final OutputStream outputStream = environment.getOutputStream(0);
                   if (this.cachedResponse.length > 0) {
                       environment.setContentLength(this.cachedResponse.length);
                       outputStream.write(this.cachedResponse);
  @@ -227,11 +227,15 @@
                   this.getLogger().debug("Caching content for further requests of '" + environment.getURI()
+ "'.");
               }
               try {
  -                OutputStream os = environment.getOutputStream();
  +                OutputStream os = null;
  +                
                   if ( this.cacheCompleteResponse ) {
  -                    os = new CachingOutputStream( os );
  +                    os = new CachingOutputStream( environment.getOutputStream(this.outputBufferSize)
);
                   }
                   if ( super.serializer != super.lastConsumer ) {
  +                    if (os == null) {
  +                        os = environment.getOutputStream(this.outputBufferSize);
  +                    }
                       // internal processing
                       if ( this.xmlDeserializer != null ) {
                           this.xmlDeserializer.deserialize(this.cachedResponse);
  @@ -240,6 +244,9 @@
                       }
                   } else {
                       if (this.serializer.shouldSetContentLength()) {
  +                        if (os == null) {
  +                            os = environment.getOutputStream(0);
  +                        }
                           // set the output stream
                           ByteArrayOutputStream baos = new ByteArrayOutputStream();
                           this.serializer.setOutputStream(baos);
  @@ -254,6 +261,9 @@
                           environment.setContentLength(data.length);
                           os.write(data);
                       } else {
  +                        if (os == null) {
  +                            os = environment.getOutputStream(this.outputBufferSize);
  +                        }
                           // set the output stream
                           this.serializer.setOutputStream( os );
                           // execute the pipeline:
  @@ -598,7 +608,7 @@
       throws ProcessingException {
           try {
               boolean usedCache = false;
  -            OutputStream outputStream = environment.getOutputStream();
  +            OutputStream outputStream = null;
               SourceValidity readerValidity = null;
               PipelineCacheKey pcKey = null;
   
  @@ -658,6 +668,7 @@
                           byte[] response = cachedObject.getResponse();
                           if (response.length > 0) {
                               usedCache = true;
  +                            outputStream = environment.getOutputStream(0);
                               environment.setContentLength(response.length);
                               outputStream.write(response);
                           }
  @@ -688,12 +699,16 @@
                           }
                       }
                       if (readerValidity != null) {
  +                        outputStream = environment.getOutputStream(this.outputBufferSize);
                           outputStream = new CachingOutputStream(outputStream);
                       } else {
                           pcKey = null;
                       }
                   }
   
  +                if (outputStream == null) {
  +                    outputStream = environment.getOutputStream(this.outputBufferSize);
  +                }
                   super.processReader( environment, outputStream );
   
                   // store the response
  
  
  
  1.37      +2 -2      xml-cocoon2/src/java/org/apache/cocoon/Cocoon.java
  
  Index: Cocoon.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/Cocoon.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- Cocoon.java	12 Sep 2002 14:14:36 -0000	1.36
  +++ Cocoon.java	13 Sep 2002 06:46:29 -0000	1.37
  @@ -591,7 +591,7 @@
               return result;
           } catch (Exception any) {
               // reset response on error
  -            environment.resetResponse();
  +            environment.tryResetResponse();
               throw any;
           } finally {
               if (this.getLogger().isDebugEnabled()) {
  
  
  

----------------------------------------------------------------------
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


Mime
View raw message