hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1151823 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/nio/pool/RouteSpecificPool.java main/java/org/apache/http/nio/pool/SessionPool.java test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java
Date Thu, 28 Jul 2011 12:47:37 GMT
Author: olegk
Date: Thu Jul 28 12:47:36 2011
New Revision: 1151823

URL: http://svn.apache.org/viewvc?rev=1151823&view=rev
Log:
Renamed instance variables and methods

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/SessionPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java?rev=1151823&r1=1151822&r2=1151823&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
Thu Jul 28 12:47:36 2011
@@ -41,55 +41,55 @@ import org.apache.http.pool.PoolEntry;
 abstract class RouteSpecificPool<T, E extends PoolEntry<T, IOSession>> {
 
     private final T route;
-    private final Set<E> leasedSessions;
-    private final LinkedList<E> availableSessions;
-    private final Map<SessionRequest, PoolEntryCallback<E>> pendingSessions;
+    private final Set<E> leased;
+    private final LinkedList<E> available;
+    private final Map<SessionRequest, PoolEntryCallback<E>> pending;
 
     RouteSpecificPool(final T route) {
         super();
         this.route = route;
-        this.leasedSessions = new HashSet<E>();
-        this.availableSessions = new LinkedList<E>();
-        this.pendingSessions = new HashMap<SessionRequest, PoolEntryCallback<E>>();
+        this.leased = new HashSet<E>();
+        this.available = new LinkedList<E>();
+        this.pending = new HashMap<SessionRequest, PoolEntryCallback<E>>();
     }
 
     protected abstract E createEntry(T route, IOSession session);
 
     public int getLeasedCount() {
-        return this.leasedSessions.size();
+        return this.leased.size();
     }
 
     public int getPendingCount() {
-        return this.pendingSessions.size();
+        return this.pending.size();
     }
 
     public int getAvailableCount() {
-        return this.availableSessions.size();
+        return this.available.size();
     }
 
     public int getAllocatedCount() {
-        return this.availableSessions.size() + this.leasedSessions.size() + this.pendingSessions.size();
+        return this.available.size() + this.leased.size() + this.pending.size();
     }
 
-    public E getFreeEntry(final Object state) {
-        if (!this.availableSessions.isEmpty()) {
+    public E getFree(final Object state) {
+        if (!this.available.isEmpty()) {
             if (state != null) {
-                Iterator<E> it = this.availableSessions.iterator();
+                Iterator<E> it = this.available.iterator();
                 while (it.hasNext()) {
                     E entry = it.next();
                     if (state.equals(entry.getState())) {
                         it.remove();
-                        this.leasedSessions.add(entry);
+                        this.leased.add(entry);
                         return entry;
                     }
                 }
             }
-            Iterator<E> it = this.availableSessions.iterator();
+            Iterator<E> it = this.available.iterator();
             while (it.hasNext()) {
                 E entry = it.next();
                 if (entry.getState() == null) {
                     it.remove();
-                    this.leasedSessions.add(entry);
+                    this.leased.add(entry);
                     return entry;
                 }
             }
@@ -101,36 +101,36 @@ abstract class RouteSpecificPool<T, E ex
         if (entry == null) {
             throw new IllegalArgumentException("Pool entry may not be null");
         }
-        if (!this.availableSessions.remove(entry)) {
-            if (!this.leasedSessions.remove(entry)) {
+        if (!this.available.remove(entry)) {
+            if (!this.leased.remove(entry)) {
                 return false;
             }
         }
         return true;
     }
 
-    public void freeEntry(final E entry, boolean reusable) {
+    public void free(final E entry, boolean reusable) {
         if (entry == null) {
             throw new IllegalArgumentException("Pool entry may not be null");
         }
-        boolean found = this.leasedSessions.remove(entry);
+        boolean found = this.leased.remove(entry);
         if (!found) {
             throw new IllegalStateException("Entry " + entry +
                     " has not been leased from this pool");
         }
         if (reusable) {
-            this.availableSessions.add(entry);
+            this.available.add(entry);
         }
     }
 
     public void addPending(
             final SessionRequest sessionRequest,
             final PoolEntryCallback<E> callback) {
-        this.pendingSessions.put(sessionRequest, callback);
+        this.pending.put(sessionRequest, callback);
     }
 
     private PoolEntryCallback<E> removeRequest(final SessionRequest request) {
-        PoolEntryCallback<E> callback = this.pendingSessions.remove(request);
+        PoolEntryCallback<E> callback = this.pending.remove(request);
         if (callback == null) {
             throw new IllegalStateException("Invalid session request");
         }
@@ -141,7 +141,7 @@ abstract class RouteSpecificPool<T, E ex
         PoolEntryCallback<E> callback = removeRequest(request);
         IOSession iosession = request.getSession();
         E entry = createEntry(this.route, iosession);
-        this.leasedSessions.add(entry);
+        this.leased.add(entry);
         callback.completed(entry);
         return entry;
     }
@@ -162,18 +162,18 @@ abstract class RouteSpecificPool<T, E ex
     }
 
     public void shutdown() {
-        for (SessionRequest sessionRequest: this.pendingSessions.keySet()) {
+        for (SessionRequest sessionRequest: this.pending.keySet()) {
             sessionRequest.cancel();
         }
-        this.pendingSessions.clear();
-        for (E entry: this.availableSessions) {
+        this.pending.clear();
+        for (E entry: this.available) {
             entry.getConnection().close();
         }
-        this.availableSessions.clear();
-        for (E entry: this.leasedSessions) {
+        this.available.clear();
+        for (E entry: this.leased) {
             entry.getConnection().close();
         }
-        this.leasedSessions.clear();
+        this.leased.clear();
     }
 
     @Override
@@ -182,11 +182,11 @@ abstract class RouteSpecificPool<T, E ex
         buffer.append("[route: ");
         buffer.append(this.route);
         buffer.append("][leased: ");
-        buffer.append(this.leasedSessions.size());
+        buffer.append(this.leased.size());
         buffer.append("][available: ");
-        buffer.append(this.availableSessions.size());
+        buffer.append(this.available.size());
         buffer.append("][pending: ");
-        buffer.append(this.pendingSessions.size());
+        buffer.append(this.pending.size());
         buffer.append("]");
         return buffer.toString();
     }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/SessionPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/SessionPool.java?rev=1151823&r1=1151822&r2=1151823&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/SessionPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/SessionPool.java
Thu Jul 28 12:47:36 2011
@@ -52,9 +52,9 @@ public abstract class SessionPool<T, E e
     private final SessionRequestCallback sessionRequestCallback;
     private final Map<T, RouteSpecificPool<T, E>> routeToPool;
     private final LinkedList<LeaseRequest<T, E>> leasingRequests;
-    private final Set<SessionRequest> pendingSessions;
-    private final Set<E> leasedSessions;
-    private final LinkedList<E> availableSessions;
+    private final Set<SessionRequest> pending;
+    private final Set<E> leased;
+    private final LinkedList<E> available;
     private final Map<T, Integer> maxPerRoute;
     private final Lock lock;
 
@@ -80,9 +80,9 @@ public abstract class SessionPool<T, E e
         this.sessionRequestCallback = new InternalSessionRequestCallback();
         this.routeToPool = new HashMap<T, RouteSpecificPool<T, E>>();
         this.leasingRequests = new LinkedList<LeaseRequest<T, E>>();
-        this.pendingSessions = new HashSet<SessionRequest>();
-        this.leasedSessions = new HashSet<E>();
-        this.availableSessions = new LinkedList<E>();
+        this.pending = new HashSet<SessionRequest>();
+        this.leased = new HashSet<E>();
+        this.available = new LinkedList<E>();
         this.maxPerRoute = new HashMap<T, Integer>();
         this.lock = new ReentrantLock();
         this.defaultMaxPerRoute = defaultMaxPerRoute;
@@ -108,22 +108,22 @@ public abstract class SessionPool<T, E e
         this.isShutDown = true;
         this.lock.lock();
         try {
-            for (SessionRequest sessionRequest: this.pendingSessions) {
+            for (SessionRequest sessionRequest: this.pending) {
                 sessionRequest.cancel();
             }
-            for (E entry: this.availableSessions) {
+            for (E entry: this.available) {
                 closeEntry(entry);
             }
-            for (E entry: this.leasedSessions) {
+            for (E entry: this.leased) {
                 closeEntry(entry);
             }
             for (RouteSpecificPool<T, E> pool: this.routeToPool.values()) {
                 pool.shutdown();
             }
             this.routeToPool.clear();
-            this.leasedSessions.clear();
-            this.pendingSessions.clear();
-            this.availableSessions.clear();
+            this.leased.clear();
+            this.pending.clear();
+            this.available.clear();
             this.leasingRequests.clear();
             this.ioreactor.shutdown(waitMs);
         } finally {
@@ -184,11 +184,11 @@ public abstract class SessionPool<T, E e
         }
         this.lock.lock();
         try {
-            if (this.leasedSessions.remove(entry)) {
+            if (this.leased.remove(entry)) {
                 RouteSpecificPool<T, E> pool = getPool(entry.getRoute());
-                pool.freeEntry(entry, reusable);
+                pool.free(entry, reusable);
                 if (reusable) {
-                    this.availableSessions.add(entry);
+                    this.available.add(entry);
                 } else {
                     closeEntry(entry);
                 }
@@ -212,32 +212,32 @@ public abstract class SessionPool<T, E e
             RouteSpecificPool<T, E> pool = getPool(request.getRoute());
             E entry = null;
             for (;;) {
-                entry = pool.getFreeEntry(state);
+                entry = pool.getFree(state);
                 if (entry == null) {
                     break;
                 }
                 if (entry.isExpired(System.currentTimeMillis())) {
                     closeEntry(entry);
-                    this.availableSessions.remove(entry);
-                    pool.freeEntry(entry, false);
+                    this.available.remove(entry);
+                    pool.free(entry, false);
                 } else {
                     break;
                 }
             }
             if (entry != null) {
                 it.remove();
-                this.availableSessions.remove(entry);
-                this.leasedSessions.add(entry);
+                this.available.remove(entry);
+                this.leased.add(entry);
                 callback.completed(entry);
                 continue;
             }
             if (pool.getAllocatedCount() < getMaxPerRoute(route)) {
-                int totalUsed = this.pendingSessions.size() + this.leasedSessions.size();
+                int totalUsed = this.pending.size() + this.leased.size();
                 int freeCapacity = Math.max(this.maxTotal - totalUsed, 0);
                 if (freeCapacity == 0) {
                     continue;
                 }
-                int totalAvailable = this.availableSessions.size();
+                int totalAvailable = this.available.size();
                 if (totalAvailable > freeCapacity - 1) {
                     dropLastUsed();
                 }
@@ -248,15 +248,15 @@ public abstract class SessionPool<T, E e
                         route,
                         this.sessionRequestCallback);
                 sessionRequest.setConnectTimeout(timeout);
-                this.pendingSessions.add(sessionRequest);
+                this.pending.add(sessionRequest);
                 pool.addPending(sessionRequest, callback);
             }
         }
     }
 
     private void dropLastUsed() {
-        if (!this.availableSessions.isEmpty()) {
-            E entry = this.availableSessions.removeFirst();
+        if (!this.available.isEmpty()) {
+            E entry = this.available.removeFirst();
             closeEntry(entry);
             RouteSpecificPool<T, E> pool = getPool(entry.getRoute());
             pool.remove(entry);
@@ -271,10 +271,10 @@ public abstract class SessionPool<T, E e
         T route = (T) request.getAttachment();
         this.lock.lock();
         try {
-            this.pendingSessions.remove(request);
+            this.pending.remove(request);
             RouteSpecificPool<T, E> pool = getPool(route);
             E entry = pool.completed(request);
-            this.leasedSessions.add(entry);
+            this.leased.add(entry);
         } finally {
             this.lock.unlock();
         }
@@ -288,7 +288,7 @@ public abstract class SessionPool<T, E e
         T route = (T) request.getAttachment();
         this.lock.lock();
         try {
-            this.pendingSessions.remove(request);
+            this.pending.remove(request);
             RouteSpecificPool<T, E> pool = getPool(route);
             pool.cancelled(request);
         } finally {
@@ -304,7 +304,7 @@ public abstract class SessionPool<T, E e
         T route = (T) request.getAttachment();
         this.lock.lock();
         try {
-            this.pendingSessions.remove(request);
+            this.pending.remove(request);
             RouteSpecificPool<T, E> pool = getPool(route);
             pool.failed(request);
         } finally {
@@ -320,7 +320,7 @@ public abstract class SessionPool<T, E e
         T route = (T) request.getAttachment();
         this.lock.lock();
         try {
-            this.pendingSessions.remove(request);
+            this.pending.remove(request);
             RouteSpecificPool<T, E> pool = getPool(route);
             pool.timeout(request);
         } finally {
@@ -380,9 +380,9 @@ public abstract class SessionPool<T, E e
         this.lock.lock();
         try {
             return new PoolStats(
-                    this.leasedSessions.size(),
-                    this.pendingSessions.size(),
-                    this.availableSessions.size(),
+                    this.leased.size(),
+                    this.pending.size(),
+                    this.available.size(),
                     this.maxTotal);
         } finally {
             this.lock.unlock();
@@ -417,7 +417,7 @@ public abstract class SessionPool<T, E e
         long deadline = System.currentTimeMillis() - time;
         this.lock.lock();
         try {
-            Iterator<E> it = this.availableSessions.iterator();
+            Iterator<E> it = this.available.iterator();
             while (it.hasNext()) {
                 E entry = it.next();
                 if (entry.getUpdated() <= deadline) {
@@ -437,7 +437,7 @@ public abstract class SessionPool<T, E e
         long now = System.currentTimeMillis();
         this.lock.lock();
         try {
-            Iterator<E> it = this.availableSessions.iterator();
+            Iterator<E> it = this.available.iterator();
             while (it.hasNext()) {
                 E entry = it.next();
                 if (entry.isExpired(now)) {
@@ -457,11 +457,11 @@ public abstract class SessionPool<T, E e
     public String toString() {
         StringBuilder buffer = new StringBuilder();
         buffer.append("[leased: ");
-        buffer.append(this.leasedSessions);
+        buffer.append(this.leased);
         buffer.append("][available: ");
-        buffer.append(this.availableSessions);
+        buffer.append(this.available);
         buffer.append("][pending: ");
-        buffer.append(this.pendingSessions);
+        buffer.append(this.pending);
         buffer.append("]");
         return buffer.toString();
     }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java?rev=1151823&r1=1151822&r2=1151823&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java
Thu Jul 28 12:47:36 2011
@@ -238,18 +238,18 @@ public class TestRouteSpecificPool {
         Assert.assertEquals(3, pool.getLeasedCount());
         Assert.assertEquals(0, pool.getPendingCount());
 
-        pool.freeEntry(entry1, true);
-        pool.freeEntry(entry2, false);
-        pool.freeEntry(entry3, true);
+        pool.free(entry1, true);
+        pool.free(entry2, false);
+        pool.free(entry3, true);
 
         Assert.assertEquals(2, pool.getAllocatedCount());
         Assert.assertEquals(2, pool.getAvailableCount());
         Assert.assertEquals(0, pool.getLeasedCount());
         Assert.assertEquals(0, pool.getPendingCount());
 
-        Assert.assertNotNull(pool.getFreeEntry(null));
-        Assert.assertNotNull(pool.getFreeEntry(null));
-        Assert.assertNull(pool.getFreeEntry(null));
+        Assert.assertNotNull(pool.getFree(null));
+        Assert.assertNotNull(pool.getFree(null));
+        Assert.assertNull(pool.getFree(null));
 
         Assert.assertEquals(2, pool.getAllocatedCount());
         Assert.assertEquals(0, pool.getAvailableCount());
@@ -281,28 +281,28 @@ public class TestRouteSpecificPool {
         Assert.assertNotNull(entry3);
 
         entry2.setState(Boolean.FALSE);
-        pool.freeEntry(entry1, true);
-        pool.freeEntry(entry2, true);
-        pool.freeEntry(entry3, true);
-
-        Assert.assertEquals(entry2, pool.getFreeEntry(Boolean.FALSE));
-        Assert.assertEquals(entry1, pool.getFreeEntry(Boolean.FALSE));
-        Assert.assertEquals(entry3, pool.getFreeEntry(null));
-        Assert.assertEquals(null, pool.getFreeEntry(null));
+        pool.free(entry1, true);
+        pool.free(entry2, true);
+        pool.free(entry3, true);
+
+        Assert.assertEquals(entry2, pool.getFree(Boolean.FALSE));
+        Assert.assertEquals(entry1, pool.getFree(Boolean.FALSE));
+        Assert.assertEquals(entry3, pool.getFree(null));
+        Assert.assertEquals(null, pool.getFree(null));
 
         entry1.setState(Boolean.TRUE);
         entry2.setState(Boolean.FALSE);
         entry3.setState(Boolean.TRUE);
-        pool.freeEntry(entry1, true);
-        pool.freeEntry(entry2, true);
-        pool.freeEntry(entry3, true);
-
-        Assert.assertEquals(null, pool.getFreeEntry(null));
-        Assert.assertEquals(entry2, pool.getFreeEntry(Boolean.FALSE));
-        Assert.assertEquals(null, pool.getFreeEntry(Boolean.FALSE));
-        Assert.assertEquals(entry1, pool.getFreeEntry(Boolean.TRUE));
-        Assert.assertEquals(entry3, pool.getFreeEntry(Boolean.TRUE));
-        Assert.assertEquals(null, pool.getFreeEntry(Boolean.TRUE));
+        pool.free(entry1, true);
+        pool.free(entry2, true);
+        pool.free(entry3, true);
+
+        Assert.assertEquals(null, pool.getFree(null));
+        Assert.assertEquals(entry2, pool.getFree(Boolean.FALSE));
+        Assert.assertEquals(null, pool.getFree(Boolean.FALSE));
+        Assert.assertEquals(entry1, pool.getFree(Boolean.TRUE));
+        Assert.assertEquals(entry3, pool.getFree(Boolean.TRUE));
+        Assert.assertEquals(null, pool.getFree(Boolean.TRUE));
     }
 
     @Test(expected=IllegalStateException.class)
@@ -310,7 +310,7 @@ public class TestRouteSpecificPool {
         LocalRoutePool pool = new LocalRoutePool();
         IOSession session = Mockito.mock(IOSession.class);
         LocalPoolEntry entry = new LocalPoolEntry("whatever", session);
-        pool.freeEntry(entry, true);
+        pool.free(entry, true);
     }
 
     @Test
@@ -354,8 +354,8 @@ public class TestRouteSpecificPool {
         Assert.assertEquals(2, pool.getLeasedCount());
         Assert.assertEquals(0, pool.getPendingCount());
 
-        pool.freeEntry(entry1, true);
-        pool.freeEntry(entry3, true);
+        pool.free(entry1, true);
+        pool.free(entry3, true);
 
         Assert.assertEquals(2, pool.getAllocatedCount());
         Assert.assertEquals(2, pool.getAvailableCount());
@@ -374,7 +374,7 @@ public class TestRouteSpecificPool {
     @Test(expected=IllegalArgumentException.class)
     public void testReleaseInvalid() throws Exception {
         LocalRoutePool pool = new LocalRoutePool();
-        pool.freeEntry(null, true);
+        pool.free(null, true);
     }
 
     @Test(expected=IllegalArgumentException.class)
@@ -404,7 +404,7 @@ public class TestRouteSpecificPool {
         LocalPoolEntry entry2 = pool.completed(sessionRequest2);
         Assert.assertNotNull(entry2);
 
-        pool.freeEntry(entry1, true);
+        pool.free(entry1, true);
 
         Assert.assertEquals(3, pool.getAllocatedCount());
         Assert.assertEquals(1, pool.getAvailableCount());



Mime
View raw message