You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2014/11/14 09:46:45 UTC
[1/3] mina git commit: o Added tests for methods expand(int) and
expand(int, int). o Added some Javadoc
Repository: mina
Updated Branches:
refs/heads/2.0 bdad876b2 -> 59b7dbabc
o Added tests for methods expand(int) and expand(int, int).
o Added some Javadoc
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/dd852f9e
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/dd852f9e
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/dd852f9e
Branch: refs/heads/2.0
Commit: dd852f9e2fa3ab4d71fd6f39b0189d0096c88567
Parents: bdad876
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Sun Nov 9 08:59:13 2014 +0100
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Sun Nov 9 08:59:13 2014 +0100
----------------------------------------------------------------------
.../org/apache/mina/core/buffer/IoBuffer.java | 284 ++++++++++++++++---
.../apache/mina/core/buffer/IoBufferTest.java | 167 +++++++++++
2 files changed, 410 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/dd852f9e/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java b/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java
index 84db5d3..19827c2 100644
--- a/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java
+++ b/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java
@@ -61,7 +61,7 @@ import org.apache.mina.core.session.IoSession;
* IoBuffer buf = IoBuffer.allocate(1024, false);
* </pre>
*
- * you can also allocate a new direct buffer:
+ * You can also allocate a new direct buffer:
*
* <pre>
* IoBuffer buf = IoBuffer.allocate(1024, true);
@@ -72,6 +72,7 @@ import org.apache.mina.core.session.IoSession;
* <pre>
* // Allocate heap buffer by default.
* IoBuffer.setUseDirectBuffer(false);
+ *
* // A new heap buffer is returned.
* IoBuffer buf = IoBuffer.allocate(1024);
* </pre>
@@ -86,11 +87,11 @@ import org.apache.mina.core.session.IoSession;
* <h2>AutoExpand</h2>
* <p>
* Writing variable-length data using NIO <tt>ByteBuffers</tt> is not really
- * easy, and it is because its size is fixed. {@link IoBuffer} introduces
- * <tt>autoExpand</tt> property. If <tt>autoExpand</tt> property is true, you
- * never get {@link BufferOverflowException} or
- * {@link IndexOutOfBoundsException} (except when index is negative). It
- * automatically expands its capacity and limit value. For example:
+ * easy, and it is because its size is fixed at allocation. {@link IoBuffer} introduces
+ * the <tt>autoExpand</tt> property. If <tt>autoExpand</tt> property is set to true,
+ * you never get a {@link BufferOverflowException} or
+ * an {@link IndexOutOfBoundsException} (except when index is negative). It
+ * automatically expands its capacity. For instance:
*
* <pre>
* String greeting = messageBundle.getMessage("hello");
@@ -115,29 +116,30 @@ import org.apache.mina.core.session.IoSession;
* buffer when {@link #compact()} is invoked and only 1/4 or less of the current
* capacity is being used.
* <p>
- * You can also {@link #shrink()} method manually to shrink the capacity of the
+ * You can also call the {@link #shrink()} method manually to shrink the capacity of the
* buffer.
* <p>
- * The underlying {@link ByteBuffer} is reallocated by {@link IoBuffer} behind
+ * The underlying {@link ByteBuffer} is reallocated by the {@link IoBuffer} behind
* the scene, and therefore {@link #buf()} will return a different
* {@link ByteBuffer} instance once capacity changes. Please also note
- * {@link #compact()} or {@link #shrink()} will not decrease the capacity if the
- * new capacity is less than the {@link #minimumCapacity()} of the buffer.
+ * that the {@link #compact()} method or the {@link #shrink()} method
+ * will not decrease the capacity if the new capacity is less than the
+ * {@link #minimumCapacity()} of the buffer.
*
* <h2>Derived Buffers</h2>
* <p>
- * Derived buffers are the buffers which were created by {@link #duplicate()},
- * {@link #slice()}, or {@link #asReadOnlyBuffer()}. They are useful especially
+ * Derived buffers are the buffers which were created by the {@link #duplicate()},
+ * {@link #slice()}, or {@link #asReadOnlyBuffer()} methods. They are useful especially
* when you broadcast the same messages to multiple {@link IoSession}s. Please
- * note that the buffer derived from and its derived buffers are not both
- * auto-expandable neither auto-shrinkable. Trying to call
+ * note that the buffer derived from and its derived buffers are not
+ * auto-expandable nor auto-shrinkable. Trying to call
* {@link #setAutoExpand(boolean)} or {@link #setAutoShrink(boolean)} with
* <tt>true</tt> parameter will raise an {@link IllegalStateException}.
* </p>
*
* <h2>Changing Buffer Allocation Policy</h2>
* <p>
- * {@link IoBufferAllocator} interface lets you override the default buffer
+ * The {@link IoBufferAllocator} interface lets you override the default buffer
* management behavior. There are two allocators provided out-of-the-box:
* <ul>
* <li>{@link SimpleBufferAllocator} (default)</li>
@@ -157,7 +159,7 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
private static boolean useDirectBuffer = false;
/**
- * Returns the allocator used by existing and new buffers
+ * @return the allocator used by existing and new buffers
*/
public static IoBufferAllocator getAllocator() {
return allocator;
@@ -165,6 +167,8 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
/**
* Sets the allocator used by existing and new buffers
+ *
+ * @paream newAllocator the new allocator to use
*/
public static void setAllocator(IoBufferAllocator newAllocator) {
if (newAllocator == null) {
@@ -181,7 +185,7 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
}
/**
- * Returns <tt>true</tt> if and only if a direct buffer is allocated by
+ * @return <tt>true</tt> if and only if a direct buffer is allocated by
* default when the type of the new buffer is not specified. The default
* value is <tt>false</tt>.
*/
@@ -192,6 +196,8 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
/**
* Sets if a direct buffer should be allocated by default when the type of
* the new buffer is not specified. The default value is <tt>false</tt>.
+ *
+ * @param useDirectBuffer Tells if direct buffers should be allocated
*/
public static void setUseDirectBuffer(boolean useDirectBuffer) {
IoBuffer.useDirectBuffer = useDirectBuffer;
@@ -201,8 +207,8 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
* Returns the direct or heap buffer which is capable to store the specified
* amount of bytes.
*
- * @param capacity
- * the capacity of the buffer
+ * @param capacity the capacity of the buffer
+ * @return a IoBuffer which can hold up to capacity bytes
*
* @see #setUseDirectBuffer(boolean)
*/
@@ -211,38 +217,53 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
}
/**
- * Returns the buffer which is capable of the specified size.
+ * Returns a direct or heap IoBuffer which can contain the specified number of bytes.
*
- * @param capacity
- * the capacity of the buffer
- * @param direct
- * <tt>true</tt> to get a direct buffer, <tt>false</tt> to get a
+ * @param capacity the capacity of the buffer
+ * @param useDirectBuffer <tt>true</tt> to get a direct buffer, <tt>false</tt> to get a
* heap buffer.
+ * @return a direct or heap IoBuffer which can hold up to capacity bytes
*/
- public static IoBuffer allocate(int capacity, boolean direct) {
+ public static IoBuffer allocate(int capacity, boolean useDirectBuffer) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity: " + capacity);
}
- return allocator.allocate(capacity, direct);
+ return allocator.allocate(capacity, useDirectBuffer);
}
/**
- * Wraps the specified NIO {@link ByteBuffer} into MINA buffer.
+ * Wraps the specified NIO {@link ByteBuffer} into a MINA buffer (either direct or heap).
+ *
+ * @param nioBuffer The {@link ByteBuffer} to wrap
+ * @return a IoBuffer containing the bytes stored in the {@link ByteBuffer}
*/
public static IoBuffer wrap(ByteBuffer nioBuffer) {
return allocator.wrap(nioBuffer);
}
/**
- * Wraps the specified byte array into MINA heap buffer.
+ * Wraps the specified byte array into a MINA heap buffer. Note that
+ * the byte array is not copied, so any modification done on it will
+ * be visible by both sides.
+ *
+ * @param byteArray The byte array to wrap
+ * @return a heap IoBuffer containing the byte array
*/
public static IoBuffer wrap(byte[] byteArray) {
return wrap(ByteBuffer.wrap(byteArray));
}
/**
- * Wraps the specified byte array into MINA heap buffer.
+ * Wraps the specified byte array into MINA heap buffer. We just wrap the
+ * bytes starting from offset up to offset + length. Note that
+ * the byte array is not copied, so any modification done on it will
+ * be visible by both sides.
+ *
+ * @param byteArray The byte array to wrap
+ * @param offset The starting point in the byte array
+ * @param length The number of bytes to store
+ * @return a heap IoBuffer containing the selected part of the byte array
*/
public static IoBuffer wrap(byte[] byteArray, int offset, int length) {
return wrap(ByteBuffer.wrap(byteArray, offset, length));
@@ -253,6 +274,9 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
* often helpful for optimal memory usage and performance. If it is greater
* than or equal to {@link Integer#MAX_VALUE}, it returns
* {@link Integer#MAX_VALUE}. If it is zero, it returns zero.
+ *
+ * @param requestedCapacity The IoBuffer capacity we want to be able to store
+ * @return The power of 2 strictly superior to the requested capacity
*/
protected static int normalizeCapacity(int requestedCapacity) {
if (requestedCapacity < 0) {
@@ -261,11 +285,13 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
int newCapacity = Integer.highestOneBit(requestedCapacity);
newCapacity <<= (newCapacity < requestedCapacity ? 1 : 0);
+
return newCapacity < 0 ? Integer.MAX_VALUE : newCapacity;
}
/**
- * Creates a new instance. This is an empty constructor.
+ * Creates a new instance. This is an empty constructor. It's protected,
+ * to forbid its usage by the users.
*/
protected IoBuffer() {
// Do nothing
@@ -280,7 +306,7 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
public abstract void free();
/**
- * Returns the underlying NIO buffer instance.
+ * @return the underlying NIO {@link ByteBuffer} instance.
*/
public abstract ByteBuffer buf();
@@ -290,9 +316,9 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
public abstract boolean isDirect();
/**
- * returns <tt>true</tt> if and only if this buffer is derived from other
- * buffer via {@link #duplicate()}, {@link #slice()} or
- * {@link #asReadOnlyBuffer()}.
+ * @return <tt>true</tt> if and only if this buffer is derived from another
+ * buffer via one of the {@link #duplicate()}, {@link #slice()} or
+ * {@link #asReadOnlyBuffer()} methods.
*/
public abstract boolean isDerived();
@@ -302,8 +328,8 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
public abstract boolean isReadOnly();
/**
- * Returns the minimum capacity of this buffer which is used to determine
- * the new capacity of the buffer shrunk by {@link #compact()} and
+ * @return the minimum capacity of this buffer which is used to determine
+ * the new capacity of the buffer shrunk by the {@link #compact()} and
* {@link #shrink()} operation. The default value is the initial capacity of
* the buffer.
*/
@@ -314,6 +340,9 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
* new capacity of the buffer shrunk by {@link #compact()} and
* {@link #shrink()} operation. The default value is the initial capacity of
* the buffer.
+ *
+ * @param minimumCapacity the wanted minimum capacity
+ * @return the underlying NIO {@link ByteBuffer} instance.
*/
public abstract IoBuffer minimumCapacity(int minimumCapacity);
@@ -324,30 +353,76 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
/**
* Increases the capacity of this buffer. If the new capacity is less than
- * or equal to the current capacity, this method returns silently. If the
- * new capacity is greater than the current capacity, the buffer is
+ * or equal to the current capacity, this method returns the original buffer.
+ * If the new capacity is greater than the current capacity, the buffer is
* reallocated while retaining the position, limit, mark and the content of
- * the buffer.
+ * the buffer.<br/>
+ * Note that the IoBuffer is replaced, it's not copied.
+ * <br>
+ * Assuming a buffer contains N bytes, its position is 0 and its current capacity is C,
+ * here are the resulting buffer if we set the new capacity to a value V < C and V > C :
+ *
+ * <pre>
+ * Initial buffer :
+ *
+ * 0 L C
+ * +--------+----------+
+ * |XXXXXXXX| |
+ * +--------+----------+
+ * ^ ^ ^
+ * | | |
+ * pos limit capacity
+ *
+ * V < C :
+ *
+ * 0 L V
+ * +--------+----------+
+ * |XXXXXXXX| |
+ * +--------+----------+
+ * ^ ^ ^
+ * | | |
+ * pos limit newCapacity
+ *
+ * V > C :
+ *
+ * 0 L C V
+ * +--------+-----------------------+
+ * |XXXXXXXX| : |
+ * +--------+-----------------------+
+ * ^ ^ ^ ^
+ * | | | |
+ * pos limit oldCapacity newCapacity
+ *
+ * </pre>
+ *
+ * @param capacity the wanted capacity
+ * @return the underlying NIO {@link ByteBuffer} instance.
*/
public abstract IoBuffer capacity(int newCapacity);
/**
- * Returns <tt>true</tt> if and only if <tt>autoExpand</tt> is turned on.
+ * @return <tt>true</tt> if and only if <tt>autoExpand</tt> is turned on.
*/
public abstract boolean isAutoExpand();
/**
* Turns on or off <tt>autoExpand</tt>.
+ *
+ * @param autoExpand The flag value to set
+ * @return The modified IoBuffer instance
*/
public abstract IoBuffer setAutoExpand(boolean autoExpand);
/**
- * Returns <tt>true</tt> if and only if <tt>autoShrink</tt> is turned on.
+ * @return <tt>true</tt> if and only if <tt>autoShrink</tt> is turned on.
*/
public abstract boolean isAutoShrink();
/**
* Turns on or off <tt>autoShrink</tt>.
+ *
+ * @param autoShrink The flag value to set
+ * @return The modified IoBuffer instance
*/
public abstract IoBuffer setAutoShrink(boolean autoShrink);
@@ -355,6 +430,68 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
* Changes the capacity and limit of this buffer so this buffer get the
* specified <tt>expectedRemaining</tt> room from the current position. This
* method works even if you didn't set <tt>autoExpand</tt> to <tt>true</tt>.
+ * <br>
+ * Assuming a buffer contains N bytes, its position is P and its current capacity is C,
+ * here are the resulting buffer if we call the expand method with a expectedRemaining
+ * value V :
+ *
+ * <pre>
+ * Initial buffer :
+ *
+ * 0 L C
+ * +--------+----------+
+ * |XXXXXXXX| |
+ * +--------+----------+
+ * ^ ^ ^
+ * | | |
+ * pos limit capacity
+ *
+ * ( pos + V) <= L, no change :
+ *
+ * 0 L C
+ * +--------+----------+
+ * |XXXXXXXX| |
+ * +--------+----------+
+ * ^ ^ ^
+ * | | |
+ * pos limit newCapacity
+ *
+ * You can still put ( L - pos ) bytes in the buffer
+ *
+ * ( pos + V ) > L & ( pos + V ) <= C :
+ *
+ * 0 L C
+ * +------------+------+
+ * |XXXXXXXX:...| |
+ * +------------+------+
+ * ^ ^ ^
+ * | | |
+ * pos newlimit newCapacity
+ *
+ * You can now put ( L - pos + V) bytes in the buffer.
+ *
+ *
+ * ( pos + V ) > C
+ *
+ * 0 L C
+ * +-------------------+----+
+ * |XXXXXXXX:..........:....|
+ * +------------------------+
+ * ^ ^
+ * | |
+ * pos +-- newlimit
+ * |
+ * +-- newCapacity
+ *
+ * You can now put ( L - pos + V ) bytes in the buffer, which limit is now
+ * equals to the capacity.
+ * </pre>
+ *
+ * Note that the expecting remaining bytes starts at the current position. In all
+ * those examples, the position is 0.
+ *
+ * @param expectedRemaining The expected remaining bytes in the buffer
+ * @return The modified IoBuffer instance
*/
public abstract IoBuffer expand(int expectedRemaining);
@@ -363,6 +500,69 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
* specified <tt>expectedRemaining</tt> room from the specified
* <tt>position</tt>. This method works even if you didn't set
* <tt>autoExpand</tt> to <tt>true</tt>.
+ * Assuming a buffer contains N bytes, its position is P and its current capacity is C,
+ * here are the resulting buffer if we call the expand method with a expectedRemaining
+ * value V :
+ *
+ * <pre>
+ * Initial buffer :
+ *
+ * P L C
+ * +--------+----------+
+ * |XXXXXXXX| |
+ * +--------+----------+
+ * ^ ^ ^
+ * | | |
+ * pos limit capacity
+ *
+ * ( pos + V) <= L, no change :
+ *
+ * P L C
+ * +--------+----------+
+ * |XXXXXXXX| |
+ * +--------+----------+
+ * ^ ^ ^
+ * | | |
+ * pos limit newCapacity
+ *
+ * You can still put ( L - pos ) bytes in the buffer
+ *
+ * ( pos + V ) > L & ( pos + V ) <= C :
+ *
+ * P L C
+ * +------------+------+
+ * |XXXXXXXX:...| |
+ * +------------+------+
+ * ^ ^ ^
+ * | | |
+ * pos newlimit newCapacity
+ *
+ * You can now put ( L - pos + V) bytes in the buffer.
+ *
+ *
+ * ( pos + V ) > C
+ *
+ * P L C
+ * +-------------------+----+
+ * |XXXXXXXX:..........:....|
+ * +------------------------+
+ * ^ ^
+ * | |
+ * pos +-- newlimit
+ * |
+ * +-- newCapacity
+ *
+ * You can now put ( L - pos + V ) bytes in the buffer, which limit is now
+ * equals to the capacity.
+ * </pre>
+ *
+ * Note that the expecting remaining bytes starts at the current position. In all
+ * those examples, the position is P.
+ *
+ * @param position The starting position from which we want to define a remaining
+ * number of bytes
+ * @param expectedRemaining The expected remaining bytes in the buffer
+ * @return The modified IoBuffer instance
*/
public abstract IoBuffer expand(int position, int expectedRemaining);
@@ -372,6 +572,8 @@ public abstract class IoBuffer implements Comparable<IoBuffer> {
* content between the position and limit. The capacity of the buffer never
* becomes less than {@link #minimumCapacity()}. The mark is discarded once
* the capacity changes.
+ *
+ * @return The modified IoBuffer instance
*/
public abstract IoBuffer shrink();
http://git-wip-us.apache.org/repos/asf/mina/blob/dd852f9e/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java
----------------------------------------------------------------------
diff --git a/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java b/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java
index 4e85dab..238036d 100644
--- a/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java
+++ b/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java
@@ -56,6 +56,173 @@ public class IoBufferTest {
}
@Test
+ public void testCapacity() {
+ IoBuffer buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+
+ // See if we can decrease the capacity (we shouldn't)
+ IoBuffer newBuffer = buffer.capacity(7);
+ assertEquals(10, newBuffer.capacity());
+ assertEquals(buffer, newBuffer);
+
+ // See if we can increase the capacity
+ buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+ newBuffer = buffer.capacity(14);
+ assertEquals(14, newBuffer.capacity());
+ assertEquals(buffer, newBuffer);
+ newBuffer.put(0, (byte)'9');
+ assertEquals((byte)'9', newBuffer.get(0));
+ assertEquals((byte)'9', buffer.get(0));
+ }
+
+ @Test
+ public void testExpand() {
+ IoBuffer buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+
+ assertEquals(6, buffer.remaining());
+
+ // See if we can expand with a lower number of remaining bytes. We should not.
+ IoBuffer newBuffer = buffer.expand(2);
+ assertEquals(6, newBuffer.limit());
+ assertEquals(10, newBuffer.capacity());
+ assertEquals(0, newBuffer.position());
+
+ // Now, let's expand the buffer above the number of current bytes but below the limit
+ buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+ newBuffer = buffer.expand(8);
+ assertEquals(8, newBuffer.limit());
+ assertEquals(10, newBuffer.capacity());
+ assertEquals(0, newBuffer.position());
+
+ // Last, expand the buffer above the limit
+ buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+ newBuffer = buffer.expand(12);
+ assertEquals(12, newBuffer.limit());
+ assertEquals(12, newBuffer.capacity());
+ assertEquals(0, newBuffer.position());
+
+ // Now, move forward in the buffer
+ buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+ buffer.position(4);
+
+ // See if we can expand with a lower number of remaining bytes. We should not.
+ newBuffer = buffer.expand(2);
+ assertEquals(6, newBuffer.limit());
+ assertEquals(10, newBuffer.capacity());
+ assertEquals(4, newBuffer.position());
+
+ // Expand above the current limit
+ buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+ buffer.position(4);
+ newBuffer = buffer.expand(3);
+ assertEquals(7, newBuffer.limit());
+ assertEquals(10, newBuffer.capacity());
+ assertEquals(4, newBuffer.position());
+
+ // Expand above the current capacity
+ buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+ buffer.position(4);
+ newBuffer = buffer.expand(7);
+ assertEquals(11, newBuffer.limit());
+ assertEquals(11, newBuffer.capacity());
+ assertEquals(4, newBuffer.position());
+ }
+
+ @Test
+ public void testExpandPos() {
+ IoBuffer buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+
+ assertEquals(6, buffer.remaining());
+
+ // See if we can expand with a lower number of remaining bytes. We should not.
+ IoBuffer newBuffer = buffer.expand(3, 2);
+ assertEquals(6, newBuffer.limit());
+ assertEquals(10, newBuffer.capacity());
+ assertEquals(0, newBuffer.position());
+
+ // Now, let's expand the buffer above the number of current bytes but below the limit
+ buffer = IoBuffer.allocate(10);
+ buffer.put("012345".getBytes());
+ buffer.flip();
+
+ newBuffer = buffer.expand(3, 5);
+ assertEquals(8, newBuffer.limit());
+ assertEquals(10, newBuffer.capacity());
+ assertEquals(0, newBuffer.position());
+
+ // Last, expand the buffer above the limit
+ buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+ newBuffer = buffer.expand(3,9);
+ assertEquals(12, newBuffer.limit());
+ assertEquals(12, newBuffer.capacity());
+ assertEquals(0, newBuffer.position());
+
+ // Now, move forward in the buffer
+ buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+ buffer.position(4);
+
+ // See if we can expand with a lower number of remaining bytes. We should not be.
+ newBuffer = buffer.expand(5, 1);
+ assertEquals(6, newBuffer.limit());
+ assertEquals(10, newBuffer.capacity());
+ assertEquals(4, newBuffer.position());
+
+ // Expand above the current limit
+ buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+ buffer.position(4);
+ newBuffer = buffer.expand(5, 2);
+ assertEquals(7, newBuffer.limit());
+ assertEquals(10, newBuffer.capacity());
+ assertEquals(4, newBuffer.position());
+
+ // Expand above the current capacity
+ buffer = IoBuffer.allocate(10);
+
+ buffer.put("012345".getBytes());
+ buffer.flip();
+ buffer.position(4);
+ newBuffer = buffer.expand(5, 6);
+ assertEquals(11, newBuffer.limit());
+ assertEquals(11, newBuffer.capacity());
+ assertEquals(4, newBuffer.position());
+ }
+
+ @Test
public void testNormalizeCapacity() {
// A few sanity checks
assertEquals(Integer.MAX_VALUE, IoBufferImpl.normalizeCapacity(-10));
[3/3] mina git commit: Added mising Apache headers
Posted by el...@apache.org.
Added mising Apache headers
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/59b7dbab
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/59b7dbab
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/59b7dbab
Branch: refs/heads/2.0
Commit: 59b7dbabce68e400fab6905ca11abcc37672ce3f
Parents: 1d22556
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Fri Nov 14 09:46:22 2014 +0100
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Fri Nov 14 09:46:22 2014 +0100
----------------------------------------------------------------------
.../org/apache/mina/http/HttpClientEncoder.java | 69 ++++++----
.../mina/http/HttpRequestImplTestCase.java | 127 +++++++++++--------
2 files changed, 117 insertions(+), 79 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/59b7dbab/mina-http/src/main/java/org/apache/mina/http/HttpClientEncoder.java
----------------------------------------------------------------------
diff --git a/mina-http/src/main/java/org/apache/mina/http/HttpClientEncoder.java b/mina-http/src/main/java/org/apache/mina/http/HttpClientEncoder.java
index 81203fb..26f7994 100644
--- a/mina-http/src/main/java/org/apache/mina/http/HttpClientEncoder.java
+++ b/mina-http/src/main/java/org/apache/mina/http/HttpClientEncoder.java
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
package org.apache.mina.http;
import java.nio.ByteBuffer;
@@ -18,24 +37,24 @@ public class HttpClientEncoder implements ProtocolEncoder {
private static final Logger LOG = LoggerFactory.getLogger(HttpClientCodec.class);
private static final CharsetEncoder ENCODER = Charset.forName("UTF-8").newEncoder();
- public void encode(IoSession session, Object message, ProtocolEncoderOutput out)
- throws Exception {
- LOG.debug("encode {}", message.getClass().getCanonicalName());
- if (message instanceof HttpRequest) {
- LOG.debug("HttpRequest");
- HttpRequest msg = (HttpRequest)message;
- StringBuilder sb = new StringBuilder(msg.getMethod().toString());
- sb.append(" ");
- sb.append(msg.getRequestPath());
- if (!"".equals(msg.getQueryString())) {
- sb.append("?");
- sb.append(msg.getQueryString());
- }
- sb.append(" ");
- sb.append(msg.getProtocolVersion());
- sb.append("\r\n");
+ public void encode(IoSession session, Object message, ProtocolEncoderOutput out)
+ throws Exception {
+ LOG.debug("encode {}", message.getClass().getCanonicalName());
+ if (message instanceof HttpRequest) {
+ LOG.debug("HttpRequest");
+ HttpRequest msg = (HttpRequest)message;
+ StringBuilder sb = new StringBuilder(msg.getMethod().toString());
+ sb.append(" ");
+ sb.append(msg.getRequestPath());
+ if (!"".equals(msg.getQueryString())) {
+ sb.append("?");
+ sb.append(msg.getQueryString());
+ }
+ sb.append(" ");
+ sb.append(msg.getProtocolVersion());
+ sb.append("\r\n");
- for (Map.Entry<String, String> header : msg.getHeaders().entrySet()) {
+ for (Map.Entry<String, String> header : msg.getHeaders().entrySet()) {
sb.append(header.getKey());
sb.append(": ");
sb.append(header.getValue());
@@ -50,19 +69,19 @@ public class HttpClientEncoder implements ProtocolEncoder {
buf.flip();
out.write(buf);
} else if (message instanceof ByteBuffer) {
- LOG.debug("Body");
- out.write(message);
+ LOG.debug("Body");
+ out.write(message);
} else if (message instanceof HttpEndOfContent) {
- LOG.debug("End of Content");
+ LOG.debug("End of Content");
// end of HTTP content
// keep alive ?
- }
+ }
- }
+ }
- public void dispose(IoSession arg0) throws Exception {
- // TODO Auto-generated method stub
+ public void dispose(IoSession arg0) throws Exception {
+ // TODO Auto-generated method stub
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/mina/blob/59b7dbab/mina-http/src/test/java/org/apache/mina/http/HttpRequestImplTestCase.java
----------------------------------------------------------------------
diff --git a/mina-http/src/test/java/org/apache/mina/http/HttpRequestImplTestCase.java b/mina-http/src/test/java/org/apache/mina/http/HttpRequestImplTestCase.java
index ef6a42f..ba3b724 100644
--- a/mina-http/src/test/java/org/apache/mina/http/HttpRequestImplTestCase.java
+++ b/mina-http/src/test/java/org/apache/mina/http/HttpRequestImplTestCase.java
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
package org.apache.mina.http;
import static org.junit.Assert.*;
@@ -12,65 +31,65 @@ import org.junit.Test;
public class HttpRequestImplTestCase {
- @Test
- public void testGetParameterNoParameter() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","", null);
- assertNull("p0 doesn't exist", req.getParameter("p0"));
- }
+ @Test
+ public void testGetParameterNoParameter() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","", null);
+ assertNull("p0 doesn't exist", req.getParameter("p0"));
+ }
- @Test
- public void testGetParameterOneEmptyParameter() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=", null);
- assertEquals("p0 is emtpy", "", req.getParameter("p0"));
- assertNull("p1 doesn't exist", req.getParameter("p1"));
- }
+ @Test
+ public void testGetParameterOneEmptyParameter() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=", null);
+ assertEquals("p0 is emtpy", "", req.getParameter("p0"));
+ assertNull("p1 doesn't exist", req.getParameter("p1"));
+ }
- @Test
- public void testGetParameterOneParameter() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=0", null);
- assertEquals("p0 is '0'", "0", req.getParameter("p0"));
- assertNull("p1 doesn't exist", req.getParameter("p1"));
- }
+ @Test
+ public void testGetParameterOneParameter() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=0", null);
+ assertEquals("p0 is '0'", "0", req.getParameter("p0"));
+ assertNull("p1 doesn't exist", req.getParameter("p1"));
+ }
- @Test
- public void testGetParameter3Parameters() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=&p1=1&p2=2", null);
- assertEquals("p0 is emtpy", "", req.getParameter("p0"));
- assertEquals("p1 is '1'", "1", req.getParameter("p1"));
- assertEquals("p2 is '2'", "2", req.getParameter("p2"));
- assertNull("p3 doesn't exist", req.getParameter("p3"));
- }
+ @Test
+ public void testGetParameter3Parameters() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "p0=&p1=1&p2=2", null);
+ assertEquals("p0 is emtpy", "", req.getParameter("p0"));
+ assertEquals("p1 is '1'", "1", req.getParameter("p1"));
+ assertEquals("p2 is '2'", "2", req.getParameter("p2"));
+ assertNull("p3 doesn't exist", req.getParameter("p3"));
+ }
- @Test
- public void testGetParametersNoParameter() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "", null);
- assertTrue("Empty Map", req.getParameters().isEmpty());
- }
+ @Test
+ public void testGetParametersNoParameter() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", "", null);
+ assertTrue("Empty Map", req.getParameters().isEmpty());
+ }
- @Test
- public void testGetParameters3Parameters() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","p0=&p1=1&p2=2", null);
- Map<String, List<String>> parameters = req.getParameters();
- assertEquals("3 parameters", 3, parameters.size());
- assertEquals("one p0", 1, parameters.get("p0").size());
- assertEquals("p0 is emtpy", "", parameters.get("p0").get(0));
- assertEquals("one p1", 1, parameters.get("p1").size());
- assertEquals("p1 is '1'", "1", parameters.get("p1").get(0));
- assertEquals("one p2", 1, parameters.get("p2").size());
- assertEquals("p2 is '2'", "2", parameters.get("p2").get(0));
- }
+ @Test
+ public void testGetParameters3Parameters() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","p0=&p1=1&p2=2", null);
+ Map<String, List<String>> parameters = req.getParameters();
+ assertEquals("3 parameters", 3, parameters.size());
+ assertEquals("one p0", 1, parameters.get("p0").size());
+ assertEquals("p0 is emtpy", "", parameters.get("p0").get(0));
+ assertEquals("one p1", 1, parameters.get("p1").size());
+ assertEquals("p1 is '1'", "1", parameters.get("p1").get(0));
+ assertEquals("one p2", 1, parameters.get("p2").size());
+ assertEquals("p2 is '2'", "2", parameters.get("p2").get(0));
+ }
- @Test
- public void testGetParameters3ParametersWithDuplicate() {
- HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","p0=&p1=1&p0=2", null);
- Map<String, List<String>> parameters = req.getParameters();
- assertEquals("2 parameters", 2, parameters.size());
- assertEquals("two p0", 2, parameters.get("p0").size());
- assertEquals("1st p0 is emtpy", "", parameters.get("p0").get(0));
- assertEquals("2nd p0 is '2'", "2", parameters.get("p0").get(1));
- assertEquals("one p1", 1, parameters.get("p1").size());
- assertEquals("p1 is '1'", "1", parameters.get("p1").get(0));
- assertNull("No p2", parameters.get("p2"));
- }
+ @Test
+ public void testGetParameters3ParametersWithDuplicate() {
+ HttpRequest req = new HttpRequestImpl(HttpVersion.HTTP_1_1, HttpMethod.GET, "/","p0=&p1=1&p0=2", null);
+ Map<String, List<String>> parameters = req.getParameters();
+ assertEquals("2 parameters", 2, parameters.size());
+ assertEquals("two p0", 2, parameters.get("p0").size());
+ assertEquals("1st p0 is emtpy", "", parameters.get("p0").get(0));
+ assertEquals("2nd p0 is '2'", "2", parameters.get("p0").get(1));
+ assertEquals("one p1", 1, parameters.get("p1").size());
+ assertEquals("p1 is '1'", "1", parameters.get("p1").get(0));
+ assertNull("No p2", parameters.get("p2"));
+ }
}
[2/3] mina git commit: Minor formatting
Posted by el...@apache.org.
Minor formatting
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/1d22556a
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/1d22556a
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/1d22556a
Branch: refs/heads/2.0
Commit: 1d22556ac29240c7c545b2079bfb4408c0cafd5e
Parents: dd852f9
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Sun Nov 9 09:00:53 2014 +0100
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Sun Nov 9 09:00:53 2014 +0100
----------------------------------------------------------------------
.../polling/AbstractPollingIoConnector.java | 126 ++++++++++++-------
1 file changed, 79 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/1d22556a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
index 167e8a5..a782d41 100644
--- a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
+++ b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
@@ -80,35 +80,38 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
private final AtomicReference<Connector> connectorRef = new AtomicReference<Connector>();
/**
- * Constructor for {@link AbstractPollingIoConnector}. You need to provide a default
- * session configuration, a class of {@link IoProcessor} which will be instantiated in a
- * {@link SimpleIoProcessorPool} for better scaling in multiprocessor systems. The default
- * pool size will be used.
+ * Constructor for {@link AbstractPollingIoConnector}. You need to provide a
+ * default session configuration, a class of {@link IoProcessor} which will
+ * be instantiated in a {@link SimpleIoProcessorPool} for better scaling in
+ * multiprocessor systems. The default pool size will be used.
*
* @see SimpleIoProcessorPool
*
* @param sessionConfig
* the default configuration for the managed {@link IoSession}
- * @param processorClass a {@link Class} of {@link IoProcessor} for the associated {@link IoSession}
- * type.
+ * @param processorClass
+ * a {@link Class} of {@link IoProcessor} for the associated
+ * {@link IoSession} type.
*/
protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, Class<? extends IoProcessor<T>> processorClass) {
this(sessionConfig, null, new SimpleIoProcessorPool<T>(processorClass), true);
}
/**
- * Constructor for {@link AbstractPollingIoConnector}. You need to provide a default
- * session configuration, a class of {@link IoProcessor} which will be instantiated in a
- * {@link SimpleIoProcessorPool} for using multiple thread for better scaling in multiprocessor
- * systems.
+ * Constructor for {@link AbstractPollingIoConnector}. You need to provide a
+ * default session configuration, a class of {@link IoProcessor} which will
+ * be instantiated in a {@link SimpleIoProcessorPool} for using multiple
+ * thread for better scaling in multiprocessor systems.
*
* @see SimpleIoProcessorPool
*
* @param sessionConfig
* the default configuration for the managed {@link IoSession}
- * @param processorClass a {@link Class} of {@link IoProcessor} for the associated {@link IoSession}
- * type.
- * @param processorCount the amount of processor to instantiate for the pool
+ * @param processorClass
+ * a {@link Class} of {@link IoProcessor} for the associated
+ * {@link IoSession} type.
+ * @param processorCount
+ * the amount of processor to instantiate for the pool
*/
protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, Class<? extends IoProcessor<T>> processorClass,
int processorCount) {
@@ -210,33 +213,44 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
/**
* Initialize the polling system, will be called at construction time.
- * @throws Exception any exception thrown by the underlying system calls
+ *
+ * @throws Exception
+ * any exception thrown by the underlying system calls
*/
protected abstract void init() throws Exception;
/**
* Destroy the polling system, will be called when this {@link IoConnector}
* implementation will be disposed.
- * @throws Exception any exception thrown by the underlying systems calls
+ *
+ * @throws Exception
+ * any exception thrown by the underlying systems calls
*/
protected abstract void destroy() throws Exception;
/**
* Create a new client socket handle from a local {@link SocketAddress}
- * @param localAddress the socket address for binding the new client socket
+ *
+ * @param localAddress
+ * the socket address for binding the new client socket
* @return a new client socket handle
- * @throws Exception any exception thrown by the underlying systems calls
+ * @throws Exception
+ * any exception thrown by the underlying systems calls
*/
protected abstract H newHandle(SocketAddress localAddress) throws Exception;
/**
- * Connect a newly created client socket handle to a remote {@link SocketAddress}.
- * This operation is non-blocking, so at end of the call the socket can be still in connection
- * process.
- * @param handle the client socket handle
- * @param remoteAddress the remote address where to connect
- * @return <tt>true</tt> if a connection was established, <tt>false</tt> if this client socket
- * is in non-blocking mode and the connection operation is in progress
+ * Connect a newly created client socket handle to a remote
+ * {@link SocketAddress}. This operation is non-blocking, so at end of the
+ * call the socket can be still in connection process.
+ *
+ * @param handle
+ * the client socket handle
+ * @param remoteAddress
+ * the remote address where to connect
+ * @return <tt>true</tt> if a connection was established, <tt>false</tt> if
+ * this client socket is in non-blocking mode and the connection
+ * operation is in progress
* @throws Exception
*/
protected abstract boolean connect(H handle, SocketAddress remoteAddress) throws Exception;
@@ -256,19 +270,26 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
/**
* Create a new {@link IoSession} from a connected socket client handle.
- * Will assign the created {@link IoSession} to the given {@link IoProcessor} for
- * managing future I/O events.
- * @param processor the processor in charge of this session
- * @param handle the newly connected client socket handle
+ * Will assign the created {@link IoSession} to the given
+ * {@link IoProcessor} for managing future I/O events.
+ *
+ * @param processor
+ * the processor in charge of this session
+ * @param handle
+ * the newly connected client socket handle
* @return a new {@link IoSession}
- * @throws Exception any exception thrown by the underlying systems calls
+ * @throws Exception
+ * any exception thrown by the underlying systems calls
*/
protected abstract T newSession(IoProcessor<T> processor, H handle) throws Exception;
/**
* Close a client socket.
- * @param handle the client socket
- * @throws Exception any exception thrown by the underlying systems calls
+ *
+ * @param handle
+ * the client socket
+ * @throws Exception
+ * any exception thrown by the underlying systems calls
*/
protected abstract void close(H handle) throws Exception;
@@ -279,11 +300,13 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
protected abstract void wakeup();
/**
- * Check for connected sockets, interrupt when at least a connection is processed (connected or
- * failed to connect). All the client socket descriptors processed need to be returned by
- * {@link #selectedHandles()}
+ * Check for connected sockets, interrupt when at least a connection is
+ * processed (connected or failed to connect). All the client socket
+ * descriptors processed need to be returned by {@link #selectedHandles()}
+ *
* @return The number of socket having received some data
- * @throws Exception any exception thrown by the underlying systems calls
+ * @throws Exception
+ * any exception thrown by the underlying systems calls
*/
protected abstract int select(int timeout) throws Exception;
@@ -297,22 +320,30 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
/**
* {@link Iterator} for all the client sockets polled for connection.
+ *
* @return the list of client sockets currently polled for connection
*/
protected abstract Iterator<H> allHandles();
/**
* Register a new client socket for connection, add it to connection polling
- * @param handle client socket handle
- * @param request the associated {@link ConnectionRequest}
- * @throws Exception any exception thrown by the underlying systems calls
+ *
+ * @param handle
+ * client socket handle
+ * @param request
+ * the associated {@link ConnectionRequest}
+ * @throws Exception
+ * any exception thrown by the underlying systems calls
*/
protected abstract void register(H handle, ConnectionRequest request) throws Exception;
/**
* get the {@link ConnectionRequest} for a given client socket handle
- * @param handle the socket client handle
- * @return the connection request if the socket is connecting otherwise <code>null</code>
+ *
+ * @param handle
+ * the socket client handle
+ * @return the connection request if the socket is connecting otherwise
+ * <code>null</code>
*/
protected abstract ConnectionRequest getConnectionRequest(H handle);
@@ -437,8 +468,8 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
}
/**
- * Process the incoming connections, creating a new session for each
- * valid connection.
+ * Process the incoming connections, creating a new session for each valid
+ * connection.
*/
private int processConnections(Iterator<H> handlers) {
int nHandles = 0;
@@ -506,7 +537,8 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
nHandles += registerNew();
- // get a chance to get out of the connector loop, if we don't have any more handles
+ // get a chance to get out of the connector loop, if we
+ // don't have any more handles
if (nHandles == 0) {
connectorRef.set(null);
@@ -581,13 +613,13 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
public ConnectionRequest(H handle, IoSessionInitializer<? extends ConnectFuture> callback) {
this.handle = handle;
long timeout = getConnectTimeoutMillis();
-
+
if (timeout <= 0L) {
this.deadline = Long.MAX_VALUE;
} else {
this.deadline = System.currentTimeMillis() + timeout;
}
-
+
this.sessionInitializer = callback;
}
@@ -607,7 +639,7 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
public boolean cancel() {
if (!isDone()) {
boolean justCancelled = super.cancel();
-
+
// We haven't cancelled the request before, so add the future
// in the cancel queue.
if (justCancelled) {
@@ -616,7 +648,7 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
wakeup();
}
}
-
+
return true;
}
}