cvs commit: ant/src/main/org/apache/tools/ant DemuxOutputStream.java

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

cvs commit: ant/src/main/org/apache/tools/ant DemuxOutputStream.java

Steve Loughran
stevel      2005/05/02 11:02:15

  Modified:    src/main/org/apache/tools/ant DemuxOutputStream.java
  Log:
  Move to WeakHashMap to reduce resource leakage on long-lived many-exec runs
 
  Revision  Changes    Path
  1.25      +37 -37    ant/src/main/org/apache/tools/ant/DemuxOutputStream.java
 
  Index: DemuxOutputStream.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DemuxOutputStream.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DemuxOutputStream.java 9 Mar 2004 16:47:59 -0000 1.24
  +++ DemuxOutputStream.java 2 May 2005 18:02:15 -0000 1.25
  @@ -21,19 +21,18 @@
   import java.io.IOException;
   import java.io.OutputStream;
   import java.util.Hashtable;
  +import java.util.WeakHashMap;
   
   /**
  - * Logs content written by a thread and forwards the buffers onto the
  - * project object which will forward the content to the appropriate
  - * task.
  + * Logs content written by a thread and forwards the buffers onto the project object which will forward the content to
  + * the appropriate task.
    *
    * @since 1.4
    */
   public class DemuxOutputStream extends OutputStream {
   
       /**
  -     * A data class to store information about a buffer. Such information
  -     * is stored on a per-thread basis.
  +     * A data class to store information about a buffer. Such information is stored on a per-thread basis.
        */
       private static class BufferInfo {
           /**
  @@ -42,26 +41,36 @@
           private ByteArrayOutputStream buffer;
   
           /**
  -         * Indicates we have just seen a carriage return. It may be part of
  -         * a crlf pair or a single cr invoking processBuffer twice.
  +         * Indicates we have just seen a carriage return. It may be part of a crlf pair or a single cr invoking
  +         * processBuffer twice.
            */
  -         private boolean crSeen = false;
  +        private boolean crSeen = false;
       }
   
  -    /** Maximum buffer size. */
  +    /**
  +     * Maximum buffer size.
  +     */
       private static final int MAX_SIZE = 1024;
   
  -    /** Initial buffer size. */
  +    /**
  +     * Initial buffer size.
  +     */
       private static final int INTIAL_SIZE = 132;
   
  -    /** Carriage return */
  +    /**
  +     * Carriage return
  +     */
       private static final int CR = 0x0d;
   
  -    /** Linefeed */
  +    /**
  +     * Linefeed
  +     */
       private static final int LF = 0x0a;
   
  -    /** Mapping from thread to buffer (Thread to BufferInfo). */
  -    private Hashtable buffers = new Hashtable();
  +    /**
  +     * Mapping from thread to buffer (Thread to BufferInfo).
  +     */
  +    private WeakHashMap buffers = new WeakHashMap();
   
       /**
        * The project to send output to.
  @@ -76,12 +85,10 @@
       /**
        * Creates a new instance of this class.
        *
  -     * @param project The project instance for which output is being
  -     *                demultiplexed. Must not be <code>null</code>.
  -     * @param isErrorStream <code>true</code> if this is the error string,
  -     *                      otherwise a normal output stream. This is
  -     *                      passed to the project so it knows
  -     *                      which stream it is receiving.
  +     * @param project       The project instance for which output is being demultiplexed. Must not be
  +     *                      <code>null</code>.
  +     * @param isErrorStream <code>true</code> if this is the error string, otherwise a normal output stream. This is
  +     *                      passed to the project so it knows which stream it is receiving.
        */
       public DemuxOutputStream(Project project, boolean isErrorStream) {
           this.project = project;
  @@ -125,15 +132,15 @@
        */
       private void removeBuffer() {
           Thread current = Thread.currentThread();
  -        buffers.remove (current);
  +        buffers.remove(current);
       }
   
       /**
  -     * Writes the data to the buffer and flushes the buffer if a line
  -     * separator is detected or if the buffer has reached its maximum size.
  +     * Writes the data to the buffer and flushes the buffer if a line separator is detected or if the buffer has reached
  +     * its maximum size.
        *
        * @param cc data to log (byte).
  -     * @exception IOException if the data cannot be written to the stream
  +     * @throws IOException if the data cannot be written to the stream
        */
       public void write(int cc) throws IOException {
           final byte c = (byte) cc;
  @@ -161,9 +168,7 @@
       /**
        * Converts the buffer to a string and sends it to the project.
        *
  -     * @param buffer the ByteArrayOutputStream used to collect the output
  -     * until a line separator is seen.
  -     *
  +     * @param buffer the ByteArrayOutputStream used to collect the output until a line separator is seen.
        * @see Project#demuxOutput(String,boolean)
        */
       protected void processBuffer(ByteArrayOutputStream buffer) {
  @@ -175,9 +180,7 @@
       /**
        * Converts the buffer to a string and sends it to the project.
        *
  -     * @param buffer the ByteArrayOutputStream used to collect the output
  -     * until a line separator is seen.
  -     *
  +     * @param buffer the ByteArrayOutputStream used to collect the output until a line separator is seen.
        * @see Project#demuxOutput(String,boolean)
        */
       protected void processFlush(ByteArrayOutputStream buffer) {
  @@ -189,8 +192,7 @@
       /**
        * Equivalent to flushing the stream.
        *
  -     * @exception IOException if there is a problem closing the stream.
  -     *
  +     * @throws IOException if there is a problem closing the stream.
        * @see #flush
        */
       public void close() throws IOException {
  @@ -199,10 +201,9 @@
       }
   
       /**
  -     * Writes all remaining data in the buffer associated
  -     * with the current thread to the project.
  +     * Writes all remaining data in the buffer associated with the current thread to the project.
        *
  -     * @exception IOException if there is a problem flushing the stream.
  +     * @throws IOException if there is a problem flushing the stream.
        */
       public void flush() throws IOException {
           BufferInfo bufferInfo = getBufferInfo();
  @@ -214,10 +215,9 @@
       /**
        * Write a block of characters to the output stream
        *
  -     * @param b the array containing the data
  +     * @param b   the array containing the data
        * @param off the offset into the array where data starts
        * @param len the length of block
  -     *
        * @throws IOException if the data cannot be written into the stream.
        */
       public void write(byte[] b, int off, int len) throws IOException {
 
 
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|

RE: cvs commit: ant/src/main/org/apache/tools/ant DemuxOutputStream.java

Dominique Devienne
> From: [hidden email] [mailto:[hidden email]]
>   - * Logs content written by a thread and forwards the buffers onto
the
>   - * project object which will forward the content to the appropriate
>   - * task.
>   + * Logs content written by a thread and forwards the buffers onto
the
> project object which will forward the content to
>   + * the appropriate task.

I know I'm nitpicking here, and I apologize for it, but aren't you
creating lines over 80 chars with this reformatting Steve? I picked just
one example here. Is this an IDE configuration issue? --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: cvs commit: ant/src/main/org/apache/tools/ant DemuxOutputStream.java

trelony
I think it is an issue with big screens - 80 characters take about half of
my monitor, so at work everybody is using 105 character limit.

- Alexey.

On 5/2/05, Dominique Devienne <[hidden email]> wrote:

>
> > From: [hidden email] [mailto:[hidden email]]
> > - * Logs content written by a thread and forwards the buffers onto
> the
> > - * project object which will forward the content to the appropriate
> > - * task.
> > + * Logs content written by a thread and forwards the buffers onto
> the
> > project object which will forward the content to
> > + * the appropriate task.
>
> I know I'm nitpicking here, and I apologize for it, but aren't you
> creating lines over 80 chars with this reformatting Steve? I picked just
> one example here. Is this an IDE configuration issue? --DD
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Alexey N. Solofnenko mailto:trelony at gmail.com <http://gmail.com>
home: http://trelony.cjb.net/
Pleasant Hill, CA (GMT-8 hours usually)
Reply | Threaded
Open this post in threaded view
|

RE: cvs commit: ant/src/main/org/apache/tools/ant DemuxOutputStream.java

Dominique Devienne
In reply to this post by Steve Loughran
> From: Alexey Solofnenko [mailto:[hidden email]]
>
> I think it is an issue with big screens - 80 characters take about
half of
> my monitor, so at work everybody is using 105 character limit.
>
> On 5/2/05, Dominique Devienne <[hidden email]> wrote:
> > I know I'm nitpicking here, and I apologize for it, but aren't you
> > creating lines over 80 chars with this reformatting Steve? I picked
just
> > one example here. Is this an IDE configuration issue? --DD

Hmmm, looks like Ant's checkstyle config uses 100 chars for the line
length. I vaguely remember this coming up a while back. I personally
like to have 2 files side by side on my screen, and going beyond 80
chars makes the lines wrap in this case. I personally just don't view a
commit changing Javadoc written to the 80 char per line standard changed
to longer line an improvement. I'm not using an IDE that hides Javadocs
by default though, so maybe I'm alone on this... --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: cvs commit: ant/src/main/org/apache/tools/ant DemuxOutputStream.java

Matt Benson
In reply to this post by Steve Loughran
--- Dominique Devienne <[hidden email]> wrote:
> I
> personally just don't view a
> commit changing Javadoc written to the 80 char per
> line standard changed
> to longer line an improvement. I'm not using an IDE
> that hides Javadocs
> by default though, so maybe I'm alone on this...
> --DD
>
If it makes you feel better, it doesn't look that
great to me either.

-Matt
 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [hidden email]
> For additional commands, e-mail:
> [hidden email]
>
>

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: cvs commit: ant/src/main/org/apache/tools/ant DemuxOutputStream.java

Steve Loughran
In reply to this post by Steve Loughran
[hidden email] wrote:

> stevel      2005/05/02 11:02:15
>
>   Modified:    src/main/org/apache/tools/ant DemuxOutputStream.java
>   Log:
>   Move to WeakHashMap to reduce resource leakage on long-lived many-exec runs
>  
>   Revision  Changes    Path
>   1.25      +37 -37    ant/src/main/org/apache/tools/ant/DemuxOutputStream.java
>  
>   Index: DemuxOutputStream.java
>   ===================================================================
>   RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DemuxOutputStream.java,v
>   retrieving revision 1.24
>   retrieving revision 1.25
>   diff -u -r1.24 -r1.25
>   --- DemuxOutputStream.java 9 Mar 2004 16:47:59 -0000 1.24
>   +++ DemuxOutputStream.java 2 May 2005 18:02:15 -0000 1.25
>   @@ -21,19 +21,18 @@
>    import java.io.IOException;
>    import java.io.OutputStream;
>    import java.util.Hashtable;
>   +import java.util.WeakHashMap;
>    
>    /**
>   - * Logs content written by a thread and forwards the buffers onto the
>   - * project object which will forward the content to the appropriate
>   - * task.
>   + * Logs content written by a thread and forwards the buffers onto the project object which will forward the content to
>   + * the appropriate task.
>     *

I dont remember all the javadoc fixup; I just edited one bit ... I think
the IDE got over-excited or something.

Shall I roll back this commit and retry without such a big diff?

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: cvs commit: ant/src/main/org/apache/tools/ant DemuxOutputStream.java

Steve Loughran
In reply to this post by Dominique Devienne
Dominique Devienne wrote:

>>From: [hidden email] [mailto:[hidden email]]
>>  - * Logs content written by a thread and forwards the buffers onto
>
> the
>
>>  - * project object which will forward the content to the appropriate
>>  - * task.
>>  + * Logs content written by a thread and forwards the buffers onto
>
> the
>
>>project object which will forward the content to
>>  + * the appropriate task.
>
>
> I know I'm nitpicking here, and I apologize for it, but aren't you
> creating lines over 80 chars with this reformatting Steve? I picked just
> one example here. Is this an IDE configuration issue? --DD


you arent nitpicking; 80 lines is the ant rule; 100 lines is another
project.

I wasnt expecting any javadoc changes to go in; will roll back.

-steve

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]