hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1154490 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/ httpcore-nio/src/main/java/org/apache/http/nio/pool/ httpcore/src/main/java/org/apache/http/impl/pool/ httpcore/src/main/java/org/apache...
Date Sat, 06 Aug 2011 11:12:34 GMT
Author: olegk
Date: Sat Aug  6 11:12:33 2011
New Revision: 1154490

URL: http://svn.apache.org/viewvc?rev=1154490&view=rev
Log:
Added thread safety annotations; made PoolEntry thread safe

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntryFuture.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolStats.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java?rev=1154490&r1=1154489&r2=1154490&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java
Sat Aug  6 11:12:33 2011
@@ -33,6 +33,7 @@ import java.net.SocketAddress;
 import org.apache.http.HttpConnection;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponseFactory;
+import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.impl.nio.DefaultNHttpClientConnection;
 import org.apache.http.nio.NHttpClientConnection;
@@ -43,6 +44,7 @@ import org.apache.http.nio.util.ByteBuff
 import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
+@ThreadSafe
 public class BasicNIOConnPool extends AbstractNIOConnPool<HttpHost, NHttpClientConnection,
BasicNIOPoolEntry> {
 
     private final HttpResponseFactory responseFactory;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java?rev=1154490&r1=1154489&r2=1154490&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java
Sat Aug  6 11:12:33 2011
@@ -27,9 +27,11 @@
 package org.apache.http.impl.nio.pool;
 
 import org.apache.http.HttpHost;
+import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.nio.NHttpClientConnection;
 import org.apache.http.pool.PoolEntry;
 
+@ThreadSafe
 public class BasicNIOPoolEntry extends PoolEntry<HttpHost, NHttpClientConnection> {
 
     public BasicNIOPoolEntry(final HttpHost route, final NHttpClientConnection conn) {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java?rev=1154490&r1=1154489&r2=1154490&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
Sat Aug  6 11:12:33 2011
@@ -40,6 +40,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.concurrent.BasicFuture;
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
@@ -50,6 +51,7 @@ import org.apache.http.pool.ConnPoolCont
 import org.apache.http.pool.PoolEntry;
 import org.apache.http.pool.PoolStats;
 
+@ThreadSafe
 public abstract class AbstractNIOConnPool<T, C, E extends PoolEntry<T, C>> implements
ConnPoolControl<T> {
 
     private final ConnectingIOReactor ioreactor;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java?rev=1154490&r1=1154489&r2=1154490&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
Sat Aug  6 11:12:33 2011
@@ -26,9 +26,11 @@
  */
 package org.apache.http.nio.pool;
 
+import org.apache.http.annotation.Immutable;
 import org.apache.http.concurrent.BasicFuture;
 import org.apache.http.pool.PoolEntry;
 
+@Immutable
 class LeaseRequest<T, C, E extends PoolEntry<T, C>> {
 
     private final T route;

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=1154490&r1=1154489&r2=1154490&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
Sat Aug  6 11:12:33 2011
@@ -34,10 +34,12 @@ import java.util.LinkedList;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.concurrent.BasicFuture;
 import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.pool.PoolEntry;
 
+@NotThreadSafe
 abstract class RouteSpecificPool<T, C, E extends PoolEntry<T, C>> {
 
     private final T route;

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java?rev=1154490&r1=1154489&r2=1154490&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnPool.java
Sat Aug  6 11:12:33 2011
@@ -35,11 +35,13 @@ import javax.net.ssl.SSLSocketFactory;
 import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpConnection;
 import org.apache.http.HttpHost;
+import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.impl.DefaultHttpClientConnection;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.pool.AbstractConnPool;
 
+@ThreadSafe
 public class BasicConnPool extends AbstractConnPool<HttpHost, HttpClientConnection, BasicPoolEntry>
{
 
     private final SSLSocketFactory sslfactory;

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java?rev=1154490&r1=1154489&r2=1154490&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicPoolEntry.java
Sat Aug  6 11:12:33 2011
@@ -28,8 +28,10 @@ package org.apache.http.impl.pool;
 
 import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpHost;
+import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.pool.PoolEntry;
 
+@ThreadSafe
 public class BasicPoolEntry extends PoolEntry<HttpHost, HttpClientConnection> {
 
     public BasicPoolEntry(final HttpHost route, final HttpClientConnection conn) {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java?rev=1154490&r1=1154489&r2=1154490&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
Sat Aug  6 11:12:33 2011
@@ -40,14 +40,17 @@ import java.util.concurrent.TimeoutExcep
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import org.apache.http.annotation.ThreadSafe;
+
+@ThreadSafe
 public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>> implements
ConnPoolControl<T> {
 
+    private final Lock lock;
     private final Map<T, RouteSpecificPool<T, C, E>> routeToPool;
     private final Set<E> leased;
     private final LinkedList<E> available;
     private final LinkedList<PoolEntryFuture<E>> pending;
     private final Map<T, Integer> maxPerRoute;
-    private final Lock lock;
 
     private volatile boolean isShutDown;
     private volatile int defaultMaxPerRoute;
@@ -63,12 +66,12 @@ public abstract class AbstractConnPool<T
         if (maxTotal <= 0) {
             throw new IllegalArgumentException("Max total value may not be negative or zero");
         }
+        this.lock = new ReentrantLock();
         this.routeToPool = new HashMap<T, RouteSpecificPool<T, C, E>>();
         this.leased = new HashSet<E>();
         this.available = new LinkedList<E>();
         this.pending = new LinkedList<PoolEntryFuture<E>>();
         this.maxPerRoute = new HashMap<T, Integer>();
-        this.lock = new ReentrantLock();
         this.defaultMaxPerRoute = defaultMaxPerRoute;
         this.maxTotal = maxTotal;
     }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java?rev=1154490&r1=1154489&r2=1154490&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
Sat Aug  6 11:12:33 2011
@@ -29,6 +29,9 @@ package org.apache.http.pool;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.apache.http.annotation.ThreadSafe;
+
+@ThreadSafe
 public class PoolEntry<T, C> {
 
     private static AtomicLong COUNTER = new AtomicLong();
@@ -70,6 +73,10 @@ public class PoolEntry<T, C> {
         this(route, conn, 0, TimeUnit.MILLISECONDS);
     }
 
+    public long getId() {
+        return this.id;
+    }
+
     public T getRoute() {
         return this.route;
     }
@@ -94,15 +101,15 @@ public class PoolEntry<T, C> {
         this.state = state;
     }
 
-    public long getUpdated() {
+    public synchronized long getUpdated() {
         return this.updated;
     }
 
-    public long getExpiry() {
+    public synchronized long getExpiry() {
         return this.expiry;
     }
 
-    public void updateExpiry(final long time, final TimeUnit tunit) {
+    public synchronized void updateExpiry(final long time, final TimeUnit tunit) {
         if (tunit == null) {
             throw new IllegalArgumentException("Time unit may not be null");
         }
@@ -116,7 +123,7 @@ public class PoolEntry<T, C> {
         this.expiry = Math.min(newExpiry, this.validUnit);
     }
 
-    public boolean isExpired(final long now) {
+    public synchronized boolean isExpired(final long now) {
         return now >= this.expiry;
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntryFuture.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntryFuture.java?rev=1154490&r1=1154489&r2=1154490&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntryFuture.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolEntryFuture.java
Sat Aug  6 11:12:33 2011
@@ -35,6 +35,9 @@ import java.util.concurrent.TimeoutExcep
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
 
+import org.apache.http.annotation.ThreadSafe;
+
+@ThreadSafe
 abstract class PoolEntryFuture<T> implements Future<T> {
 
     private final Lock lock;

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolStats.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolStats.java?rev=1154490&r1=1154489&r2=1154490&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolStats.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/PoolStats.java
Sat Aug  6 11:12:33 2011
@@ -26,6 +26,9 @@
  */
 package org.apache.http.pool;
 
+import org.apache.http.annotation.Immutable;
+
+@Immutable
 public class PoolStats {
 
     private final int leased;



Mime
View raw message