Author: markt Date: Tue Aug 7 19:15:50 2012 New Revision: 1370441 URL: http://svn.apache.org/viewvc?rev=1370441&view=rev Log: FindBugs: Sync mis-match Reduce size of sync block and make current volatile so updates are seen consistently
Modified: tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java Modified: tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java?rev=1370441&r1=1370440&r2=1370441&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java (original) +++ tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java Tue Aug 7 19:15:50 2012 @@ -62,7 +62,7 @@ public class NioSender extends AbstractS */ protected ByteBuffer readbuf = null; protected ByteBuffer writebuf = null; - protected byte[] current = null; + protected volatile byte[] current = null; protected final XByteBuffer ackbuf = new XByteBuffer(128,true); protected int remaining = 0; protected boolean complete; @@ -349,38 +349,41 @@ public class NioSender extends AbstractS * @throws IOException * TODO Implement this org.apache.catalina.tribes.transport.IDataSender method */ - public synchronized void setMessage(byte[] data) throws IOException { - setMessage(data,0,data.length); - } - - public synchronized void setMessage(byte[] data,int offset, int length) throws IOException { - if ( data != null ) { - current = data; - remaining = length; - ackbuf.clear(); - if ( writebuf != null ) writebuf.clear(); - else writebuf = getBuffer(length); - if ( writebuf.capacity() < length ) writebuf = getBuffer(length); - - //TODO use ByteBuffer.wrap to avoid copying the data. - writebuf.put(data,offset,length); - //writebuf.rewind(); - //set the limit so that we don't write non wanted data - //writebuf.limit(length); - writebuf.flip(); - if (isConnected()) { - if (isUdpBased()) - dataChannel.register(getSelector(), SelectionKey.OP_WRITE, this); - else - socketChannel.register(getSelector(), SelectionKey.OP_WRITE, this); - } - } - } - - public byte[] getMessage() { - return current; - } + public void setMessage(byte[] data) throws IOException { + setMessage(data,0,data.length); + } + + public void setMessage(byte[] data,int offset, int length) throws IOException { + if (data != null) { + synchronized (this) { + current = data; + remaining = length; + ackbuf.clear(); + if (writebuf != null) { + writebuf.clear(); + } else { + writebuf = getBuffer(length); + } + if (writebuf.capacity() < length) { + writebuf = getBuffer(length); + } + // TODO use ByteBuffer.wrap to avoid copying the data. + writebuf.put(data,offset,length); + writebuf.flip(); + if (isConnected()) { + if (isUdpBased()) + dataChannel.register(getSelector(), SelectionKey.OP_WRITE, this); + else + socketChannel.register(getSelector(), SelectionKey.OP_WRITE, this); + } + } + } + } + + public byte[] getMessage() { + return current; + } public boolean isComplete() { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org