Author: dkulp
Date: Tue Sep 11 15:57:33 2012
New Revision: 1383461
URL: http://svn.apache.org/viewvc?rev=1383461&view=rev
Log:
If waiting for input, just fill the input buffer and return immediately so the
waiting thread can continue. We'll get another input event shortly where we
can fill the buffer.
Modified:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedInputBuffer.java
Modified:
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedInputBuffer.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedInputBuffer.java?rev=1383461&r1=1383460&r2=1383461&view=diff
==============================================================================
---
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedInputBuffer.java
(original)
+++
cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/SharedInputBuffer.java
Tue Sep 11 15:57:33 2012
@@ -57,12 +57,18 @@ public class SharedInputBuffer extends E
private volatile ByteBuffer waitingBuffer;
+ //private volatile int waitCnt;
+ //private volatile int nowaitCnt;
+
public SharedInputBuffer(int buffersize,
final ByteBufferAllocator allocator) {
super(buffersize, allocator);
this.lock = new ReentrantLock();
this.condition = this.lock.newCondition();
- this.requestInputSize = buffersize * 4 / 3;
+ //if the buffer become 3/4 empty, we'll turn on the input
+ //events again to hopefully get more data before the next
+ //the buffer fully empties and we have to wait to read
+ this.requestInputSize = buffersize * 3 / 4;
}
public void reset() {
@@ -96,9 +102,10 @@ public class SharedInputBuffer extends E
while ((bytesRead = decoder.read(this.waitingBuffer)) > 0) {
totalRead += bytesRead;
}
- }
- while ((bytesRead = decoder.read(this.buffer)) > 0) {
- totalRead += bytesRead;
+ } else {
+ while ((bytesRead = decoder.read(this.buffer)) > 0) {
+ totalRead += bytesRead;
+ }
}
if (bytesRead == -1 || decoder.isCompleted()) {
this.endOfStream = true;
@@ -251,10 +258,12 @@ public class SharedInputBuffer extends E
int i = waitingBuffer.position();
waitingBuffer = null;
if (i > 0) {
+ //++waitCnt;
return i;
}
}
if (isEndOfStream()) {
+ //System.out.println(waitCnt + " " + nowaitCnt);
return -1;
}
setOutputMode();
@@ -263,12 +272,13 @@ public class SharedInputBuffer extends E
chunk = this.buffer.remaining();
}
this.buffer.get(b, off, chunk);
- if (this.buffer.remaining() < this.requestInputSize &&
!this.endOfStream && this.ioctrl != null) {
+ if (this.buffer.position() >= this.requestInputSize &&
!this.endOfStream && this.ioctrl != null) {
//we have a significant amount of space empty in the buffer,
we'll turn on
//the input so maybe we'll get another chunk by the time the
next read happens
//and we can then avoid waiting for input
this.ioctrl.requestInput();
}
+ //++nowaitCnt;
return chunk;
} finally {
this.lock.unlock();