Initiates an orderly shutdown in which http requests previously submitted are run to + * completion, but no new requests will be accepted. Running a request to completion may involve + * running several operations in the background, including waiting for responses to be delivered. + * This method waits until all operations have completed execution and the client has terminated. + * + * @see {@linkplain java.net.http.HttpClient#close} + */ + @Override + void close(); + /** * Builds the HttpClient. * diff --git a/http-generator-client/src/main/java/io/avaje/http/generator/client/ClientWriter.java b/http-generator-client/src/main/java/io/avaje/http/generator/client/ClientWriter.java index 52d7d944..1291a06e 100644 --- a/http-generator-client/src/main/java/io/avaje/http/generator/client/ClientWriter.java +++ b/http-generator-client/src/main/java/io/avaje/http/generator/client/ClientWriter.java @@ -1,5 +1,6 @@ package io.avaje.http.generator.client; +import io.avaje.http.generator.core.APContext; import io.avaje.http.generator.core.BaseControllerWriter; import io.avaje.http.generator.core.ControllerReader; import io.avaje.http.generator.core.MethodReader; @@ -62,12 +63,17 @@ private void writeMethods() { for (final ClientMethodWriter methodWriter : methodList) { methodWriter.write(); } + writer.append(" @Override").eol(); + writer.append(" public void close() {").eol(); + writer.append(" this.client.close();").eol(); + writer.append(" }").eol(); } private void writeClassStart() { writer.append(AT_GENERATED).eol(); AnnotationUtil.writeAnnotations(writer, reader.beanType()); - writer.append("public class %s%s implements %s {", shortName, suffix, shortName).eol().eol(); + + writer.append("public class %s%s implements %s, AutoCloseable {", shortName, suffix, shortName).eol().eol(); writer.append(" private final HttpClient client;").eol().eol();