This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/juneau.git
commit 970718f42c5674744a08ad9968bbfb3f9c5a0e61 Author: Gary Gregory <[email protected]> AuthorDate: Fri Jun 23 22:52:16 2023 -0400 [juneau-rest-client] Use lambdas --- .../apache/juneau/rest/client/ResponseContent.java | 52 +++++----------------- .../org/apache/juneau/rest/client/RestClient.java | 40 +++++++---------- .../org/apache/juneau/rest/client/RestRequest.java | 20 ++------- .../apache/juneau/rest/client/RestResponse.java | 29 ++++++------ 4 files changed, 46 insertions(+), 95 deletions(-) diff --git a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseContent.java b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseContent.java index 567ac09dc..641e07f96 100644 --- a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseContent.java +++ b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseContent.java @@ -764,16 +764,9 @@ public class ResponseContent implements HttpEntity { * RestClient.Builder#executorService(ExecutorService, boolean) for defining the executor service for creating * {@link Future Futures}. */ - public <T> Future<T> asFuture(final Class<T> type) throws RestCallException { - return client.getExecutorService().submit( - new Callable<T>() { - @Override /* Callable */ - public T call() throws Exception { - return as(type); - } - } - ); - } + public <T> Future<T> asFuture(final Class<T> type) throws RestCallException { + return client.getExecutorService().submit(() -> as(type)); + } /** * Same as {@link #as(ClassMeta)} but allows you to run the call asynchronously. @@ -797,16 +790,9 @@ public class ResponseContent implements HttpEntity { * RestClient.Builder#executorService(ExecutorService, boolean) for defining the executor service for creating * {@link Future Futures}. */ - public <T> Future<T> asFuture(final ClassMeta<T> type) throws RestCallException { - return client.getExecutorService().submit( - new Callable<T>() { - @Override /* Callable */ - public T call() throws Exception { - return as(type); - } - } - ); - } + public <T> Future<T> asFuture(final ClassMeta<T> type) throws RestCallException { + return client.getExecutorService().submit(() -> as(type)); + } /** * Same as {@link #as(Type,Type...)} but allows you to run the call asynchronously. @@ -836,16 +822,9 @@ public class ResponseContent implements HttpEntity { * RestClient.Builder#executorService(ExecutorService, boolean) for defining the executor service for creating * {@link Future Futures}. */ - public <T> Future<T> asFuture(final Type type, final Type...args) throws RestCallException { - return client.getExecutorService().submit( - new Callable<T>() { - @Override /* Callable */ - public T call() throws Exception { - return as(type, args); - } - } - ); - } + public <T> Future<T> asFuture(final Type type, final Type... args) throws RestCallException { + return client.getExecutorService().submit(() -> as(type, args)); + } /** * Returns the contents of this body as a string. @@ -894,16 +873,9 @@ public class ResponseContent implements HttpEntity { * RestClient.Builder#executorService(ExecutorService, boolean) for defining the executor service for creating * {@link Future Futures}. */ - public Future<String> asStringFuture() throws RestCallException { - return client.getExecutorService().submit( - new Callable<String>() { - @Override /* Callable */ - public String call() throws Exception { - return asString(); - } - } - ); - } + public Future<String> asStringFuture() throws RestCallException { + return client.getExecutorService().submit(() -> asString()); + } /** * Same as {@link #asString()} but truncates the string to the specified length. 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 0f3483fad..0c243bf2d 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 @@ -7396,31 +7396,25 @@ public class RestClient extends BeanContextable implements HttpClient, Closeable RemoteOperationReturn ror = rom.getReturns(); if (ror.isFuture()) { - return getExecutorService().submit(new Callable<Object>() { - @Override - public Object call() throws Exception { - try { - return executeRemote(interfaceClass, rc, method, rom); - } catch (Exception e) { - throw e; - } catch (Throwable e) { - throw asRuntimeException(e); - } - } - }); + return getExecutorService().submit(() -> { + try { + return executeRemote(interfaceClass, rc, method, rom); + } catch (Exception e) { + throw e; + } catch (Throwable e) { + throw asRuntimeException(e); + } + }); } else if (ror.isCompletableFuture()) { CompletableFuture<Object> cf = new CompletableFuture<>(); - getExecutorService().submit(new Callable<Object>() { - @Override - public Object call() throws Exception { - try { - cf.complete(executeRemote(interfaceClass, rc, method, rom)); - } catch (Throwable e) { - cf.completeExceptionally(e); - } - return null; - } - }); + getExecutorService().submit(() -> { + try { + cf.complete(executeRemote(interfaceClass, rc, method, rom)); + } catch (Throwable e) { + cf.completeExceptionally(e); + } + return null; + }); return cf; } diff --git a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java index ff9944c89..db263db99 100644 --- a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java +++ b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java @@ -2025,16 +2025,9 @@ public class RestRequest extends BeanSession implements HttpUriRequest, Configur * @return The HTTP status code. * @throws RestCallException If the executor service was not defined. */ - public Future<RestResponse> runFuture() throws RestCallException { - return client.getExecutorService().submit( - new Callable<RestResponse>() { - @Override /* Callable */ - public RestResponse call() throws Exception { - return run(); - } - } - ); - } + public Future<RestResponse> runFuture() throws RestCallException { + return client.getExecutorService().submit(() -> run()); + } /** * Same as {@link #run()} but immediately calls {@link RestResponse#consume()} to clean up the response. @@ -2085,12 +2078,7 @@ public class RestRequest extends BeanSession implements HttpUriRequest, Configur */ public Future<RestResponse> completeFuture() throws RestCallException { return client.getExecutorService().submit( - new Callable<RestResponse>() { - @Override /* Callable */ - public RestResponse call() throws Exception { - return complete(); - } - } + () -> complete() ); } diff --git a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java index 83841cedb..6fbe88c27 100644 --- a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java +++ b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java @@ -438,22 +438,19 @@ public class RestResponse implements HttpResponse { return (T)Proxy.newProxyInstance( c.getClassLoader(), new Class[] { c }, - new InvocationHandler() { - @Override /* InvocationHandler */ - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - ResponseBeanPropertyMeta pm = rbm.getProperty(method.getName()); - HttpPartParserSession pp = getPartParserSession(pm.getParser().orElse(rc.getPartParser())); - HttpPartSchema schema = pm.getSchema(); - HttpPartType pt = pm.getPartType(); - String name = pm.getPartName().orElse(null); - ClassMeta<?> type = rc.getBeanContext().getClassMeta(method.getGenericReturnType()); - if (pt == RESPONSE_HEADER) - return getHeader(name).parser(pp).schema(schema).as(type).orElse(null); - if (pt == RESPONSE_STATUS) - return getStatusCode(); - return getContent().schema(schema).as(type); - } - }); + (InvocationHandler) (proxy, method, args) -> { + ResponseBeanPropertyMeta pm = rbm.getProperty(method.getName()); + HttpPartParserSession pp = getPartParserSession(pm.getParser().orElse(rc.getPartParser())); + HttpPartSchema schema = pm.getSchema(); + HttpPartType pt = pm.getPartType(); + String name = pm.getPartName().orElse(null); + ClassMeta<?> type = rc.getBeanContext().getClassMeta(method.getGenericReturnType()); + if (pt == RESPONSE_HEADER) + return getHeader(name).parser(pp).schema(schema).as(type).orElse(null); + if (pt == RESPONSE_STATUS) + return getStatusCode(); + return getContent().schema(schema).as(type); + }); } /**
