[JBoss-dev] CVS update: jbossmq/src/main/org/jboss/mq SpyTextMessage.java
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 ChangesPath 1.9 +57 -44jbossmq/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 - 1.8 +++ SpyTextMessage.java 13 Feb 2002 05:49:06 - 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]) - * @createdAugust 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(); } } -
[JBoss-dev] CVS update: jbossmq/src/main/org/jboss/mq SpyTextMessage.java
User: lqd Date: 02/01/14 07:25:36 Modified:src/main/org/jboss/mq Tag: Branch_2_4 SpyTextMessage.java Log: safeguard for TextMessages with a 'null' body Revision ChangesPath No revision No revision 1.2.2.7 +7 -1 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.2.2.6 retrieving revision 1.2.2.7 diff -u -r1.2.2.6 -r1.2.2.7 --- SpyTextMessage.java 2001/12/13 21:29:21 1.2.2.6 +++ SpyTextMessage.java 2002/01/14 15:25:35 1.2.2.7 @@ -16,7 +16,7 @@ * * @author Norbert Lataille ([EMAIL PROTECTED]) * @createdAugust 16, 2001 - * @version$Revision: 1.2.2.6 $ + * @version$Revision: 1.2.2.7 $ */ public class SpyTextMessage extends SpyMessage @@ -76,6 +76,9 @@ */ final public boolean isVersion2() { + if( content == null ) + return false; + // This is very conservative but cheap int length = content.length(); boolean canWriteUTF = length MAX_UTF_LENGTH; @@ -180,3 +183,6 @@ } } } +/* +vim:tabstop=3:expandtab:shiftwidth=3 +*/ ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
[JBoss-dev] CVS update: jbossmq/src/main/org/jboss/mq SpyTextMessage.java
User: starksm Date: 01/11/03 22:53:32 Modified:src/main/org/jboss/mq SpyTextMessage.java Log: Since the ObjectInput.available() may be = 0 check for this and default to a small message size of 256 bytes. Revision ChangesPath 1.6 +52 -20jbossmq/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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SpyTextMessage.java 2001/11/02 23:06:46 1.5 +++ SpyTextMessage.java 2001/11/04 06:53:31 1.6 @@ -18,11 +18,12 @@ * * @author Norbert Lataille ([EMAIL PROTECTED]) * @createdAugust 16, 2001 - * @version$Revision: 1.5 $ + * @version$Revision: 1.6 $ */ public class SpyTextMessage extends SpyMessage - implements Cloneable, TextMessage, Externalizable { + implements Cloneable, TextMessage, Externalizable +{ // Attributes @@ -34,26 +35,31 @@ // Public public void setText( String string ) - throws JMSException { - if ( header.msgReadOnly ) { + throws JMSException + { + if ( header.msgReadOnly ) + { throw new MessageNotWriteableException( Cannot set the content ); } content = string; } public String getText() - throws JMSException { + throws JMSException + { return content; } public void clearBody() - throws JMSException { + throws JMSException + { content = null; super.clearBody(); } public SpyMessage myClone() - throws JMSException { + throws JMSException + { SpyTextMessage result = new SpyTextMessage(); result.copyProps( this ); result.content = this.content; @@ -61,12 +67,16 @@ } public void readExternal( java.io.ObjectInput in ) - throws java.io.IOException, ClassNotFoundException { + throws java.io.IOException, ClassNotFoundException + { super.readExternal( in ); byte type = in.readByte(); - if ( type == NULL ) { + if ( type == NULL ) + { content = null; - } else { + } + else + { // apply workaround for string 64K bug in jdk's 1.3.* // Read the no. of chunks this message is split into, allocate @@ -75,9 +85,21 @@ int chunksToRead = in.readInt(); int bufferSize = chunkSize * chunksToRead; if(chunksToRead = 1) -bufferSize = Math.min(in.available(), bufferSize); + { +/* 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 ) + inSize = 256; +bufferSize = Math.min(inSize, bufferSize); + } StringBuffer sb = new StringBuffer(bufferSize); - for (int i = 0; i chunksToRead; i++) { + for (int i = 0; i chunksToRead; i++) + { sb.append( in.readUTF() ); } content = sb.toString(); @@ -85,11 +107,15 @@ } public void writeExternal( java.io.ObjectOutput out ) - throws java.io.IOException { + throws java.io.IOException + { super.writeExternal( out ); - if ( content == null ) { + if ( content == null ) + { out.writeByte( NULL ); - } else { + } + else + { // apply workaround for string 64K bug in jdk's 1.3.* // Split content into chunks of size 'chunkSize' and assemble @@ -97,7 +123,8 @@ ArrayList v = new ArrayList(); int contentLength = content.length(); - while (contentLength 0) { + while (contentLength 0) + { int beginCopy = (v.size()) * chunkSize; int endCopy = contentLength = chunkSize ? beginCopy + contentLength : beginCopy + chunkSize; @@ -112,7 +139,8 @@ // all chunks that have been assembled previously out.writeByte( OBJECT ); out.writeInt(v.size()); - for (int i = 0; i v.size(); i++) { + for (int i = 0; i v.size(); i++) + { out.writeUTF( (String)v.get(i) ); }
[JBoss-dev] CVS update: jbossmq/src/main/org/jboss/mq SpyTextMessage.java
User: weave Date: 01/11/02 15:06:47 Modified:src/main/org/jboss/mq SpyTextMessage.java Log: Modified the readExternl() method to check the number of available chunks. If there is only one chuck available then the initial capacity of the StringBuffer is set to the number of available bytes. This was necessary to avoid small messages from allocating large buffers. In addition when testing with the IBM JDK the toString() method of the StringBuffer class appeared to implement a copy-on-write char[] sharing. This meant that if a large buffer was allocate it would not be reduced to the message size since the StringBuffer was not modified after the toString() call. I'm still concerned that if the last chunk is realitively small then there may be a fair amount of wasted space. This would become a smaller precent as the number of chunks grow. Revision ChangesPath 1.5 +5 -2 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.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SpyTextMessage.java 2001/10/28 04:07:34 1.4 +++ SpyTextMessage.java 2001/11/02 23:06:46 1.5 @@ -18,7 +18,7 @@ * * @author Norbert Lataille ([EMAIL PROTECTED]) * @createdAugust 16, 2001 - * @version$Revision: 1.4 $ + * @version$Revision: 1.5 $ */ public class SpyTextMessage extends SpyMessage @@ -73,7 +73,10 @@ // a StringBuffer that can hold all chunks, read the chunks // into the buffer and set 'content' accordingly int chunksToRead = in.readInt(); - StringBuffer sb = new StringBuffer(chunkSize * chunksToRead); + int bufferSize = chunkSize * chunksToRead; + if(chunksToRead = 1) +bufferSize = Math.min(in.available(), bufferSize); + StringBuffer sb = new StringBuffer(bufferSize); for (int i = 0; i chunksToRead; i++) { sb.append( in.readUTF() ); } ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
[JBoss-dev] CVS update: jbossmq/src/main/org/jboss/mq SpyTextMessage.java
User: starksm Date: 01/09/30 23:31:58 Modified:src/main/org/jboss/mq Tag: Branch_2_4 SpyTextMessage.java Log: Undo the hacky fix for bug 462253 Revision ChangesPath No revision No revision 1.2.2.3 +4 -39 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.2.2.2 retrieving revision 1.2.2.3 diff -u -r1.2.2.2 -r1.2.2.3 --- SpyTextMessage.java 2001/09/18 21:02:38 1.2.2.2 +++ SpyTextMessage.java 2001/10/01 06:31:58 1.2.2.3 @@ -7,7 +7,6 @@ package org.jboss.mq; import java.io.*; -import java.util.ArrayList; import javax.jms.JMSException; import javax.jms.MessageNotWriteableException; @@ -18,7 +17,7 @@ * * @author Norbert Lataille ([EMAIL PROTECTED]) * @createdAugust 16, 2001 - * @version$Revision: 1.2.2.2 $ + * @version$Revision: 1.2.2.3 $ */ public class SpyTextMessage extends SpyMessage @@ -29,8 +28,7 @@ String content = null; private final static long serialVersionUID = 235726945332013953L; - private final static int chunkSize = 16384; - + // Public public void setText( String string ) @@ -67,17 +65,7 @@ if ( type == NULL ) { content = null; } else { - // apply workaround for string 64K bug in jdk's 1.3.* - - // Read the no. of chunks this message is split into, allocate - // a StringBuffer that can hold all chunks, read the chunks - // into the buffer and set 'content' accordingly - int chunksToRead = in.readInt(); - StringBuffer sb = new StringBuffer(chunkSize * chunksToRead); - for (int i = 0; i chunksToRead; i++) { -sb.append( in.readUTF() ); - } - content = sb.toString(); + content = in.readUTF(); } } @@ -87,31 +75,8 @@ if ( content == 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 ... - ArrayList v = new ArrayList(); - int contentLength = content.length(); - - while (contentLength 0) { -int beginCopy = (v.size()) * chunkSize; -int endCopy = contentLength = chunkSize ? - beginCopy + contentLength : beginCopy + chunkSize; - -String theChunk = content.substring(beginCopy, endCopy); -v.add(theChunk); - -contentLength -= chunkSize; - } - - // Write out the type (OBJECT), the no. of chunks and finally - // all chunks that have been assembled previously out.writeByte( OBJECT ); - out.writeInt(v.size()); - for (int i = 0; i v.size(); i++) { -out.writeUTF( (String)v.get(i) ); - } + out.writeUTF( content ); } } ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
[JBoss-dev] CVS update: jbossmq/src/main/org/jboss/mq SpyTextMessage.java
User: dmaplesden Date: 01/09/18 14:02:38 Modified:src/main/org/jboss/mq Tag: Branch_2_4 SpyTextMessage.java Log: Apply patch #437132 to Branch_2_4 (as requested) Revision ChangesPath No revision No revision 1.2.2.2 +39 -4 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.2.2.1 retrieving revision 1.2.2.2 diff -u -r1.2.2.1 -r1.2.2.2 --- SpyTextMessage.java 2001/08/23 03:57:08 1.2.2.1 +++ SpyTextMessage.java 2001/09/18 21:02:38 1.2.2.2 @@ -7,6 +7,7 @@ package org.jboss.mq; import java.io.*; +import java.util.ArrayList; import javax.jms.JMSException; import javax.jms.MessageNotWriteableException; @@ -17,7 +18,7 @@ * * @author Norbert Lataille ([EMAIL PROTECTED]) * @createdAugust 16, 2001 - * @version$Revision: 1.2.2.1 $ + * @version$Revision: 1.2.2.2 $ */ public class SpyTextMessage extends SpyMessage @@ -28,7 +29,8 @@ String content = null; private final static long serialVersionUID = 235726945332013953L; - + private final static int chunkSize = 16384; + // Public public void setText( String string ) @@ -65,7 +67,17 @@ if ( type == NULL ) { content = null; } else { - content = in.readUTF(); + // apply workaround for string 64K bug in jdk's 1.3.* + + // Read the no. of chunks this message is split into, allocate + // a StringBuffer that can hold all chunks, read the chunks + // into the buffer and set 'content' accordingly + int chunksToRead = in.readInt(); + StringBuffer sb = new StringBuffer(chunkSize * chunksToRead); + for (int i = 0; i chunksToRead; i++) { +sb.append( in.readUTF() ); + } + content = sb.toString(); } } @@ -75,8 +87,31 @@ if ( content == 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 ... + ArrayList v = new ArrayList(); + int contentLength = content.length(); + + while (contentLength 0) { +int beginCopy = (v.size()) * chunkSize; +int endCopy = contentLength = chunkSize ? + beginCopy + contentLength : beginCopy + chunkSize; + +String theChunk = content.substring(beginCopy, endCopy); +v.add(theChunk); + +contentLength -= chunkSize; + } + + // Write out the type (OBJECT), the no. of chunks and finally + // all chunks that have been assembled previously out.writeByte( OBJECT ); - out.writeUTF( content ); + out.writeInt(v.size()); + for (int i = 0; i v.size(); i++) { +out.writeUTF( (String)v.get(i) ); + } } } ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
[JBoss-dev] CVS update: jbossmq/src/main/org/jboss/mq SpyTextMessage.java
User: dmaplesden Date: 01/09/17 14:09:46 Modified:src/main/org/jboss/mq SpyTextMessage.java Log: Apply submitted patch for working around write/read utf limitation in jdk 1.3.* Revision ChangesPath 1.3 +39 -4 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SpyTextMessage.java 2001/08/17 03:04:01 1.2 +++ SpyTextMessage.java 2001/09/17 21:09:46 1.3 @@ -7,6 +7,7 @@ package org.jboss.mq; import java.io.*; +import java.util.ArrayList; import javax.jms.JMSException; import javax.jms.MessageNotWriteableException; @@ -17,7 +18,7 @@ * * @author Norbert Lataille ([EMAIL PROTECTED]) * @createdAugust 16, 2001 - * @version$Revision: 1.2 $ + * @version$Revision: 1.3 $ */ public class SpyTextMessage extends SpyMessage @@ -28,7 +29,8 @@ String content = null; private final static long serialVersionUID = 235726945332013953L; - + private final static int chunkSize = 16384; + // Public public void setText( String string ) @@ -65,7 +67,17 @@ if ( type == NULL ) { content = null; } else { - content = in.readUTF(); + // apply workaround for string 64K bug in jdk's 1.3.* + + // Read the no. of chunks this message is split into, allocate + // a StringBuffer that can hold all chunks, read the chunks + // into the buffer and set 'content' accordingly + int chunksToRead = in.readInt(); + StringBuffer sb = new StringBuffer(chunkSize * chunksToRead); + for (int i = 0; i chunksToRead; i++) { +sb.append( in.readUTF() ); + } + content = sb.toString(); } } @@ -75,8 +87,31 @@ if ( content == 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 ... + ArrayList v = new ArrayList(); + int contentLength = content.length(); + + while (contentLength 0) { +int beginCopy = (v.size()) * chunkSize; +int endCopy = contentLength = chunkSize ? + beginCopy + contentLength : beginCopy + chunkSize; + +String theChunk = content.substring(beginCopy, endCopy); +v.add(theChunk); + +contentLength -= chunkSize; + } + + // Write out the type (OBJECT), the no. of chunks and finally + // all chunks that have been assembled previously out.writeByte( OBJECT ); - out.writeUTF( content ); + out.writeInt(v.size()); + for (int i = 0; i v.size(); i++) { +out.writeUTF( (String)v.get(i) ); + } } } ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development