This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 7802869  Context API refactoring.
7802869 is described below

commit 78028696e193cdbdc44adfc0b4d7416fdaa11a71
Author: JamesBognar <[email protected]>
AuthorDate: Fri Sep 24 12:59:45 2021 -0400

    Context API refactoring.
---
 .../org/apache/juneau/rest/client/RestClient.java  | 27 +-------
 .../juneau/rest/client/RestClientBuilder.java      | 77 ++++++++++------------
 2 files changed, 36 insertions(+), 68 deletions(-)

diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
index bff27d3..8d42a05 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
@@ -1021,31 +1021,6 @@ public class RestClient extends BeanContextable 
implements HttpClient, Closeable
        private static final String PREFIX = "RestClient.";
 
        /**
-        * Configuration property:  Connection manager
-        *
-        * <h5 class='section'>Property:</h5>
-        * <ul class='spaced-list'>
-        *      <li><b>ID:</b>  {@link 
org.apache.juneau.rest.client.RestClient#RESTCLIENT_connectionManager 
RESTCLIENT_connectionManager}
-        *      <li><b>Name:</b>  <js>"RestClient.connectionManager.o"</js>
-        *      <li><b>System property:</b>  <c>RestClient.connectionManager</c>
-        *      <li><b>Data type:</b>
-        *      <ul>
-        *              <li><b>Data type:</b>  {@link 
org.apache.http.conn.HttpClientConnectionManager}</c>
-        *      </ul>
-        *      <li><b>Default:</b>  Value returned by {@link 
org.apache.juneau.rest.client.RestClientBuilder#createConnectionManager()}
-        *      <li><b>Methods:</b>
-        *              <ul>
-        *                      <li class='jm'>{@link 
org.apache.juneau.rest.client.RestClientBuilder#connectionManager(HttpClientConnectionManager)}
-        *              </ul>
-        * </ul>
-        *
-        * <h5 class='section'>Description:</h5>
-        * <p>
-        * Allows you to override the connection manager used by the HTTP 
client.
-        */
-       public static final String RESTCLIENT_connectionManager = PREFIX + 
"connectionManager.o";
-
-       /**
         * Configuration property:  Console print stream.
         *
         * <h5 class='section'>Property:</h5>
@@ -1608,12 +1583,12 @@ public class RestClient extends BeanContextable 
implements HttpClient, Closeable
                skipEmptyFormData = builder.skipEmptyFormData;
                rootUri = builder.rootUri;
                errorCodes = builder.errorCodes;
+               connectionManager = builder.connectionManager;
 
                ContextProperties cp = 
getContextProperties().copy().apply(getBeanContext().getContextProperties()).build();
 
                beanStore.addBean(ContextProperties.class, cp);
 
-               this.connectionManager = 
cp.getInstance(RESTCLIENT_connectionManager, 
HttpClientConnectionManager.class).orElse(null);
                this.keepHttpClientOpen = 
cp.getBoolean(RESTCLIENT_keepHttpClientOpen).orElse(false);
                this.executorServiceShutdownOnClose = 
cp.getBoolean(RESTCLIENT_executorServiceShutdownOnClose).orElse(false);
                this.leakDetection = 
cp.getBoolean(RESTCLIENT_leakDetection).orElse(isDebug());
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java
index c272a7b..19e385d 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java
@@ -14,7 +14,6 @@ package org.apache.juneau.rest.client;
 
 import static org.apache.juneau.rest.client.RestClient.*;
 import static org.apache.juneau.assertions.Assertions.*;
-import static org.apache.juneau.internal.ClassUtils.*;
 import static org.apache.juneau.internal.ExceptionUtils.*;
 import static org.apache.juneau.internal.StringUtils.*;
 
@@ -100,12 +99,12 @@ public class RestClientBuilder extends 
BeanContextableBuilder {
        private HeaderList.Builder headerData;
        private PartList.Builder queryData, formData, pathData;
        private BeanCreator<RestCallHandler> callHandler;
-//     private RestCallHandler.Builder restCallHandler;
        private boolean pooled;
 
        String rootUri;
        boolean skipEmptyHeaderData, skipEmptyFormData, skipEmptyQueryData;
        Predicate<Integer> errorCodes = x ->  x<=0 || x>=400;
+       HttpClientConnectionManager connectionManager;
 
        SerializerGroup.Builder serializerGroupBuilder;
        ParserGroup.Builder parserGroupBuilder;
@@ -845,14 +844,9 @@ public class RestClientBuilder extends 
BeanContextableBuilder {
         * @return The HTTP client to use.
         */
        protected CloseableHttpClient createHttpClient() {
-               Object cm = peek(RESTCLIENT_connectionManager);
-               // Don't call createConnectionManager() if 
RestClient.setConnectionManager() was called.
-               if (cm == null)
-                       
httpClientBuilder().setConnectionManager(createConnectionManager());
-               else if (cm instanceof HttpClientConnectionManager)
-                       
httpClientBuilder().setConnectionManager((HttpClientConnectionManager)cm);
-               else
-                       throw runtimeException("Invalid type for 
RESTCLIENT_connectionManager: {0}", className(cm));
+               if (connectionManager == null)
+                       connectionManager = createConnectionManager();
+               httpClientBuilder().setConnectionManager(connectionManager);
                return httpClientBuilder().build();
        }
 
@@ -2189,7 +2183,6 @@ public class RestClientBuilder extends 
BeanContextableBuilder {
         *
         * @return The HTTP client builder to use to create the HTTP client.
         */
-       @SuppressWarnings("resource")
        protected HttpClientConnectionManager createConnectionManager() {
                return (pooled ? new PoolingHttpClientConnectionManager() : new 
BasicHttpClientConnectionManager());
        }
@@ -2216,6 +2209,37 @@ public class RestClientBuilder extends 
BeanContextableBuilder {
        }
 
        /**
+        * Assigns {@link HttpClientConnectionManager} instance.
+        *
+        * @param value New property value.
+        * @return This object (for method chaining).
+        * @see 
HttpClientBuilder#setConnectionManager(HttpClientConnectionManager)
+        */
+       @FluentSetter
+       public RestClientBuilder connectionManager(HttpClientConnectionManager 
value) {
+               connectionManager = value;
+               httpClientBuilder().setConnectionManager(value);
+               return this;
+       }
+
+       /**
+        * Defines the connection manager is to be shared by multiple client 
instances.
+        *
+        * <ul class='notes'>
+        *      <li>If the connection manager is shared its life-cycle is 
expected to be managed by the caller and it will not be shut down if the client 
is closed.
+        * </ul>
+        *
+        * @param shared New property value.
+        * @return This object (for method chaining).
+        * @see HttpClientBuilder#setConnectionManagerShared(boolean)
+        */
+       @FluentSetter
+       public RestClientBuilder connectionManagerShared(boolean shared) {
+               httpClientBuilder().setConnectionManagerShared(shared);
+               return this;
+       }
+
+       /**
         * Set up this client to use BASIC auth.
         *
         * <h5 class='section'>Example:</h5>
@@ -5200,37 +5224,6 @@ public class RestClientBuilder extends 
BeanContextableBuilder {
        }
 
        /**
-        * Assigns {@link HttpClientConnectionManager} instance.
-        *
-        * @param connManager New property value.
-        * @return This object (for method chaining).
-        * @see 
HttpClientBuilder#setConnectionManager(HttpClientConnectionManager)
-        */
-       @FluentSetter
-       public RestClientBuilder connectionManager(HttpClientConnectionManager 
connManager) {
-               set(RESTCLIENT_connectionManager, connManager);
-               httpClientBuilder().setConnectionManager(connManager);
-               return this;
-       }
-
-       /**
-        * Defines the connection manager is to be shared by multiple client 
instances.
-        *
-        * <ul class='notes'>
-        *      <li>If the connection manager is shared its life-cycle is 
expected to be managed by the caller and it will not be shut down if the client 
is closed.
-        * </ul>
-        *
-        * @param shared New property value.
-        * @return This object (for method chaining).
-        * @see HttpClientBuilder#setConnectionManagerShared(boolean)
-        */
-       @FluentSetter
-       public RestClientBuilder connectionManagerShared(boolean shared) {
-               httpClientBuilder().setConnectionManagerShared(shared);
-               return this;
-       }
-
-       /**
         * Assigns {@link ConnectionReuseStrategy} instance.
         *
         * @param reuseStrategy New property value.

Reply via email to