Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

package software.amazon.smithy.java.client.core;

import java.io.Closeable;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.List;
import java.util.concurrent.CompletionException;
import java.util.function.Predicate;
Expand All @@ -29,7 +32,7 @@
/**
* Base Smithy client class.
*/
public abstract class Client {
public abstract class Client implements Closeable {

private final ClientConfig config;
private final ClientPipeline<?, ?> pipeline;
Expand Down Expand Up @@ -130,6 +133,18 @@ public ClientConfig config() {
return config;
}

/**
* Closes the transport used by this client.
*/
@Override
public void close() {
try {
config.transport().close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

/**
* Builder for Clients and request overrides.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package software.amazon.smithy.java.client.core;

import java.io.Closeable;
import java.io.IOException;
import java.net.ConnectException;
import java.net.ProtocolException;
import java.net.SocketException;
Expand All @@ -25,7 +27,7 @@
* @implNote To be discoverable by dynamic clients and client code generators,
* ClientTransport's should implement a {@link ClientTransportFactory} service provider.
*/
public interface ClientTransport<RequestT, ResponseT> {
public interface ClientTransport<RequestT, ResponseT> extends Closeable {
/**
* Send a prepared request.
*
Expand All @@ -46,6 +48,14 @@ public interface ClientTransport<RequestT, ResponseT> {
*/
MessageExchange<RequestT, ResponseT> messageExchange();

/**
* {@inheritDoc}
*
* <p>Default implementation is a no-op.
*/
@Override
default void close() throws IOException {}

/**
* Remaps a thrown exception to an appropriate {@link TransportException} or {@link CallException}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ private static HttpVersion javaToSmithyVersion(HttpClient.Version version) {
};
}

@Override
public void close() {
client.close();
}

public static final class Factory implements ClientTransportFactory<HttpRequest, HttpResponse> {
@Override
public String name() {
Expand Down
Loading