Hi people, as we have a default Buffer of 8192 byte in the AbstractTextSerializer sometimes it takes very long until any result is visible in the browser. Therefore I introduced an "OutputFlusher" which flushes the BufferedOutputStream per default every 500 ms. Now the pageheader is shown immediately, independent of how long it takes to fill 8192 byte. I hope this helps. I prepared AbstractTextSerializer to get the time in milliseconds from cocoon.xconf, the name is "flush-time", default is 500, values below 100 are set to 100, value of 0 means no flushing. But I have no idea how to setup, what to put in cocoon.xconf. Do I have to put AbstractTextSerializer into cocoon.roles???
Attached the diff and a new class for cocoon/serialization Regards, Michael
package org.apache.cocoon.serialization; import java.io.BufferedOutputStream; import java.io.IOException; public class OutputFlusher extends java.lang.Thread { private BufferedOutputStream bos; private int flushTime; public OutputFlusher(BufferedOutputStream bos, int flushTime) { this.bos = bos; this.flushTime = flushTime; start(); } public void run() { while(bos != null) { try { bos.flush(); sleep(flushTime); } catch(InterruptedException ie) {} catch(IOException ioe) { break; } } } }
--- AbstractTextSerializer.java.orig Thu Jan 17 11:15:33 2002 +++ AbstractTextSerializer.java Thu Jan 17 15:40:27 2002 @@ -12,6 +12,7 @@ import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.Constants; import org.apache.cocoon.caching.CacheValidity; import org.apache.cocoon.caching.Cacheable; @@ -80,6 +81,22 @@ private NamespaceAsAttributes namespacePipe; /** + * The parameter from cocoon.xconf for flushing the BufferedOutputStream + */ + private final String FLUSH_TIME_ID = "flush-time"; + + /** + * Per default flushing every 500 ms + */ + private final int FLUSH_TIME_DEFAULT = 500; + private int flushTime = FLUSH_TIME_DEFAULT; + + /** + * flushTime less than 100 eats up too much performance + */ + private final int FLUSH_TIME_MINIMUM = 100; + + /** * Interpose namespace pipe if needed. */ public void setConsumer(XMLConsumer consumer) { @@ -139,6 +156,7 @@ */ BufferedOutputStream streamBuffer = new BufferedOutputStream(out, outputBufferSize); super.setOutputStream(streamBuffer); + if(flushTime >= FLUSH_TIME_MINIMUM) new OutputFlusher(streamBuffer, +flushTime); } /** @@ -205,6 +223,10 @@ } catch(Exception e) { getLogger().warn("Cannot know if transformer needs namespaces attributes - assuming NO.", e); } + + Parameters params = Parameters.fromConfiguration(conf); + flushTime = params.getParameterAsInteger(FLUSH_TIME_ID, FLUSH_TIME_DEFAULT); + if(flushTime > 0 && flushTime < FLUSH_TIME_MINIMUM) flushTime = +FLUSH_TIME_MINIMUM; } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]