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 @@ -105,6 +105,16 @@ public Class<? extends SubstrateSdkException> getException(Throwable t) {
return UnknownException.class;
}

/**
* Closes the underlying OSS client and releases any resources.
*/
@Override
public void close() {
if (ossClient != null) {
ossClient.shutdown();
}
}

public static class Builder extends AbstractBlobClient.Builder<AliBlobClient> {

public Builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,16 @@ protected boolean doDoesObjectExist(String key, String versionId) {
return ossClient.doesObjectExist(transformer.toMetadataRequest(key, versionId));
}

/**
* Closes the underlying OSS client and releases any resources.
*/
@Override
public void close() {
if (ossClient != null) {
ossClient.shutdown();
}
}

@Getter
public static class Builder extends AbstractBlobStore.Builder<AliBlobStore, Builder> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ public Class<? extends SubstrateSdkException> getException(Throwable t) {
return UnknownException.class;
}

/**
* Closes the underlying S3 client and releases any resources.
*/
@Override
public void close() {
if (s3Client != null) {
s3Client.close();
}
}


public static class Builder extends AbstractBlobClient.Builder<AwsBlobClient> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import com.salesforce.multicloudj.common.exceptions.InvalidArgumentException;
import com.salesforce.multicloudj.common.exceptions.SubstrateSdkException;
import com.salesforce.multicloudj.common.exceptions.UnknownException;
import com.salesforce.multicloudj.common.retries.RetryConfig;
import lombok.Getter;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.ResponseBytes;
import software.amazon.awssdk.core.ResponseInputStream;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.core.sync.ResponseTransformer;
Expand Down Expand Up @@ -77,7 +77,6 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import software.amazon.awssdk.core.ResponseInputStream;

/**
* AWS implementation of BlobStore
Expand Down Expand Up @@ -489,6 +488,16 @@ protected boolean doDoesObjectExist(String key, String versionId) {
}
}

/**
* Closes the underlying S3 client and releases any resources.
*/
@Override
public void close() {
if (s3Client != null) {
s3Client.close();
}
}

@Getter
public static class Builder extends AbstractBlobStore.Builder<AwsBlobStore, Builder> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,19 @@ protected CompletableFuture<Boolean> doDoesObjectExist(String key, String versio
});
}

/**
* Closes the underlying S3 async client and transfer manager, releasing any resources.
*/
@Override
public void close() {
if (transferManager != null) {
transferManager.close();
}
if (client != null) {
client.close();
}
}

public static Builder builder() {
return new Builder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
/**
* Entry point for async Client code to interact with the Blob storage.
*/
public class AsyncBucketClient {
public class AsyncBucketClient implements AutoCloseable {

protected AsyncBlobStore blobStore;

Expand Down Expand Up @@ -428,6 +428,16 @@ public CompletableFuture<Void> deleteDirectory(String prefix) {
.exceptionally(this::handleException);
}

/**
* Closes the underlying async blob store and releases any resources.
*/
@Override
public void close() throws Exception {
if (blobStore != null) {
blobStore.close();
}
}

public static class Builder extends BlobClientBuilder<AsyncBucketClient, AsyncBlobStore> {

public Builder(String providerId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/**
* API for async interaction with a backing blob storage engine.
*/
public interface AsyncBlobStore extends SdkService {
public interface AsyncBlobStore extends SdkService, AutoCloseable {

/**
* Returns the bucket this blob store operates against.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,14 @@ public CompletableFuture<DirectoryUploadResponse> uploadDirectory(DirectoryUploa
public CompletableFuture<Void> deleteDirectory(String prefix) {
return CompletableFuture.runAsync(() -> blobStore.deleteDirectory(prefix), executorService);
}

/**
* Closes the wrapped blob store and releases any resources.
*/
@Override
public void close() throws Exception {
if (blobStore != null) {
blobStore.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* <p>This class serves the purpose of providing common (i.e. substrate-agnostic) service functionality.
*
*/
public class BlobClient {
public class BlobClient implements AutoCloseable {

protected AbstractBlobClient<?> blobClient;

Expand Down Expand Up @@ -58,6 +58,16 @@ public void createBucket(String bucketName) {
}
}

/**
* Closes the underlying blob client and releases any resources.
*/
@Override
public void close() throws Exception {
if (blobClient != null) {
blobClient.close();
}
}

public static class BlobClientBuilder {

private final AbstractBlobClient.Builder<?> blobClientBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/**
* Entry point for Client code to interact with the Blob storage.
*/
public class BucketClient {
public class BucketClient implements AutoCloseable {

protected AbstractBlobStore blobStore;

Expand Down Expand Up @@ -484,6 +484,16 @@ public boolean doesObjectExist(String key, String versionId) {
}
}

/**
* Closes the underlying blob store and releases any resources.
*/
@Override
public void close() throws Exception {
if (blobStore != null) {
blobStore.close();
}
}

public static class BlobBuilder {

private final AbstractBlobStore.Builder<?, ?> blobStoreBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Base class for substrate-specific implementations.
* This class serves the purpose of providing common (i.e. substrate-agnostic) functionality.
*/
public abstract class AbstractBlobClient<T extends AbstractBlobClient<T>> implements Provider, SdkService {
public abstract class AbstractBlobClient<T extends AbstractBlobClient<T>> implements Provider, SdkService, AutoCloseable {
Copy link
Collaborator

@LihaoLiuXs LihaoLiuXs Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a default close method in AbstractBlobClient and AbstractBlobStore?

@Override public void close() { }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really because we want to force the providers to implement the close


private final String providerId;
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Base class for substrate-specific implementations.AbstractBlobStore
* This class serves the purpose of providing common (i.e. substrate-agnostic) functionality
*/
public abstract class AbstractBlobStore implements BlobStore {
public abstract class AbstractBlobStore implements BlobStore, AutoCloseable {

@Getter
private final String providerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ protected CompletableFuture<Void> doDeleteDirectory(String prefix) {
return CompletableFuture.completedFuture(null);
}

@Override
public void close() {
// Test implementation - no-op
}

public static Builder builder() {
return new Builder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ protected void doCreateBucket(String bucketName) {
// Test implementation - no-op
}

@Override
public void close() {
// Test implementation - no-op
}

public static class Builder extends AbstractBlobClient.Builder<TestBlobClient> {

protected Builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ public Class<? extends SubstrateSdkException> getException(Throwable t) {
return null;
}

@Override
public void close() {
// Test implementation - no-op
}

public static class Builder extends AbstractBlobStore.Builder<TestBlobStore, Builder> {

protected Builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ public Class<? extends SubstrateSdkException> getException(Throwable t) {
return UnknownException.class;
}

/**
* Closes the underlying GCP Storage client and releases any resources.
*/
@Override
public void close() {
try {
if (storage != null) {
storage.close();
}
} catch (Exception e) {
throw new SubstrateSdkException("Failed to close GCP Storage client", e);
}
}

public static class Builder extends AbstractBlobClient.Builder<GcpBlobClient> {

public Builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,20 @@ public Class<? extends SubstrateSdkException> getException(Throwable t) {
return UnknownException.class;
}

/**
* Closes the underlying GCP Storage client and releases any resources.
*/
@Override
public void close() {
try {
if (storage != null) {
storage.close();
}
} catch (Exception e) {
throw new SubstrateSdkException("Failed to close GCP Storage client", e);
}
}

@Getter
public static class Builder extends AbstractBlobStore.Builder<GcpBlobStore, Builder> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.salesforce.multicloudj.blob.driver.AbstractBlobStore;
import com.salesforce.multicloudj.blob.gcp.GcpBlobStore;
import com.salesforce.multicloudj.blob.gcp.GcpTransformerSupplier;
import com.salesforce.multicloudj.common.exceptions.SubstrateSdkException;
import com.salesforce.multicloudj.common.gcp.GcpConstants;
import lombok.Getter;

Expand Down Expand Up @@ -36,6 +37,20 @@ public GcpAsyncBlobStore(AbstractBlobStore blobStore, ExecutorService executorSe
this.transformerSupplier = transformerSupplier;
}

/**
* Closes the underlying GCP Storage client and wrapped blob store
*/
@Override
public void close() {
try {
if (storage != null) {
storage.close();
}
} catch (Exception e) {
throw new SubstrateSdkException("Failed to close GCP Storage client", e);
}
}

public static Builder builder() {
return new Builder();
}
Expand Down
Loading