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 e896360 Context API refactoring.
e896360 is described below
commit e89636083066b1e801298faf07ddf2a0244cff15
Author: JamesBognar <[email protected]>
AuthorDate: Fri Sep 24 15:33:09 2021 -0400
Context API refactoring.
---
.../org/apache/juneau/rest/client/RestClient.java | 93 +---------------------
.../juneau/rest/client/RestClientBuilder.java | 12 +--
2 files changed, 6 insertions(+), 99 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 068941f..77d2938 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
@@ -1022,94 +1022,6 @@ public class RestClient extends BeanContextable
implements HttpClient, Closeable
private static final String PREFIX = "RestClient.";
/**
- * Configuration property: Executor service.
- *
- * <h5 class='section'>Property:</h5>
- * <ul class='spaced-list'>
- * <li><b>ID:</b> {@link
org.apache.juneau.rest.client.RestClient#RESTCLIENT_executorService
RESTCLIENT_executorService}
- * <li><b>Name:</b> <js>"RestClient.executorService.o"</js>
- * <li><b>Data type:</b>
- * <ul>
- * <li><c>Class<? <jk>extends</jk> {@link
java.util.concurrent.ExecutorService}></c>
- * <li>{@link java.util.concurrent.ExecutorService}
- * </ul>
- * <li><b>Default:</b> <jk>null</jk>.
- * <li><b>Methods:</b>
- * <ul>
- * <li class='jm'>{@link
org.apache.juneau.rest.client.RestClientBuilder#executorService(ExecutorService,
boolean)}
- * </ul>
- * </ul>
- *
- * <h5 class='section'>Description:</h5>
- * <p>
- * Defines the executor service to use when calling future methods on
the {@link RestRequest} class.
- *
- * <p>
- * This executor service is used to create {@link Future} objects on
the following methods:
- * <ul>
- * <li class='jm'>{@link RestRequest#runFuture()}
- * <li class='jm'>{@link RestRequest#completeFuture()}
- * <li class='jm'>{@link ResponseBody#asFuture(Class)} (and
similar methods)
- * </ul>
- *
- * <p>
- * The default executor service is a single-threaded {@link
ThreadPoolExecutor} with a 30 second timeout
- * and a queue size of 10.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Create a client with a customized executor service.</jc>
- * RestClient <jv>client</jv> = RestClient
- * .<jsm>create</jsm>()
- * .executorService(<jk>new</jk> ThreadPoolExecutor(1, 1,
30, TimeUnit.<jsf>SECONDS</jsf>, <jk>new</jk>
ArrayBlockingQueue<Runnable>(10)), <jk>true</jk>)
- * .build();
- *
- * <jc>// Use it to asynchronously run a request.</jc>
- * Future<RestResponse> <jv>responseFuture</jv> =
<jv>client</jv>.get(<jsf>URI</jsf>).runFuture();
- *
- * <jc>// Do some other stuff.</jc>
- *
- * <jc>// Now read the response.</jc>
- * String <jv>body</jv> =
<jv>responseFuture</jv>.get().getBody().asString();
- *
- * <jc>// Use it to asynchronously retrieve a response.</jc>
- * Future<MyBean> <jv>myBeanFuture</jv> = <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
- * .getBody().asFuture(MyBean.<jk>class</jk>);
- *
- * <jc>// Do some other stuff.</jc>
- *
- * <jc>// Now read the response.</jc>
- * MyBean <jv>bean</jv> = <jv>myBeanFuture</jv>.get();
- * </p>
- */
- public static final String RESTCLIENT_executorService = PREFIX +
"executorService.o";
-
- /**
- * Configuration property: Shut down executor service on close.
- *
- * <h5 class='section'>Property:</h5>
- * <ul class='spaced-list'>
- * <li><b>ID:</b> {@link
org.apache.juneau.rest.client.RestClient#RESTCLIENT_executorServiceShutdownOnClose
RESTCLIENT_executorServiceShutdownOnClose}
- * <li><b>Name:</b>
<js>"RestClient.executorServiceShutdownOnClose.b"</js>
- * <li><b>Data type:</b> <jk>boolean</jk>
- * <li><b>System property:</b>
<c>RestClient.executorServiceShutdownOnClose</c>
- * <li><b>Environment variable:</b>
<c>RESTCLIENT_EXECUTORSERVICESHUTDOWNONCLOSE</c>
- * <li><b>Default:</b> <jk>false</jk>
- * <li><b>Methods:</b>
- * <ul>
- * <li class='jm'>{@link
org.apache.juneau.rest.client.RestClientBuilder#executorService(ExecutorService,
boolean)}
- * </ul>
- * </ul>
- *
- * <h5 class='section'>Description:</h5>
- * <p>
- * Call {@link ExecutorService#shutdown()} when {@link
RestClient#close()} is called.
- */
- public static final String RESTCLIENT_executorServiceShutdownOnClose =
PREFIX + "executorServiceShutdownOnClose.b";
-
- /**
* Configuration property: Ignore errors.
*
* <h5 class='section'>Property:</h5>
@@ -1560,13 +1472,14 @@ public class RestClient extends BeanContextable
implements HttpClient, Closeable
errorCodes = builder.errorCodes;
connectionManager = builder.connectionManager;
console = ofNullable(builder.console).orElse(System.err);
+ executorService = builder.executorService;
+ executorServiceShutdownOnClose =
builder.executorServiceShutdownOnClose;
ContextProperties cp =
getContextProperties().copy().apply(getBeanContext().getContextProperties()).build();
beanStore.addBean(ContextProperties.class, cp);
this.keepHttpClientOpen =
cp.getBoolean(RESTCLIENT_keepHttpClientOpen).orElse(false);
- this.executorServiceShutdownOnClose =
cp.getBoolean(RESTCLIENT_executorServiceShutdownOnClose).orElse(false);
this.leakDetection =
cp.getBoolean(RESTCLIENT_leakDetection).orElse(isDebug());
this.ignoreErrors =
cp.getBoolean(RESTCLIENT_ignoreErrors).orElse(false);
this.logger = cp.getInstance(RESTCLIENT_logger,
Logger.class).orElseGet(()->Logger.getLogger(RestClient.class.getName()));
@@ -1584,8 +1497,6 @@ public class RestClient extends BeanContextable
implements HttpClient, Closeable
this.partParser = builder.simplePartParser != null ?
builder.simplePartParser : (HttpPartParser) builder.partParserBuilder.build();
- this.executorService =
cp.getInstance(RESTCLIENT_executorService, ExecutorService.class).orElse(null);
-
this.interceptors =
cp.getInstanceArray(RESTCLIENT_interceptors,
RestCallInterceptor.class).orElse(new RestCallInterceptor[0]);
creationStack = isDebug() ?
Thread.currentThread().getStackTrace() : null;
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 fb02940..3224bf7 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
@@ -102,10 +102,11 @@ public class RestClientBuilder extends
BeanContextableBuilder {
private boolean pooled;
String rootUri;
- boolean skipEmptyHeaderData, skipEmptyFormData, skipEmptyQueryData;
+ boolean skipEmptyHeaderData, skipEmptyFormData, skipEmptyQueryData,
executorServiceShutdownOnClose;
Predicate<Integer> errorCodes = x -> x<=0 || x>=400;
HttpClientConnectionManager connectionManager;
PrintStream console;
+ ExecutorService executorService;
SerializerGroup.Builder serializerGroupBuilder;
ParserGroup.Builder parserGroupBuilder;
@@ -2334,19 +2335,14 @@ public class RestClientBuilder extends
BeanContextableBuilder {
* MyBean <jv>bean</jv> = <jv>myBeanFuture</jv>.get();
* </p>
*
- * <ul class='seealso'>
- * <li class='jf'>{@link RestClient#RESTCLIENT_executorService}
- * <li class='jf'>{@link
RestClient#RESTCLIENT_executorServiceShutdownOnClose}
- * </ul>
- *
* @param executorService The executor service.
* @param shutdownOnClose Call {@link ExecutorService#shutdown()} when
{@link RestClient#close()} is called.
* @return This object (for method chaining).
*/
@FluentSetter
public RestClientBuilder executorService(ExecutorService
executorService, boolean shutdownOnClose) {
- set(RESTCLIENT_executorService, executorService);
- set(RESTCLIENT_executorServiceShutdownOnClose, shutdownOnClose);
+ this.executorService = executorService;
+ this.executorServiceShutdownOnClose = shutdownOnClose;
return this;
}