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/05/10 07:33:48 UTC

[01/13] httpcomponents-core git commit: HTTPCORE-433: moved expensive connection validation code outside the pool lock

Repository: httpcomponents-core
Updated Branches:
  refs/heads/4.4.x c9810ec11 -> 44344d4cf
  refs/heads/HTTPCORE-433 [created] 57540dce7
  refs/heads/HTTPCORE-446 [created] 67bcb4201
  refs/heads/trunk 9c362d4a2 -> 3a677d47c


HTTPCORE-433: moved expensive connection validation code outside the pool lock


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/57540dce
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/57540dce
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/57540dce

Branch: refs/heads/HTTPCORE-433
Commit: 57540dce791f02274e9a924f8d4b6d8dee36066d
Parents: 536cbad
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sat Nov 19 19:24:26 2016 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Sat Nov 19 19:47:25 2016 +0100

----------------------------------------------------------------------
 .../org/apache/http/pool/AbstractConnPool.java  | 47 ++++++++++----------
 .../java/org/apache/http/pool/PoolEntry.java    |  3 +-
 .../java/org/apache/http/pool/TestConnPool.java |  4 +-
 3 files changed, 27 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/57540dce/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java b/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
index 51b0453..d34cf24 100644
--- a/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
+++ b/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
@@ -234,22 +234,30 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
 
             @Override
             public E get(final long timeout, final TimeUnit tunit) throws InterruptedException, ExecutionException, TimeoutException {
-                final E local = entry;
-                if (local != null) {
-                    return local;
+                if (entry != null) {
+                    return entry;
                 }
                 synchronized (this) {
                     try {
-                        if (entry != null) {
+                        for (;;) {
+                            final E leasedEntry = getPoolEntryBlocking(route, state, timeout, tunit, this);
+                            if (validateAfterInactivity > 0)  {
+                                if (leasedEntry.getUpdated() + validateAfterInactivity <= System.currentTimeMillis()) {
+                                    if (!validate(leasedEntry)) {
+                                        leasedEntry.close();
+                                        release(leasedEntry, false);
+                                        continue;
+                                    }
+                                }
+                            }
+                            entry = leasedEntry;
+                            done = true;
+                            onLease(entry);
+                            if (callback != null) {
+                                callback.completed(entry);
+                            }
                             return entry;
                         }
-                        entry = getPoolEntryBlocking(route, state, timeout, tunit, this);
-                        done = true;
-                        onLease(entry);
-                        if (callback != null) {
-                            callback.completed(entry);
-                        }
-                        return entry;
                     } catch (IOException ex) {
                         done = true;
                         if (callback != null) {
@@ -290,15 +298,13 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
 
         Date deadline = null;
         if (timeout > 0) {
-            deadline = new Date
-                (System.currentTimeMillis() + tunit.toMillis(timeout));
+            deadline = new Date (System.currentTimeMillis() + tunit.toMillis(timeout));
         }
-
         this.lock.lock();
         try {
             final RouteSpecificPool<T, C, E> pool = getPool(route);
-            E entry = null;
-            while (entry == null) {
+            E entry;
+            for (;;) {
                 Asserts.check(!this.isShutDown, "Connection pool shut down");
                 for (;;) {
                     entry = pool.getFree(state);
@@ -307,12 +313,6 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
                     }
                     if (entry.isExpired(System.currentTimeMillis())) {
                         entry.close();
-                    } else if (this.validateAfterInactivity > 0) {
-                        if (entry.getUpdated() + this.validateAfterInactivity <= System.currentTimeMillis()) {
-                            if (!validate(entry)) {
-                                entry.close();
-                            }
-                        }
                     }
                     if (entry.isClosed()) {
                         this.available.remove(entry);
@@ -389,8 +389,7 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
                     this.pending.remove(future);
                 }
                 // check for spurious wakeup vs. timeout
-                if (!success && (deadline != null) &&
-                    (deadline.getTime() <= System.currentTimeMillis())) {
+                if (!success && (deadline != null && deadline.getTime() <= System.currentTimeMillis())) {
                     break;
                 }
             }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/57540dce/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java b/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
index e334e24..31b8ee2 100644
--- a/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
+++ b/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
@@ -28,8 +28,8 @@ package org.apache.http.pool;
 
 import java.util.concurrent.TimeUnit;
 
-import org.apache.http.annotation.ThreadingBehavior;
 import org.apache.http.annotation.Contract;
+import org.apache.http.annotation.ThreadingBehavior;
 import org.apache.http.util.Args;
 
 /**
@@ -83,6 +83,7 @@ public abstract class PoolEntry<T, C> {
         this.route = route;
         this.conn = conn;
         this.created = System.currentTimeMillis();
+        this.updated = this.created;
         if (timeToLive > 0) {
             this.validityDeadline = this.created + tunit.toMillis(timeToLive);
         } else {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/57540dce/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java b/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java
index 24c2fa1..75ebb26 100644
--- a/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java
+++ b/httpcore/src/test/java/org/apache/http/pool/TestConnPool.java
@@ -806,7 +806,7 @@ public class TestConnPool {
         Mockito.when(connFactory.create(Mockito.eq("somehost"))).thenReturn(conn);
 
         final LocalConnPool pool = new LocalConnPool(connFactory, 2, 10);
-        pool.setValidateAfterInactivity(5);
+        pool.setValidateAfterInactivity(100);
 
         final Future<LocalPoolEntry> future1 = pool.lease("somehost", null);
         final LocalPoolEntry entry1 = future1.get(1, TimeUnit.SECONDS);
@@ -814,7 +814,7 @@ public class TestConnPool {
 
         pool.release(entry1, true);
 
-        Thread.sleep(10);
+        Thread.sleep(150);
 
         final Future<LocalPoolEntry> future2 = pool.lease("somehost", null);
         final LocalPoolEntry entry2 = future2.get(1, TimeUnit.SECONDS);


[06/13] httpcomponents-core git commit: Change the example's hard-coded strings so that you can actually run it with SSL out of the box.

Posted by ol...@apache.org.
Change the example's hard-coded strings so that you can actually run it with SSL out of the box.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1794638 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/8b6a310f
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/8b6a310f
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/8b6a310f

Branch: refs/heads/4.4.x
Commit: 8b6a310f21b5ddc5ac3ba7c242fdd2ac1471b967
Parents: c9810ec
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue May 9 21:37:46 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue May 9 21:37:46 2017 +0000

----------------------------------------------------------------------
 .../examples/org/apache/http/examples/nio/NHttpFileServer.java   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8b6a310f/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
index 612c02e..56dba42 100644
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
@@ -78,13 +78,13 @@ public class NHttpFileServer {
         SSLContext sslContext = null;
         if (port == 8443) {
             // Initialize SSL context
-            URL url = NHttpFileServer.class.getResource("/my.keystore");
+            URL url = NHttpFileServer.class.getResource("/test.keystore");
             if (url == null) {
                 System.out.println("Keystore not found");
                 System.exit(1);
             }
             sslContext = SSLContexts.custom()
-                    .loadKeyMaterial(url, "secret".toCharArray(), "secret".toCharArray())
+                    .loadKeyMaterial(url, "nopassword".toCharArray(), "nopassword".toCharArray())
                     .build();
         }
 


[02/13] httpcomponents-core git commit: HTTPCORE-433: redesign of connection request future used by blocking AbstractConnPool

Posted by ol...@apache.org.
HTTPCORE-433: redesign of connection request future used by blocking AbstractConnPool


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/536cbad2
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/536cbad2
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/536cbad2

Branch: refs/heads/HTTPCORE-433
Commit: 536cbad26c053ffd42317ff5d3b88f0e582660b7
Parents: 58c75ad
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sat Nov 19 17:47:59 2016 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Sat Nov 19 19:47:25 2016 +0100

----------------------------------------------------------------------
 .../org/apache/http/pool/AbstractConnPool.java  | 107 ++++++++++--
 .../org/apache/http/pool/PoolEntryFuture.java   | 161 -------------------
 .../org/apache/http/pool/RouteSpecificPool.java |  13 +-
 .../apache/http/pool/TestRouteSpecificPool.java |   7 +-
 4 files changed, 102 insertions(+), 186 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/536cbad2/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java b/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
index 98831e0..51b0453 100644
--- a/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
+++ b/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
@@ -34,14 +34,16 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
-import org.apache.http.annotation.ThreadingBehavior;
 import org.apache.http.annotation.Contract;
+import org.apache.http.annotation.ThreadingBehavior;
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.util.Args;
 import org.apache.http.util.Asserts;
@@ -66,11 +68,12 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
                                                implements ConnPool<T, E>, ConnPoolControl<T> {
 
     private final Lock lock;
+    private final Condition condition;
     private final ConnFactory<T, C> connFactory;
     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 LinkedList<Future<E>> pending;
     private final Map<T, Integer> maxPerRoute;
 
     private volatile boolean isShutDown;
@@ -87,10 +90,11 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
         this.defaultMaxPerRoute = Args.positive(defaultMaxPerRoute, "Max per route value");
         this.maxTotal = Args.positive(maxTotal, "Max total value");
         this.lock = new ReentrantLock();
+        this.condition = this.lock.newCondition();
         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.pending = new LinkedList<Future<E>>();
         this.maxPerRoute = new HashMap<T, Integer>();
     }
 
@@ -183,16 +187,77 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
     public Future<E> lease(final T route, final Object state, final FutureCallback<E> callback) {
         Args.notNull(route, "Route");
         Asserts.check(!this.isShutDown, "Connection pool shut down");
-        return new PoolEntryFuture<E>(this.lock, callback) {
+
+        return new Future<E>() {
+
+            private volatile boolean cancelled;
+            private volatile boolean done;
+            private volatile E entry;
+
+            @Override
+            public boolean cancel(final boolean mayInterruptIfRunning) {
+                cancelled = true;
+                lock.lock();
+                try {
+                    condition.signalAll();
+                } finally {
+                    lock.unlock();
+                }
+                synchronized (this) {
+                    final boolean result = !done;
+                    done = true;
+                    if (callback != null) {
+                        callback.cancelled();
+                    }
+                    return result;
+                }
+            }
+
+            @Override
+            public boolean isCancelled() {
+                return cancelled;
+            }
+
+            @Override
+            public boolean isDone() {
+                return done;
+            }
 
             @Override
-            public E getPoolEntry(
-                    final long timeout,
-                    final TimeUnit tunit)
-                        throws InterruptedException, TimeoutException, IOException {
-                final E entry = getPoolEntryBlocking(route, state, timeout, tunit, this);
-                onLease(entry);
-                return entry;
+            public E get() throws InterruptedException, ExecutionException {
+                try {
+                    return get(0L, TimeUnit.MILLISECONDS);
+                } catch (TimeoutException ex) {
+                    throw new ExecutionException(ex);
+                }
+            }
+
+            @Override
+            public E get(final long timeout, final TimeUnit tunit) throws InterruptedException, ExecutionException, TimeoutException {
+                final E local = entry;
+                if (local != null) {
+                    return local;
+                }
+                synchronized (this) {
+                    try {
+                        if (entry != null) {
+                            return entry;
+                        }
+                        entry = getPoolEntryBlocking(route, state, timeout, tunit, this);
+                        done = true;
+                        onLease(entry);
+                        if (callback != null) {
+                            callback.completed(entry);
+                        }
+                        return entry;
+                    } catch (IOException ex) {
+                        done = true;
+                        if (callback != null) {
+                            callback.failed(ex);
+                        }
+                        throw new ExecutionException(ex);
+                    }
+                }
             }
 
         };
@@ -221,8 +286,7 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
     private E getPoolEntryBlocking(
             final T route, final Object state,
             final long timeout, final TimeUnit tunit,
-            final PoolEntryFuture<E> future)
-                throws IOException, InterruptedException, TimeoutException {
+            final Future<E> future) throws IOException, InterruptedException, TimeoutException {
 
         Date deadline = null;
         if (timeout > 0) {
@@ -302,9 +366,20 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
 
                 boolean success = false;
                 try {
+                    if (future.isCancelled()) {
+                        throw new InterruptedException("Operation interrupted");
+                    }
                     pool.queue(future);
                     this.pending.add(future);
-                    success = future.await(deadline);
+                    if (deadline != null) {
+                        success = this.condition.awaitUntil(deadline);
+                    } else {
+                        this.condition.await();
+                        success = true;
+                    }
+                    if (future.isCancelled()) {
+                        throw new InterruptedException("Operation interrupted");
+                    }
                 } finally {
                     // In case of 'success', we were woken up by the
                     // connection pool and should now have a connection
@@ -338,14 +413,14 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
                     entry.close();
                 }
                 onRelease(entry);
-                PoolEntryFuture<E> future = pool.nextPending();
+                Future<E> future = pool.nextPending();
                 if (future != null) {
                     this.pending.remove(future);
                 } else {
                     future = this.pending.poll();
                 }
                 if (future != null) {
-                    future.wakeup();
+                    this.condition.signalAll();
                 }
             }
         } finally {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/536cbad2/httpcore/src/main/java/org/apache/http/pool/PoolEntryFuture.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/pool/PoolEntryFuture.java b/httpcore/src/main/java/org/apache/http/pool/PoolEntryFuture.java
deleted file mode 100644
index 496ad1f..0000000
--- a/httpcore/src/main/java/org/apache/http/pool/PoolEntryFuture.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * ====================================================================
- * 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.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.http.pool;
-
-import java.io.IOException;
-import java.util.Date;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-
-import org.apache.http.annotation.ThreadingBehavior;
-import org.apache.http.annotation.Contract;
-import org.apache.http.concurrent.FutureCallback;
-import org.apache.http.util.Args;
-
-@Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
-abstract class PoolEntryFuture<T> implements Future<T> {
-
-    private final Lock lock;
-    private final FutureCallback<T> callback;
-    private final Condition condition;
-    private volatile boolean cancelled;
-    private volatile boolean completed;
-    private T result;
-
-    PoolEntryFuture(final Lock lock, final FutureCallback<T> callback) {
-        super();
-        this.lock = lock;
-        this.condition = lock.newCondition();
-        this.callback = callback;
-    }
-
-    @Override
-    public boolean cancel(final boolean mayInterruptIfRunning) {
-        this.lock.lock();
-        try {
-            if (this.completed) {
-                return false;
-            }
-            this.completed = true;
-            this.cancelled = true;
-            if (this.callback != null) {
-                this.callback.cancelled();
-            }
-            this.condition.signalAll();
-            return true;
-        } finally {
-            this.lock.unlock();
-        }
-    }
-
-    @Override
-    public boolean isCancelled() {
-        return this.cancelled;
-    }
-
-    @Override
-    public boolean isDone() {
-        return this.completed;
-    }
-
-    @Override
-    public T get() throws InterruptedException, ExecutionException {
-        try {
-            return get(0, TimeUnit.MILLISECONDS);
-        } catch (final TimeoutException ex) {
-            throw new ExecutionException(ex);
-        }
-    }
-
-    @Override
-    public T get(
-            final long timeout,
-            final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
-        Args.notNull(unit, "Time unit");
-        this.lock.lock();
-        try {
-            if (this.completed) {
-                return this.result;
-            }
-            this.result = getPoolEntry(timeout, unit);
-            this.completed = true;
-            if (this.callback != null) {
-                this.callback.completed(this.result);
-            }
-            return result;
-        } catch (final IOException ex) {
-            this.completed = true;
-            this.result = null;
-            if (this.callback != null) {
-                this.callback.failed(ex);
-            }
-            throw new ExecutionException(ex);
-        } finally {
-            this.lock.unlock();
-        }
-    }
-
-    protected abstract T getPoolEntry(
-            long timeout, TimeUnit unit) throws IOException, InterruptedException, TimeoutException;
-
-    public boolean await(final Date deadline) throws InterruptedException {
-        this.lock.lock();
-        try {
-            if (this.cancelled) {
-                throw new InterruptedException("Operation interrupted");
-            }
-            final boolean success;
-            if (deadline != null) {
-                success = this.condition.awaitUntil(deadline);
-            } else {
-                this.condition.await();
-                success = true;
-            }
-            if (this.cancelled) {
-                throw new InterruptedException("Operation interrupted");
-            }
-            return success;
-        } finally {
-            this.lock.unlock();
-        }
-
-    }
-
-    public void wakeup() {
-        this.lock.lock();
-        try {
-            this.condition.signalAll();
-        } finally {
-            this.lock.unlock();
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/536cbad2/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java b/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java
index 09bac44..c337228 100644
--- a/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java
+++ b/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java
@@ -30,6 +30,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Set;
+import java.util.concurrent.Future;
 
 import org.apache.http.util.Args;
 import org.apache.http.util.Asserts;
@@ -39,14 +40,14 @@ abstract class RouteSpecificPool<T, C, E extends PoolEntry<T, C>> {
     private final T route;
     private final Set<E> leased;
     private final LinkedList<E> available;
-    private final LinkedList<PoolEntryFuture<E>> pending;
+    private final LinkedList<Future<E>> pending;
 
     RouteSpecificPool(final T route) {
         super();
         this.route = route;
         this.leased = new HashSet<E>();
         this.available = new LinkedList<E>();
-        this.pending = new LinkedList<PoolEntryFuture<E>>();
+        this.pending = new LinkedList<Future<E>>();
     }
 
     protected abstract E createEntry(C conn);
@@ -130,18 +131,18 @@ abstract class RouteSpecificPool<T, C, E extends PoolEntry<T, C>> {
         return entry;
     }
 
-    public void queue(final PoolEntryFuture<E> future) {
+    public void queue(final Future<E> future) {
         if (future == null) {
             return;
         }
         this.pending.add(future);
     }
 
-    public PoolEntryFuture<E> nextPending() {
+    public Future<E> nextPending() {
         return this.pending.poll();
     }
 
-    public void unqueue(final PoolEntryFuture<E> future) {
+    public void unqueue(final Future<E> future) {
         if (future == null) {
             return;
         }
@@ -150,7 +151,7 @@ abstract class RouteSpecificPool<T, C, E extends PoolEntry<T, C>> {
     }
 
     public void shutdown() {
-        for (final PoolEntryFuture<E> future: this.pending) {
+        for (final Future<E> future: this.pending) {
             future.cancel(true);
         }
         this.pending.clear();

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/536cbad2/httpcore/src/test/java/org/apache/http/pool/TestRouteSpecificPool.java
----------------------------------------------------------------------
diff --git a/httpcore/src/test/java/org/apache/http/pool/TestRouteSpecificPool.java b/httpcore/src/test/java/org/apache/http/pool/TestRouteSpecificPool.java
index 7142fa1..3e48c5e 100644
--- a/httpcore/src/test/java/org/apache/http/pool/TestRouteSpecificPool.java
+++ b/httpcore/src/test/java/org/apache/http/pool/TestRouteSpecificPool.java
@@ -27,6 +27,7 @@
 package org.apache.http.pool;
 
 import java.io.IOException;
+import java.util.concurrent.Future;
 
 import org.apache.http.HttpConnection;
 import org.junit.Assert;
@@ -278,9 +279,9 @@ public class TestRouteSpecificPool {
     public void testWaitingThreadQueuing() throws Exception {
         final LocalRoutePool pool = new LocalRoutePool();
         @SuppressWarnings("unchecked")
-        final PoolEntryFuture<LocalPoolEntry> future1 = Mockito.mock(PoolEntryFuture.class);
+        final Future<LocalPoolEntry> future1 = Mockito.mock(Future.class);
         @SuppressWarnings("unchecked")
-        final PoolEntryFuture<LocalPoolEntry> future2 = Mockito.mock(PoolEntryFuture.class);
+        final Future<LocalPoolEntry> future2 = Mockito.mock(Future.class);
 
         Assert.assertEquals(0, pool.getPendingCount());
         pool.queue(future1);
@@ -308,7 +309,7 @@ public class TestRouteSpecificPool {
         final LocalPoolEntry entry2 = pool.add(conn2);
 
         @SuppressWarnings("unchecked")
-        final PoolEntryFuture<LocalPoolEntry> future1 = Mockito.mock(PoolEntryFuture.class);
+        final Future<LocalPoolEntry> future1 = Mockito.mock(Future.class);
         pool.queue(future1);
 
         Assert.assertNotNull(entry1);


[12/13] httpcomponents-core git commit: Log that we are serving with SSL.

Posted by ol...@apache.org.
Log that we are serving with SSL.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1794654 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/136bf3ae
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/136bf3ae
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/136bf3ae

Branch: refs/heads/4.4.x
Commit: 136bf3ae6b6df9dcd0fb83d32c3167f884a3a900
Parents: 5bb120e
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue May 9 22:35:42 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue May 9 22:35:42 2017 +0000

----------------------------------------------------------------------
 .../examples/org/apache/http/examples/nio/NHttpFileServer.java    | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/136bf3ae/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
index 6e1c8be..cbbe8a3 100644
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
@@ -104,7 +104,8 @@ public class NHttpFileServer {
                 .create();
 
         server.start();
-        System.out.println("Serving " + docRoot + " on " + server.getEndpoint().getAddress());
+        System.out.println("Serving " + docRoot + " on " + server.getEndpoint().getAddress()
+                + (sslContext == null ? "" : " with " + sslContext.getProvider() + " " + sslContext.getProtocol()));
         server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
 
         Runtime.getRuntime().addShutdownHook(new Thread() {


[04/13] httpcomponents-core git commit: HTTPASYNC-116: Remove cancelled lease requests from the request queue when validating pending requests

Posted by ol...@apache.org.
HTTPASYNC-116: Remove cancelled lease requests from the request queue when validating pending requests

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1780653 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/55d881e0
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/55d881e0
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/55d881e0

Branch: refs/heads/HTTPCORE-446
Commit: 55d881e0257be8c2a57c992a4fd2bdd158e86d7b
Parents: 7dc16b8
Author: olegk <ol...@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Sat Jan 28 10:34:41 2017 +0000
Committer: olegk <ol...@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Sat Jan 28 10:34:41 2017 +0000

----------------------------------------------------------------------
 .../apache/http/nio/pool/AbstractNIOConnPool.java    | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/55d881e0/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java b/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
index b4ee96d..603b71d 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
@@ -484,11 +484,18 @@ public abstract class AbstractNIOConnPool<T, C, E extends PoolEntry<T, C>>
             final ListIterator<LeaseRequest<T, C, E>> it = this.leasingRequests.listIterator();
             while (it.hasNext()) {
                 final LeaseRequest<T, C, E> request = it.next();
-                final long deadline = request.getDeadline();
-                if (now > deadline) {
+                final BasicFuture<E> future = request.getFuture();
+                if (future.isCancelled() && !request.isDone()) {
                     it.remove();
-                    request.failed(new TimeoutException());
-                    this.completedRequests.add(request);
+                } else {
+                    final long deadline = request.getDeadline();
+                    if (now > deadline) {
+                        request.failed(new TimeoutException());
+                    }
+                    if (request.isDone()) {
+                        it.remove();
+                        this.completedRequests.add(request);
+                    }
                 }
             }
         } finally {


[13/13] httpcomponents-core git commit: HTTPCORE-465: Update example NHttpReverseProxy to support SSL to origin servers which use self-signed certificates.

Posted by ol...@apache.org.
HTTPCORE-465: Update example NHttpReverseProxy to support SSL to origin servers which use self-signed certificates.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1794666 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/44344d4c
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/44344d4c
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/44344d4c

Branch: refs/heads/4.4.x
Commit: 44344d4cf9dd41b77998b5e7ceecc84e4b8840a5
Parents: 136bf3a
Author: Gary D. Gregory <gg...@apache.org>
Authored: Wed May 10 00:43:17 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Wed May 10 00:43:17 2017 +0000

----------------------------------------------------------------------
 RELEASE_NOTES.txt                               |  3 ++
 .../http/examples/nio/NHttpReverseProxy.java    | 32 +++++++++----
 .../examples/nio/TrustSelfSignedStrategy.java   | 50 ++++++++++++++++++++
 3 files changed, 77 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/44344d4c/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 21409ad..95d3ac0 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -21,6 +21,9 @@ Changelog
 * HTTPCORE-464: org.apache.http.nio.protocol.HttpAsyncService does not always log exceptions.
   Contributed by Gary Gregory <ggregory at apache.org>
 
+* HTTPCORE-465: Update example NHttpReverseProxy to support SSL to origin servers which use self-signed certificates.
+  Contributed by Gary Gregory <ggregory at apache.org>
+
 
 Release 4.4.6
 -------------------

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/44344d4c/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
index 3bd720b..04c484a 100644
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
@@ -34,6 +34,8 @@ import java.nio.ByteBuffer;
 import java.util.Locale;
 import java.util.concurrent.atomic.AtomicLong;
 
+import javax.net.ssl.SSLContext;
+
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
@@ -50,6 +52,9 @@ import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.EnglishReasonPhraseCatalog;
 import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
 import org.apache.http.impl.nio.DefaultHttpServerIODispatch;
+import org.apache.http.impl.nio.DefaultNHttpClientConnectionFactory;
+import org.apache.http.impl.nio.SSLNHttpClientConnectionFactory;
+import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
 import org.apache.http.impl.nio.pool.BasicNIOConnPool;
 import org.apache.http.impl.nio.pool.BasicNIOPoolEntry;
 import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
@@ -95,21 +100,28 @@ import org.apache.http.protocol.ResponseConnControl;
 import org.apache.http.protocol.ResponseContent;
 import org.apache.http.protocol.ResponseDate;
 import org.apache.http.protocol.ResponseServer;
+import org.apache.http.ssl.SSLContextBuilder;
 
 /**
  * Asynchronous, fully streaming HTTP/1.1 reverse proxy.
+ * <p>
+ * Supports SSL to origin servers which use self-signed certificates.
+ * </p>
  */
 public class NHttpReverseProxy {
 
     public static void main(String[] args) throws Exception {
-        if (args.length < 1) {
-            System.out.println("Usage: NHttpReverseProxy <hostname[:hostport]> [port]");
+        if (args.length < 2) {
+            System.out.println("Usage: NHttpReverseProxy <HostNameURI> <Port> [\"TrustSelfSignedStrategy\"]");
             System.exit(1);
         }
+        // Extract command line arguments
         URI uri = new URI(args[0]);
-        int port = 8080;
-        if (args.length > 1) {
-            port = Integer.parseInt(args[1]);
+        int port = Integer.parseInt(args[1]);
+        SSLContext sslContext = null;
+        if (args.length > 2 && args[2].equals("TrustSelfSignedStrategy")) {
+            System.out.println("Using TrustSelfSignedStrategy (not for production.)");
+            sslContext = SSLContextBuilder.create().loadTrustMaterial(TrustSelfSignedStrategy.INSTANCE).build();
         }
 
         // Target host
@@ -151,7 +163,11 @@ public class NHttpReverseProxy {
         HttpAsyncRequester executor = new HttpAsyncRequester(
                 outhttpproc, new ProxyOutgoingConnectionReuseStrategy());
 
-        ProxyConnPool connPool = new ProxyConnPool(connectingIOReactor, ConnectionConfig.DEFAULT);
+        // Without SSL: ProxyConnPool connPool = new ProxyConnPool(connectingIOReactor, ConnectionConfig.DEFAULT);
+        ProxyConnPool connPool = new ProxyConnPool(connectingIOReactor,
+                new BasicNIOConnFactory(new DefaultNHttpClientConnectionFactory(ConnectionConfig.DEFAULT),
+                        new SSLNHttpClientConnectionFactory(sslContext, null, ConnectionConfig.DEFAULT)),
+                0);
         connPool.setMaxTotal(100);
         connPool.setDefaultMaxPerRoute(20);
 
@@ -163,8 +179,8 @@ public class NHttpReverseProxy {
                 new ProxyIncomingConnectionReuseStrategy(),
                 handlerRegistry);
 
-        final IOEventDispatch connectingEventDispatch = new DefaultHttpClientIODispatch(
-                clientHandler, ConnectionConfig.DEFAULT);
+        final IOEventDispatch connectingEventDispatch = DefaultHttpClientIODispatch.create(
+                clientHandler, sslContext, ConnectionConfig.DEFAULT);
 
         final IOEventDispatch listeningEventDispatch = new DefaultHttpServerIODispatch(
                 serviceHandler, ConnectionConfig.DEFAULT);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/44344d4c/httpcore-nio/src/examples/org/apache/http/examples/nio/TrustSelfSignedStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/TrustSelfSignedStrategy.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/TrustSelfSignedStrategy.java
new file mode 100644
index 0000000..5969b1c
--- /dev/null
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/TrustSelfSignedStrategy.java
@@ -0,0 +1,50 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.examples.nio;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import org.apache.http.ssl.TrustStrategy;
+
+/**
+ * A trust strategy that accepts self-signed certificates as trusted. Verification of all other
+ * certificates is done by the trust manager configured in the SSL context.
+ * 
+ * Copied from HttClient.
+ */
+class TrustSelfSignedStrategy implements TrustStrategy {
+
+    public static final TrustSelfSignedStrategy INSTANCE = new TrustSelfSignedStrategy();
+
+    @Override
+    public boolean isTrusted(
+            final X509Certificate[] chain, final String authType) throws CertificateException {
+        return chain.length == 1;
+    }
+
+}


[03/13] httpcomponents-core git commit: HTTPCLIENT-1808: Fixing potential overflow for connection TTL Contributed by Andrew Shore

Posted by ol...@apache.org.
HTTPCLIENT-1808: Fixing potential overflow for connection TTL
Contributed by Andrew Shore <shorea at amazon.com>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1780648 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/7dc16b8c
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/7dc16b8c
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/7dc16b8c

Branch: refs/heads/HTTPCORE-446
Commit: 7dc16b8c570692f00e7bd075c0905052c985f114
Parents: 10331fe
Author: olegk <ol...@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Sat Jan 28 09:50:13 2017 +0000
Committer: olegk <ol...@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Sat Jan 28 09:50:13 2017 +0000

----------------------------------------------------------------------
 httpcore/src/main/java/org/apache/http/pool/PoolEntry.java   | 8 +++++---
 .../src/test/java/org/apache/http/pool/TestPoolEntry.java    | 6 ++++++
 2 files changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/7dc16b8c/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java b/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
index 31b8ee2..dad5139 100644
--- a/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
+++ b/httpcore/src/main/java/org/apache/http/pool/PoolEntry.java
@@ -26,12 +26,12 @@
  */
 package org.apache.http.pool;
 
-import java.util.concurrent.TimeUnit;
-
 import org.apache.http.annotation.Contract;
 import org.apache.http.annotation.ThreadingBehavior;
 import org.apache.http.util.Args;
 
+import java.util.concurrent.TimeUnit;
+
 /**
  * Pool entry containing a pool connection object along with its route.
  * <p>
@@ -85,7 +85,9 @@ public abstract class PoolEntry<T, C> {
         this.created = System.currentTimeMillis();
         this.updated = this.created;
         if (timeToLive > 0) {
-            this.validityDeadline = this.created + tunit.toMillis(timeToLive);
+            final long deadline = this.created + tunit.toMillis(timeToLive);
+            // If the above overflows then default to Long.MAX_VALUE
+            this.validityDeadline = deadline > 0 ? deadline : Long.MAX_VALUE;
         } else {
             this.validityDeadline = Long.MAX_VALUE;
         }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/7dc16b8c/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
----------------------------------------------------------------------
diff --git a/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java b/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
index 927f160..6bad38e 100644
--- a/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
+++ b/httpcore/src/test/java/org/apache/http/pool/TestPoolEntry.java
@@ -122,4 +122,10 @@ public class TestPoolEntry {
         entry1.updateExpiry(50L, null);
     }
 
+    @Test
+    public void testExpiryDoesNotOverflow() {
+        final MockPoolEntry entry = new MockPoolEntry("route1", Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+        Assert.assertEquals(entry.getValidityDeadline(), Long.MAX_VALUE);
+    }
+
 }


[10/13] httpcomponents-core git commit: Log that we loading the keystore and what we are serving where.

Posted by ol...@apache.org.
Log that we loading the keystore and what we are serving where.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1794647 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/04c33408
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/04c33408
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/04c33408

Branch: refs/heads/4.4.x
Commit: 04c33408888dc9a39631aaa2a9ed5daeb6425ac6
Parents: 7c5027d
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue May 9 22:11:04 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue May 9 22:11:04 2017 +0000

----------------------------------------------------------------------
 .../src/examples/org/apache/http/examples/nio/NHttpFileServer.java | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/04c33408/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
index 56dba42..6e1c8be 100644
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
@@ -83,6 +83,7 @@ public class NHttpFileServer {
                 System.out.println("Keystore not found");
                 System.exit(1);
             }
+            System.out.println("Loading keystore " + url);
             sslContext = SSLContexts.custom()
                     .loadKeyMaterial(url, "nopassword".toCharArray(), "nopassword".toCharArray())
                     .build();
@@ -103,6 +104,7 @@ public class NHttpFileServer {
                 .create();
 
         server.start();
+        System.out.println("Serving " + docRoot + " on " + server.getEndpoint().getAddress());
         server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
 
         Runtime.getRuntime().addShutdownHook(new Thread() {


[09/13] httpcomponents-core git commit: Add toString() for debugging and logging.

Posted by ol...@apache.org.
Add toString() for debugging and logging.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1794646 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/3a677d47
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/3a677d47
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/3a677d47

Branch: refs/heads/trunk
Commit: 3a677d47cb872b6ede20b28e93d3206f08b349ac
Parents: 9c362d4
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue May 9 22:09:03 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue May 9 22:09:03 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/reactor/ListenerEndpointImpl.java | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/3a677d47/httpcore5/src/main/java/org/apache/hc/core5/reactor/ListenerEndpointImpl.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ListenerEndpointImpl.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ListenerEndpointImpl.java
index 45b54e6..ace97ba 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ListenerEndpointImpl.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ListenerEndpointImpl.java
@@ -76,6 +76,12 @@ public class ListenerEndpointImpl implements ListenerEndpoint {
     }
 
     @Override
+    public String toString() {
+        return "[address=" + address + ", key=" + key + ", closed=" + closed + ", completed="
+                + completed + ", exception=" + exception + ", callback=" + callback + "]";
+    }
+
+    @Override
     public void waitFor() throws InterruptedException {
         if (this.completed) {
             return;


[05/13] httpcomponents-core git commit: HTTPCORE-446: fixed deadlock in AbstractConnPool shutdown code

Posted by ol...@apache.org.
HTTPCORE-446: fixed deadlock in AbstractConnPool shutdown code


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/67bcb420
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/67bcb420
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/67bcb420

Branch: refs/heads/HTTPCORE-446
Commit: 67bcb4201e4cb2584d298c3c0a0e800c0825f7f3
Parents: 55d881e
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Feb 15 15:10:22 2017 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Feb 15 15:10:22 2017 +0100

----------------------------------------------------------------------
 .../org/apache/http/pool/AbstractConnPool.java  | 47 +++++++++++---------
 1 file changed, 25 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/67bcb420/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java b/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
index d34cf24..25a6bfc 100644
--- a/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
+++ b/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
@@ -38,6 +38,8 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
@@ -190,37 +192,37 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
 
         return new Future<E>() {
 
-            private volatile boolean cancelled;
-            private volatile boolean done;
-            private volatile E entry;
+            private final AtomicBoolean cancelled = new AtomicBoolean(false);
+            private final AtomicBoolean done = new AtomicBoolean(false);
+            private final AtomicReference<E> entryRef = new AtomicReference<E>(null);
 
             @Override
             public boolean cancel(final boolean mayInterruptIfRunning) {
-                cancelled = true;
-                lock.lock();
-                try {
-                    condition.signalAll();
-                } finally {
-                    lock.unlock();
-                }
-                synchronized (this) {
-                    final boolean result = !done;
-                    done = true;
+                if (cancelled.compareAndSet(false, true)) {
+                    done.set(true);
+                    lock.lock();
+                    try {
+                        condition.signalAll();
+                    } finally {
+                        lock.unlock();
+                    }
                     if (callback != null) {
                         callback.cancelled();
                     }
-                    return result;
+                    return true;
+                } else {
+                    return false;
                 }
             }
 
             @Override
             public boolean isCancelled() {
-                return cancelled;
+                return cancelled.get();
             }
 
             @Override
             public boolean isDone() {
-                return done;
+                return done.get();
             }
 
             @Override
@@ -234,6 +236,7 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
 
             @Override
             public E get(final long timeout, final TimeUnit tunit) throws InterruptedException, ExecutionException, TimeoutException {
+                final E entry = entryRef.get();
                 if (entry != null) {
                     return entry;
                 }
@@ -250,16 +253,16 @@ public abstract class AbstractConnPool<T, C, E extends PoolEntry<T, C>>
                                     }
                                 }
                             }
-                            entry = leasedEntry;
-                            done = true;
-                            onLease(entry);
+                            entryRef.set(leasedEntry);
+                            done.set(true);
+                            onLease(leasedEntry);
                             if (callback != null) {
-                                callback.completed(entry);
+                                callback.completed(leasedEntry);
                             }
-                            return entry;
+                            return leasedEntry;
                         }
                     } catch (IOException ex) {
-                        done = true;
+                        done.set(true);
                         if (callback != null) {
                             callback.failed(ex);
                         }


[08/13] httpcomponents-core git commit: Add toString() for debugging and logging.

Posted by ol...@apache.org.
Add toString() for debugging and logging.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1794645 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/7c5027d3
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/7c5027d3
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/7c5027d3

Branch: refs/heads/4.4.x
Commit: 7c5027d3cacd2c234a84177f872e539d3591d4a1
Parents: e21e8d4
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue May 9 22:05:41 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue May 9 22:05:41 2017 +0000

----------------------------------------------------------------------
 .../org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/7c5027d3/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java
index 80a9267..34711a0 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java
@@ -156,4 +156,10 @@ public class ListenerEndpointImpl implements ListenerEndpoint {
         }
     }
 
+    @Override
+    public String toString() {
+        return "[address=" + address + ", key=" + key + ", closed=" + closed + ", completed="
+                + completed + ", exception=" + exception + ", callback=" + callback + "]";
+    }
+
 }


[07/13] httpcomponents-core git commit: Better usage help.

Posted by ol...@apache.org.
Better usage help.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1794639 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/e21e8d45
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/e21e8d45
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/e21e8d45

Branch: refs/heads/4.4.x
Commit: e21e8d45d937225201aeb31c338c40624efc9951
Parents: 8b6a310
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue May 9 21:45:10 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue May 9 21:45:10 2017 +0000

----------------------------------------------------------------------
 .../examples/org/apache/http/examples/nio/NHttpReverseProxy.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e21e8d45/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
index 6d9f292..3bd720b 100644
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
@@ -103,7 +103,7 @@ public class NHttpReverseProxy {
 
     public static void main(String[] args) throws Exception {
         if (args.length < 1) {
-            System.out.println("Usage: NHttpReverseProxy <hostname> [port]");
+            System.out.println("Usage: NHttpReverseProxy <hostname[:hostport]> [port]");
             System.exit(1);
         }
         URI uri = new URI(args[0]);


[11/13] httpcomponents-core git commit: Add toString() for debugging and logging.

Posted by ol...@apache.org.
Add toString() for debugging and logging.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1794648 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/5bb120e8
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/5bb120e8
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/5bb120e8

Branch: refs/heads/4.4.x
Commit: 5bb120e8b76591f9bf49a5853f9b35bfd748a683
Parents: 04c3340
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue May 9 22:15:19 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue May 9 22:15:19 2017 +0000

----------------------------------------------------------------------
 .../src/main/java/org/apache/http/params/BasicHttpParams.java   | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/5bb120e8/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java b/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java
index 115171e..18655ad 100644
--- a/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java
+++ b/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java
@@ -192,4 +192,9 @@ public class BasicHttpParams extends AbstractHttpParams implements Serializable,
     public Set<String> getNames() {
         return new HashSet<String>(this.parameters.keySet());
     }
+
+    @Override
+    public String toString() {
+        return "[parameters=" + parameters + "]";
+    }
 }