User: user57  
  Date: 02/02/12 21:49:06

  Modified:    src/main/org/jboss/mq SpyTextMessage.java
  Log:
   o fix for bug [ #486401 ] send of empty text message hangs
     as well as test cases (though if this breaks again it will only
     hand the testsuite...)
  
  Revision  Changes    Path
  1.9       +57 -44    jbossmq/src/main/org/jboss/mq/SpyTextMessage.java
  
  Index: SpyTextMessage.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/SpyTextMessage.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SpyTextMessage.java       2 Feb 2002 03:54:19 -0000       1.8
  +++ SpyTextMessage.java       13 Feb 2002 05:49:06 -0000      1.9
  @@ -7,41 +7,46 @@
   package org.jboss.mq;
   
   import java.io.Externalizable;
  +import java.io.ObjectOutput;
  +import java.io.ObjectInput;
  +import java.io.IOException;
   
   import java.util.ArrayList;
  +
   import javax.jms.JMSException;
   import javax.jms.MessageNotWriteableException;
  -
   import javax.jms.TextMessage;
   
   /**
  - *  This class implements javax.jms.TextMessage
  + * This class implements javax.jms.TextMessage
    *
  - * @author     Norbert Lataille ([EMAIL PROTECTED])
  - * @created    August 16, 2001
  - * @version    $Revision: 1.8 $
  + * @author Norbert Lataille ([EMAIL PROTECTED])
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  + * @created August 16, 2001
  + * @version $Revision: 1.9 $
    */
   public class SpyTextMessage
  -       extends SpyMessage
  -       implements Cloneable, TextMessage, Externalizable
  +   extends SpyMessage
  +   implements Cloneable, TextMessage, Externalizable
   {
  -
      // Attributes ----------------------------------------------------
   
  -   String           content = null;
  +   String content;
   
      private final static long serialVersionUID = 235726945332013953L;
  +   
      private final static int chunkSize = 16384;
   
      // Public --------------------------------------------------------
   
  -   public void setText( String string )
  +   public void setText(String string)
         throws JMSException
      {
  -      if ( header.msgReadOnly )
  +      if (header.msgReadOnly)
         {
  -         throw new MessageNotWriteableException( "Cannot set the content" );
  +         throw new MessageNotWriteableException("Cannot set the content; message is 
read-only");
         }
  +      
         content = string;
      }
   
  @@ -62,17 +67,18 @@
         throws JMSException
      {
         SpyTextMessage result = MessagePool.getTextMessage();
  -      result.copyProps( this );
  +      result.copyProps(this);
         result.content = this.content;
         return result;
      }
   
  -   public void readExternal( java.io.ObjectInput in )
  -      throws java.io.IOException, ClassNotFoundException
  +   public void readExternal(ObjectInput in)
  +      throws IOException, ClassNotFoundException
      {
  -      super.readExternal( in );
  +      super.readExternal(in);
         byte type = in.readByte();
  -      if ( type == NULL )
  +      
  +      if (type == NULL)
         {
            content = null;
         }
  @@ -84,46 +90,59 @@
            // a StringBuffer that can hold all chunks, read the chunks
            // into the buffer and set 'content' accordingly
            int chunksToRead = in.readInt();
  -      int bufferSize = chunkSize * chunksToRead;
  -      if(chunksToRead <= 1)
  +         int bufferSize = chunkSize * chunksToRead;
  +
  +         // special handling for single chunk
  +      if (chunksToRead == 1)
            {
  -            /* The text size is likely to be much smaller than the chunkSize
  -               so set bufferSize to the min of the input stream available
  -               and the maximum buffer size. Since the input stream
  -               available() can be <= 0 we check for that and default to
  -               a small msg size of 256 bytes.
  -            */
  +            // The text size is likely to be much smaller than the chunkSize
  +            // so set bufferSize to the min of the input stream available
  +            // and the maximum buffer size. Since the input stream
  +            // available() can be <= 0 we check for that and default to
  +            // a small msg size of 256 bytes.
  +
               int inSize = in.available();
  -            if( inSize <= 0 )
  +            if (inSize <= 0) {
                  inSize = 256;
  +            }
  +            
               bufferSize = Math.min(inSize, bufferSize);
            }
  +
  +         // read off all of the chunks
            StringBuffer sb = new StringBuffer(bufferSize);
  +         
            for (int i = 0; i < chunksToRead; i++)
            {
  -            sb.append( in.readUTF() );
  +            sb.append(in.readUTF());
            }
  +         
            content = sb.toString();
         }
      }
   
  -   public void writeExternal( java.io.ObjectOutput out )
  -      throws java.io.IOException
  +   public void writeExternal(ObjectOutput out)
  +      throws IOException
      {
  -      super.writeExternal( out );
  -      if ( content == null )
  +      super.writeExternal(out);
  +      
  +      if (content == null)
         {
  -         out.writeByte( NULL );
  +         out.writeByte(NULL);
         }
         else
         {
            // apply workaround for string > 64K bug in jdk's 1.3.*
   
            // Split content into chunks of size 'chunkSize' and assemble
  -         // the pieces into a Vector ...
  +         // the pieces into a List ...
  +
  +         // FIXME: could calculate the number of chunks first, then
  +         //        write as we chunk for efficiency
  +         
            ArrayList v = new ArrayList();
            int contentLength = content.length();
  -
  +         
            while (contentLength > 0)
            {
               int beginCopy = (v.size()) * chunkSize;
  @@ -138,11 +157,12 @@
   
            // Write out the type (OBJECT), the no. of chunks and finally
            // all chunks that have been assembled previously
  -         out.writeByte( OBJECT );
  +         out.writeByte(OBJECT);
            out.writeInt(v.size());
  +         
            for (int i = 0; i < v.size(); i++)
            {
  -            out.writeUTF( (String)v.get(i) );
  +            out.writeUTF((String)v.get(i));
            }
         }
      }
  @@ -151,13 +171,6 @@
   
      public String toString()
      {
  -      try
  -      {
  -         return "TextMessage@" + getText();
  -      }
  -      catch ( JMSException e )
  -      {
  -         return "toString() failed !";
  -      }
  +      return "TextMessage@" + content;
      }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to