You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/08/02 13:25:56 UTC
svn commit: r1368421 -
/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/
Author: olegk
Date: Thu Aug 2 11:25:55 2012
New Revision: 1368421
URL: http://svn.apache.org/viewvc?rev=1368421&view=rev
Log:
Alighed shared i/o buffer API with that of async content consumers / producers
Modified:
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ContentOutputBuffer.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/DirectByteBufferAllocator.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/HeapByteBufferAllocator.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedInputBuffer.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleOutputBuffer.java
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java?rev=1368421&r1=1368420&r2=1368421&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java Thu Aug 2 11:25:55 2012
@@ -32,7 +32,7 @@ import java.io.IOException;
import org.apache.http.nio.ContentDecoder;
/**
- * Buffer for storing content streamed out from a {@link ContentDecoder}.
+ * Generic content input buffer.
*
* @since 4.0
*/
@@ -45,7 +45,10 @@ public interface ContentInputBuffer {
* @param decoder the content decoder.
* @return number of bytes read.
* @throws IOException in case of an I/O error.
+ *
+ * @deprecated (4.3) use implementation specific methods.
*/
+ @Deprecated
int consumeContent(ContentDecoder decoder) throws IOException;
/**
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ContentOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ContentOutputBuffer.java?rev=1368421&r1=1368420&r2=1368421&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ContentOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/ContentOutputBuffer.java Thu Aug 2 11:25:55 2012
@@ -32,7 +32,7 @@ import java.io.IOException;
import org.apache.http.nio.ContentEncoder;
/**
- * Buffer for storing content to be streamed out to a {@link ContentEncoder}.
+ * Generic content output buffer.
*
* @since 4.0
*/
@@ -44,7 +44,10 @@ public interface ContentOutputBuffer {
* @param encoder content encoder.
* @return number of bytes written.
* @throws IOException in case of an I/O error.
+ *
+ * @deprecated (4.3) use implementation specific methods.
*/
+ @Deprecated
int produceContent(ContentEncoder encoder) throws IOException;
/**
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/DirectByteBufferAllocator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/DirectByteBufferAllocator.java?rev=1368421&r1=1368420&r2=1368421&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/DirectByteBufferAllocator.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/DirectByteBufferAllocator.java Thu Aug 2 11:25:55 2012
@@ -40,6 +40,8 @@ import org.apache.http.annotation.Immuta
@Immutable
public class DirectByteBufferAllocator implements ByteBufferAllocator {
+ public static final ByteBufferAllocator INSTANCE = new DirectByteBufferAllocator();
+
public ByteBuffer allocate(int size) {
return ByteBuffer.allocateDirect(size);
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/HeapByteBufferAllocator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/HeapByteBufferAllocator.java?rev=1368421&r1=1368420&r2=1368421&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/HeapByteBufferAllocator.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/HeapByteBufferAllocator.java Thu Aug 2 11:25:55 2012
@@ -40,6 +40,8 @@ import org.apache.http.annotation.Immuta
@Immutable
public class HeapByteBufferAllocator implements ByteBufferAllocator {
+ public static final ByteBufferAllocator INSTANCE = new HeapByteBufferAllocator();
+
public ByteBuffer allocate(int size) {
return ByteBuffer.allocate(size);
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedInputBuffer.java?rev=1368421&r1=1368420&r2=1368421&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedInputBuffer.java Thu Aug 2 11:25:55 2012
@@ -54,23 +54,40 @@ import org.apache.http.nio.IOControl;
@ThreadSafe
public class SharedInputBuffer extends ExpandableBuffer implements ContentInputBuffer {
- private final IOControl ioctrl;
private final ReentrantLock lock;
private final Condition condition;
+ private volatile IOControl ioctrl;
private volatile boolean shutdown = false;
private volatile boolean endOfStream = false;
+ /**
+ * @deprecated (4.3) use {@link SharedInputBuffer#SharedInputBuffer(int, ByteBufferAllocator)}
+ */
+ @Deprecated
public SharedInputBuffer(int buffersize, final IOControl ioctrl, final ByteBufferAllocator allocator) {
super(buffersize, allocator);
- if (ioctrl == null) {
- throw new IllegalArgumentException("I/O content control may not be null");
- }
this.ioctrl = ioctrl;
this.lock = new ReentrantLock();
this.condition = this.lock.newCondition();
}
+ /**
+ * @since 4.3
+ */
+ public SharedInputBuffer(int buffersize, final ByteBufferAllocator allocator) {
+ super(buffersize, allocator);
+ this.lock = new ReentrantLock();
+ this.condition = this.lock.newCondition();
+ }
+
+ /**
+ * @since 4.3
+ */
+ public SharedInputBuffer(int buffersize) {
+ this(buffersize, HeapByteBufferAllocator.INSTANCE);
+ }
+
public void reset() {
if (this.shutdown) {
return;
@@ -84,12 +101,26 @@ public class SharedInputBuffer extends E
}
}
+ /**
+ * @deprecated (4.3) use {@link #consumeContent(ContentDecoder, IOControl)}
+ */
+ @Deprecated
public int consumeContent(final ContentDecoder decoder) throws IOException {
+ return consumeContent(decoder, null);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public int consumeContent(final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
if (this.shutdown) {
return -1;
}
this.lock.lock();
try {
+ if (ioctrl != null) {
+ this.ioctrl = ioctrl;
+ }
setInputMode();
int totalRead = 0;
int bytesRead;
@@ -100,7 +131,9 @@ public class SharedInputBuffer extends E
this.endOfStream = true;
}
if (!this.buffer.hasRemaining()) {
- this.ioctrl.suspendInput();
+ if (this.ioctrl != null) {
+ this.ioctrl.suspendInput();
+ }
}
this.condition.signalAll();
@@ -166,7 +199,9 @@ public class SharedInputBuffer extends E
if (this.shutdown) {
throw new InterruptedIOException("Input operation aborted");
}
- this.ioctrl.requestInput();
+ if (this.ioctrl != null) {
+ this.ioctrl.requestInput();
+ }
this.condition.await();
}
} catch (InterruptedException ex) {
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java?rev=1368421&r1=1368420&r2=1368421&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java Thu Aug 2 11:25:55 2012
@@ -54,13 +54,17 @@ import org.apache.http.nio.IOControl;
@ThreadSafe
public class SharedOutputBuffer extends ExpandableBuffer implements ContentOutputBuffer {
- private final IOControl ioctrl;
private final ReentrantLock lock;
private final Condition condition;
+ private volatile IOControl ioctrl;
private volatile boolean shutdown = false;
private volatile boolean endOfStream = false;
+ /**
+ * @deprecated (4.3) use {@link SharedOutputBuffer#SharedOutputBuffer(int, ByteBufferAllocator)}
+ */
+ @Deprecated
public SharedOutputBuffer(int buffersize, final IOControl ioctrl, final ByteBufferAllocator allocator) {
super(buffersize, allocator);
if (ioctrl == null) {
@@ -71,6 +75,22 @@ public class SharedOutputBuffer extends
this.condition = this.lock.newCondition();
}
+ /**
+ * @since 4.3
+ */
+ public SharedOutputBuffer(int buffersize, final ByteBufferAllocator allocator) {
+ super(buffersize, allocator);
+ this.lock = new ReentrantLock();
+ this.condition = this.lock.newCondition();
+ }
+
+ /**
+ * @since 4.3
+ */
+ public SharedOutputBuffer(int buffersize) {
+ this(buffersize, HeapByteBufferAllocator.INSTANCE);
+ }
+
public void reset() {
if (this.shutdown) {
return;
@@ -124,12 +144,25 @@ public class SharedOutputBuffer extends
}
}
+ /**
+ * @deprecated (4.3) use {@link #produceContent(ContentEncoder, IOControl)
+ */
public int produceContent(final ContentEncoder encoder) throws IOException {
+ return produceContent(encoder, null);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public int produceContent(final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
if (this.shutdown) {
return -1;
}
this.lock.lock();
try {
+ if (ioctrl != null) {
+ this.ioctrl = ioctrl;
+ }
setOutputMode();
int bytesWritten = 0;
if (super.hasData()) {
@@ -146,7 +179,9 @@ public class SharedOutputBuffer extends
}
if (!this.endOfStream) {
// suspend output events
- this.ioctrl.suspendOutput();
+ if (this.ioctrl != null) {
+ this.ioctrl.suspendOutput();
+ }
}
}
this.condition.signalAll();
@@ -234,7 +269,9 @@ public class SharedOutputBuffer extends
if (this.shutdown) {
throw new InterruptedIOException("Output operation aborted");
}
- this.ioctrl.requestOutput();
+ if (this.ioctrl != null) {
+ this.ioctrl.requestOutput();
+ }
this.condition.await();
}
} catch (InterruptedException ex) {
@@ -252,7 +289,9 @@ public class SharedOutputBuffer extends
return;
}
this.endOfStream = true;
- this.ioctrl.requestOutput();
+ if (this.ioctrl != null) {
+ this.ioctrl.requestOutput();
+ }
} finally {
this.lock.unlock();
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java?rev=1368421&r1=1368420&r2=1368421&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java Thu Aug 2 11:25:55 2012
@@ -47,6 +47,13 @@ public class SimpleInputBuffer extends E
super(buffersize, allocator);
}
+ /**
+ * @since 4.3
+ */
+ public SimpleInputBuffer(int buffersize) {
+ this(buffersize, HeapByteBufferAllocator.INSTANCE);
+ }
+
public void reset() {
this.endOfStream = false;
super.clear();
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleOutputBuffer.java?rev=1368421&r1=1368420&r2=1368421&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SimpleOutputBuffer.java Thu Aug 2 11:25:55 2012
@@ -48,6 +48,13 @@ public class SimpleOutputBuffer extends
this.endOfStream = false;
}
+ /**
+ * @since 4.3
+ */
+ public SimpleOutputBuffer(int buffersize) {
+ this(buffersize, HeapByteBufferAllocator.INSTANCE);
+ }
+
public int produceContent(final ContentEncoder encoder) throws IOException {
setOutputMode();
int bytesWritten = encoder.write(this.buffer);