jfarcand 2004/11/22 08:31:04 Modified: catalina/src/share/org/apache/catalina/valves ByteBufferAccessLogValve.java Log: Re-add the writer thread since the valve doesn't work properly without it. This is temporary. Revision Changes Path 1.4 +105 -3 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/ByteBufferAccessLogValve.java Index: ByteBufferAccessLogValve.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/ByteBufferAccessLogValve.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ByteBufferAccessLogValve.java 22 Nov 2004 15:16:24 -0000 1.3 +++ ByteBufferAccessLogValve.java 22 Nov 2004 16:31:04 -0000 1.4 @@ -62,7 +62,7 @@ public final class ByteBufferAccessLogValve extends ValveBase - implements Lifecycle { + implements Lifecycle, Runnable { // ----------------------------------------------------------- Constructors @@ -111,7 +111,7 @@ * The descriptive information about this implementation. */ protected static final String info = - "org.apache.catalina.valves.ByteBufferAccessLogValve/1.0"; + "org.apache.catalina.valves.AccessLogValve/1.0"; /** @@ -277,6 +277,12 @@ /** + * The background writerThread. + */ + private Thread writerThread = null; + + + /** * The background writerThread completion semaphore. */ private boolean threadDone = false; @@ -314,6 +320,12 @@ /** + * The interval (in seconds) between writting the log. + */ + private int writeInterval = 5 * 60; + + + /** * Per-Thread <code>StringBuffer</code> used to store the log. */ static private ThreadLocal stringBufferThreadLocal = new ThreadLocal(){ @@ -355,6 +367,21 @@ } + /** + * Return writerThread interval (seconds) + */ + public int getWriterInterval() { + return this.writeInterval; + } + + + /** + * Set writerthread interval (seconds) + */ + public void setWriterInterval(int t) { + this.writeInterval = t; + } + // ------------------------------------------------------------- Properties @@ -953,6 +980,8 @@ dateStamp = dateFormatter.format(new Date()); open(); + + threadStart(); } @@ -975,6 +1004,9 @@ started = false; close(); + + threadStop(); + } @@ -984,6 +1016,76 @@ * throwables will be caught and logged. */ public void backgroundProcess() { - log(); + // log(); + } + + + /** + * The background writerThread that checks for write the log. + */ + public void run() { + + // Loop until the termination semaphore is set + while (!threadDone) { + threadWait(); + log(); + } } + + + /** + * Sleep for the duration specified by the <code>writeInterval</code> + * property. + */ + private void threadWait() { + + synchronized(lock){ + try { + lock.wait(writeInterval * 1000L); + } catch (InterruptedException e) { + ; + } + } + + } + + + /** + * Start the background writerThread that will periodically write access log + */ + private void threadStart() { + + if (writerThread != null) + return; + + threadDone = false; + String threadName = "AccessLogWriter"; + writerThread = new Thread(this, threadName); + writerThread.setDaemon(true); + writerThread.start(); + + } + + + /** + * Stop the background writerThread that is periodically write logs + */ + private void threadStop() { + + if (writerThread == null) + return; + + threadDone = true; + writerThread.interrupt(); + try { + writerThread.join(); + } catch (InterruptedException e) { + ; + } + + writerThread = null; + + } + + }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]