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 2017/01/07 11:16:14 UTC
svn commit: r1777763 - in /httpcomponents/httpcore/trunk/httpcore5/src:
main/java/org/apache/hc/core5/pool/ test/java/org/apache/hc/core5/pool/
Author: olegk
Date: Sat Jan 7 11:16:13 2017
New Revision: 1777763
URL: http://svn.apache.org/viewvc?rev=1777763&view=rev
Log:
Simplified PoolEntry API contract
Modified:
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java
httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java
httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestRouteSpecificPool.java
httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java?rev=1777763&r1=1777762&r2=1777763&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java Sat Jan 7 11:16:13 2017
@@ -123,6 +123,7 @@ public final class PoolEntry<T, C extend
this.updated = this.created;
this.validityDeadline = this.timeToLive > 0 ? System.currentTimeMillis() + this.timeToLive : Long.MAX_VALUE;
this.expiry = this.validityDeadline;
+ this.state = null;
} else {
throw new IllegalStateException("Connection already assigned");
}
@@ -160,17 +161,20 @@ public final class PoolEntry<T, C extend
/**
* @since 5.0
*/
- public void updateConnection(final long keepAlive, final TimeUnit timeUnit, final Object state) {
+ public void updateExpiry(final long keepAlive, final TimeUnit timeUnit) {
Args.notNull(timeUnit, "Time unit");
- if (this.connRef.get() != null) {
- this.state = state;
- final long currentTime = System.currentTimeMillis();
- final long newExpiry = keepAlive > 0 ? currentTime + timeUnit.toMillis(keepAlive) : Long.MAX_VALUE;
- this.expiry = Math.min(newExpiry, getValidityDeadline());
- this.updated = currentTime;
- } else {
- throw new IllegalStateException("Connection not assigned");
- }
+ final long currentTime = System.currentTimeMillis();
+ final long newExpiry = keepAlive > 0 ? currentTime + timeUnit.toMillis(keepAlive) : Long.MAX_VALUE;
+ this.expiry = Math.min(newExpiry, getValidityDeadline());
+ this.updated = currentTime;
+ }
+
+ /**
+ * @since 5.0
+ */
+ public void updateState(final Object state) {
+ this.state = state;
+ this.updated = System.currentTimeMillis();
}
@Override
Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java?rev=1777763&r1=1777762&r2=1777763&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java Sat Jan 7 11:16:13 2017
@@ -73,17 +73,17 @@ public class TestPoolEntry {
final PoolEntry<String, HttpConnection> entry1 = new PoolEntry<>("route1", 0L, TimeUnit.MILLISECONDS);
entry1.assignConnection(Mockito.mock(HttpConnection.class));
Assert.assertEquals(Long.MAX_VALUE, entry1.getExpiry());
- entry1.updateConnection(50L, TimeUnit.MILLISECONDS, null);
+ entry1.updateExpiry(50L, TimeUnit.MILLISECONDS);
Assert.assertEquals(entry1.getUpdated() + 50L, entry1.getExpiry());
- entry1.updateConnection(0L, TimeUnit.MILLISECONDS, null);
+ entry1.updateExpiry(0L, TimeUnit.MILLISECONDS);
Assert.assertEquals(Long.MAX_VALUE, entry1.getExpiry());
final PoolEntry<String, HttpConnection> entry2 = new PoolEntry<>("route1", 100L, TimeUnit.MILLISECONDS);
entry2.assignConnection(Mockito.mock(HttpConnection.class));
Assert.assertEquals(entry2.getUpdated() + 100L, entry2.getExpiry());
- entry2.updateConnection(150L, TimeUnit.MILLISECONDS, null);
+ entry2.updateExpiry(150L, TimeUnit.MILLISECONDS);
Assert.assertEquals(entry2.getUpdated() + 100L, entry2.getExpiry());
- entry2.updateConnection(50L, TimeUnit.MILLISECONDS, null);
+ entry2.updateExpiry(50L, TimeUnit.MILLISECONDS);
Assert.assertEquals(entry2.getUpdated() + 50L, entry2.getExpiry());
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestRouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestRouteSpecificPool.java?rev=1777763&r1=1777762&r2=1777763&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestRouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestRouteSpecificPool.java Sat Jan 7 11:16:13 2017
@@ -154,7 +154,7 @@ public class TestRouteSpecificPool {
Assert.assertEquals(0, pool.getAvailableCount());
Assert.assertEquals(3, pool.getLeasedCount());
- entry2.updateConnection(0, TimeUnit.MILLISECONDS, Boolean.FALSE);
+ entry2.updateState(Boolean.FALSE);
pool.free(entry1, true);
pool.free(entry2, true);
pool.free(entry3, true);
@@ -164,9 +164,9 @@ public class TestRouteSpecificPool {
Assert.assertSame(entry1, pool.getFree(null));
Assert.assertSame(null, pool.getFree(null));
- entry1.updateConnection(0, TimeUnit.MILLISECONDS, Boolean.TRUE);
- entry2.updateConnection(0, TimeUnit.MILLISECONDS, Boolean.FALSE);
- entry3.updateConnection(0, TimeUnit.MILLISECONDS, Boolean.TRUE);
+ entry1.updateState(Boolean.TRUE);
+ entry2.updateState(Boolean.FALSE);
+ entry3.updateState(Boolean.TRUE);
pool.free(entry1, true);
pool.free(entry2, true);
pool.free(entry3, true);
Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java?rev=1777763&r1=1777762&r2=1777763&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java Sat Jan 7 11:16:13 2017
@@ -316,9 +316,9 @@ public class TestStrictConnPool {
Assert.assertEquals(2, totals.getLeased());
Assert.assertEquals(0, totals.getPending());
- entry1.updateConnection(0, TimeUnit.MILLISECONDS, "some-stuff");
+ entry1.updateState("some-stuff");
pool.release(entry1, true);
- entry2.updateConnection(0, TimeUnit.MILLISECONDS, "some-stuff");
+ entry2.updateState("some-stuff");
pool.release(entry2, true);
final Future<PoolEntry<String, HttpConnection>> future3 = pool.lease("somehost", "some-stuff");
@@ -366,7 +366,7 @@ public class TestStrictConnPool {
Assert.assertNotNull(entry1);
entry1.assignConnection(conn1);
- entry1.updateConnection(1, TimeUnit.MILLISECONDS, null);
+ entry1.updateExpiry(1, TimeUnit.MILLISECONDS);
pool.release(entry1, true);
Thread.sleep(200L);
@@ -405,12 +405,12 @@ public class TestStrictConnPool {
Assert.assertNotNull(entry2);
entry2.assignConnection(conn2);
- entry1.updateConnection(1, TimeUnit.MILLISECONDS, null);
+ entry1.updateExpiry(1, TimeUnit.MILLISECONDS);
pool.release(entry1, true);
Thread.sleep(200);
- entry2.updateConnection(1000, TimeUnit.SECONDS, null);
+ entry2.updateExpiry(1000, TimeUnit.SECONDS);
pool.release(entry2, true);
pool.closeExpired();
@@ -447,12 +447,12 @@ public class TestStrictConnPool {
Assert.assertNotNull(entry2);
entry2.assignConnection(conn2);
- entry1.updateConnection(0, TimeUnit.MILLISECONDS, null);
+ entry1.updateState(null);
pool.release(entry1, true);
Thread.sleep(200L);
- entry2.updateConnection(0, TimeUnit.MILLISECONDS, null);
+ entry2.updateState(null);
pool.release(entry2, true);
pool.closeIdle(50, TimeUnit.MILLISECONDS);