Skip to content

Commit 1d6a53f

Browse files
committed
docs: preliminary javadocs
1 parent 7df353b commit 1d6a53f

File tree

9 files changed

+166
-20
lines changed

9 files changed

+166
-20
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSession.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,53 @@
2121
import java.io.IOException;
2222
import java.nio.channels.WritableByteChannel;
2323

24+
/**
25+
* A session to write an object to Google Cloud Storage.
26+
*
27+
* <p>A session can only write a single version of an object. If writing multiple versions of an
28+
* object a new session must be created each time.
29+
*
30+
* <p>Provides an api that allows writing to and retrieving the resulting {@link BlobInfo} after
31+
* write finalization.
32+
*
33+
* <p>The underlying implementation is dictated based upon the specified {@link
34+
* BlobWriteSessionConfig} provided at {@link StorageOptions} creation time.
35+
*
36+
* @see GrpcStorageOptions.Builder#setBlobWriteSessionConfig(BlobWriteSessionConfig)
37+
* @see BlobWriteSessionConfig
38+
* @see BlobWriteSessionConfigs
39+
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
40+
*/
2441
@BetaApi
2542
public interface BlobWriteSession {
2643

44+
/**
45+
* Open the {@link WritableByteChannel} for this session.
46+
*
47+
* <p>A session may only be {@code open}ed once. If multiple calls to open are made, an illegal
48+
* state exception will be thrown
49+
*
50+
* <p>Upon calling {@link WritableByteChannel#close()} the object creation will be finalized, and
51+
* {@link #getResult()}s future should resolve.
52+
*
53+
* @throws IOException When creating the {@link WritableByteChannel} if an unrecoverable
54+
* underlying IOException occurs it can be rethrown
55+
* @throws IllegalStateException if open is called more than once
56+
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
57+
*/
58+
@BetaApi
2759
WritableByteChannel open() throws IOException;
2860

61+
/**
62+
* Return an {@link ApiFuture}{@code <BlobInfo>} which will represent the state of the object upon
63+
* finalization and success response from Google Cloud Storage.
64+
*
65+
* <p>This future will not resolve until: 1. The object is successfully finalized and created in
66+
* Google Cloud Storage 2. A terminal failure occurs, the terminal failure will become the
67+
* exception result
68+
*
69+
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
70+
*/
71+
@BetaApi
2972
ApiFuture<BlobInfo> getResult();
3073
}

google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfig.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,27 @@
1818

1919
import com.google.api.core.InternalApi;
2020
import com.google.cloud.storage.Conversions.Decoder;
21+
import com.google.cloud.storage.Storage.BlobWriteOption;
2122
import com.google.cloud.storage.UnifiedOpts.ObjectTargetOpt;
2223
import com.google.cloud.storage.UnifiedOpts.Opts;
2324
import com.google.storage.v2.WriteObjectResponse;
2425
import java.io.IOException;
2526
import java.time.Clock;
2627

28+
/**
29+
* A sealed internal implementation only class which provides the means of configuring a {@link
30+
* BlobWriteSession}.
31+
*
32+
* <p>A {@code BlobWriteSessionConfig} will be used to configure all {@link BlobWriteSession}s
33+
* produced by an instance of {@link Storage}.
34+
*
35+
* @see BlobWriteSessionConfigs
36+
* @see GrpcStorageOptions.Builder#setBlobWriteSessionConfig(BlobWriteSessionConfig)
37+
* @see Storage#blobWriteSession(BlobInfo, BlobWriteOption...)
38+
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
39+
*/
40+
// When we have java modules, actually seal this to internal extension only
41+
@InternalApi
2742
public abstract class BlobWriteSessionConfig {
2843

2944
@InternalApi

google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfigs.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,31 @@
1717
package com.google.cloud.storage;
1818

1919
import com.google.api.core.BetaApi;
20+
import com.google.cloud.storage.GrpcStorageOptions.GrpcStorageDefaults;
21+
import com.google.cloud.storage.Storage.BlobWriteOption;
2022

23+
/**
24+
* Factory class to select and construct {@link BlobWriteSessionConfig}s.
25+
*
26+
* @see BlobWriteSessionConfig
27+
* @see GrpcStorageOptions.Builder#setBlobWriteSessionConfig(BlobWriteSessionConfig)
28+
* @see Storage#blobWriteSession(BlobInfo, BlobWriteOption...)
29+
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
30+
*/
2131
@BetaApi
2232
public final class BlobWriteSessionConfigs {
2333

2434
private BlobWriteSessionConfigs() {}
2535

36+
/**
37+
* Factory to produce the default configuration for uploading an object to Cloud Storage.
38+
*
39+
* <p>Configuration of the chunk size can be performed via {@link
40+
* DefaultBlobWriteSessionConfig#withChunkSize(int)}.
41+
*
42+
* @see GrpcStorageDefaults#getDefaultStorageWriterConfig()
43+
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
44+
*/
2645
@BetaApi
2746
public static DefaultBlobWriteSessionConfig getDefault() {
2847
return new DefaultBlobWriteSessionConfig(ByteSizeConstants._16MiB);

google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultBlobWriteSessionConfig.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,23 @@
3232
import javax.annotation.concurrent.Immutable;
3333

3434
/**
35-
* Configure a writer which is logically equivalent to the following:
35+
* Default Configuration to represent uploading to Google Cloud Storage in a chunked manner.
36+
*
37+
* <p>Perform a resumable upload, uploading at most {@code chunkSize} bytes each PUT.
38+
*
39+
* <p>Configuration of chunk size can be performed via {@link
40+
* DefaultBlobWriteSessionConfig#withChunkSize(int)}.
41+
*
42+
* <p>An instance of this class will provide a {@link BlobWriteSession} is logically equivalent to
43+
* the following:
3644
*
3745
* <pre>{@code
3846
* Storage storage = ...;
3947
* WriteChannel writeChannel = storage.writer(BlobInfo, BlobWriteOption);
4048
* writeChannel.setChunkSize(chunkSize);
4149
* }</pre>
50+
*
51+
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
4252
*/
4353
@Immutable
4454
@BetaApi
@@ -51,10 +61,28 @@ public final class DefaultBlobWriteSessionConfig extends BlobWriteSessionConfig
5161
this.chunkSize = chunkSize;
5262
}
5363

64+
/**
65+
* The number of bytes each chunk can be.
66+
*
67+
* <p><i>Default:</i> {@code 16777216 (16 MiB)}
68+
*
69+
* @see #withChunkSize(int)
70+
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
71+
*/
5472
public int getChunkSize() {
5573
return chunkSize;
5674
}
5775

76+
/**
77+
* Create a new instance with the {@code chunkSize} set to the specified value.
78+
*
79+
* <p><i>Default:</i> {@code 16777216 (16 MiB)}
80+
*
81+
* @param chunkSize The number of bytes each chunk should be. Must be >= {@code 262144 (256 KiB)}
82+
* @return The new instance
83+
* @see #getChunkSize()
84+
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
85+
*/
5886
@BetaApi
5987
public DefaultBlobWriteSessionConfig withChunkSize(int chunkSize) {
6088
Preconditions.checkArgument(

google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.google.cloud.Tuple;
4343
import com.google.cloud.grpc.GrpcTransportOptions;
4444
import com.google.cloud.spi.ServiceRpcFactory;
45+
import com.google.cloud.storage.Storage.BlobWriteOption;
4546
import com.google.cloud.storage.TransportCompatibility.Transport;
4647
import com.google.cloud.storage.UnifiedOpts.Opts;
4748
import com.google.cloud.storage.UnifiedOpts.UserProject;
@@ -511,9 +512,15 @@ public GrpcStorageOptions.Builder setGrpcInterceptorProvider(
511512
return this;
512513
}
513514

514-
/** @since 2.24.0 This new api is in preview and is subject to breaking changes. */
515+
/**
516+
* @see BlobWriteSessionConfig
517+
* @see BlobWriteSessionConfigs
518+
* @see Storage#blobWriteSession(BlobInfo, BlobWriteOption...)
519+
* @see GrpcStorageDefaults#getDefaultStorageWriterConfig()
520+
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
521+
*/
515522
@BetaApi
516-
public GrpcStorageOptions.Builder setStorageWriterConfig(
523+
public GrpcStorageOptions.Builder setBlobWriteSessionConfig(
517524
@NonNull BlobWriteSessionConfig blobWriteSessionConfig) {
518525
requireNonNull(blobWriteSessionConfig, "blobWriteSessionConfig must be non null");
519526
this.blobWriteSessionConfig = blobWriteSessionConfig;
@@ -584,6 +591,8 @@ public GrpcInterceptorProvider grpcInterceptorProvider() {
584591
return INTERCEPTOR_PROVIDER;
585592
}
586593

594+
/** @since 2.26.0 This new api is in preview and is subject to breaking changes. */
595+
@BetaApi
587596
public BlobWriteSessionConfig getDefaultStorageWriterConfig() {
588597
return BlobWriteSessionConfigs.getDefault();
589598
}

google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.cloud.storage;
1818

19+
import static com.google.cloud.storage.CrossTransportUtils.fmtMethodName;
20+
import static com.google.cloud.storage.CrossTransportUtils.throwGrpcOnly;
1921
import static com.google.common.base.Preconditions.checkArgument;
2022
import static com.google.common.base.Preconditions.checkNotNull;
2123
import static java.util.Objects.requireNonNull;
@@ -4616,7 +4618,51 @@ List<Boolean> testIamPermissions(
46164618
@Override
46174619
default void close() throws Exception {}
46184620

4621+
/**
4622+
* Create a new {@link BlobWriteSession} for the specified {@code blobInfo} and {@code options}.
4623+
*
4624+
* <p>The returned {@code BlobWriteSession} can be used to write an individual version, a new
4625+
* session must be created each time you want to create a new version.
4626+
*
4627+
* <p>By default, any MD5 value in the provided {@code blobInfo} is ignored unless the option
4628+
* {@link BlobWriteOption#md5Match()} is included in {@code options}.
4629+
*
4630+
* <p>By default, any CRC32c value in the provided {@code blobInfo} is ignored unless the option
4631+
* {@link BlobWriteOption#crc32cMatch()} is included in {@code options}.
4632+
*
4633+
* <h4>Example of creating an object using {@code BlobWriteSession}:</h4>
4634+
*
4635+
* <pre>{@code
4636+
* String bucketName = "my-unique-bucket";
4637+
* String blobName = "my-blob-name";
4638+
* BlobId blobId = BlobId.of(bucketName, blobName);
4639+
* BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
4640+
* ReadableByteChannel readableByteChannel = ...;
4641+
* BlobWriteSession blobWriteSession = storage.blobWriteSession(blobInfo, BlobWriteOption.doesNotExist());
4642+
*
4643+
* // open the channel for writing
4644+
* try (WritableByteChannel writableByteChannel = blobWriteSession.open()) {
4645+
* // copy all bytes
4646+
* ByteStreams.copy(readableByteChannel, writableByteChannel);
4647+
* } catch (IOException e) {
4648+
* // handle IOException
4649+
* }
4650+
*
4651+
* // get the resulting object metadata
4652+
* ApiFuture<BlobInfo> resultFuture = blobWriteSession.getResult();
4653+
* BlobInfo gen1 = resultFuture.get();
4654+
* }</pre>
4655+
*
4656+
* @param blobInfo blob to create
4657+
* @param options blob write options
4658+
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
4659+
* @see BlobWriteSessionConfig
4660+
* @see BlobWriteSessionConfigs
4661+
* @see GrpcStorageOptions.Builder#setBlobWriteSessionConfig(BlobWriteSessionConfig)
4662+
*/
46194663
@BetaApi
46204664
@TransportCompatibility({Transport.GRPC})
4621-
BlobWriteSession blobWriteSession(BlobInfo info, BlobWriteOption... options);
4665+
default BlobWriteSession blobWriteSession(BlobInfo blobInfo, BlobWriteOption... options) {
4666+
return throwGrpcOnly(fmtMethodName("blobWriteSession", BlobInfo.class, BlobWriteOption.class));
4667+
}
46224668
}

google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.google.cloud.storage;
1818

19-
import static com.google.cloud.storage.CrossTransportUtils.fmtMethodName;
20-
import static com.google.cloud.storage.CrossTransportUtils.throwGrpcOnly;
2119
import static com.google.cloud.storage.SignedUrlEncodingHelper.Rfc3986UriEncode;
2220
import static com.google.common.base.MoreObjects.firstNonNull;
2321
import static com.google.common.base.Preconditions.checkArgument;
@@ -26,7 +24,6 @@
2624
import static java.util.concurrent.Executors.callable;
2725

2826
import com.google.api.core.ApiFuture;
29-
import com.google.api.core.BetaApi;
3027
import com.google.api.gax.paging.Page;
3128
import com.google.api.gax.retrying.ResultRetryAlgorithm;
3229
import com.google.api.services.storage.model.BucketAccessControl;
@@ -1565,12 +1562,6 @@ public boolean deleteNotification(final String bucket, final String notification
15651562
Function.identity());
15661563
}
15671564

1568-
@BetaApi
1569-
@Override
1570-
public BlobWriteSession blobWriteSession(BlobInfo info, BlobWriteOption... options) {
1571-
return throwGrpcOnly(fmtMethodName("blobWriteSession", BlobInfo.class, BlobWriteOption.class));
1572-
}
1573-
15741565
@Override
15751566
public HttpStorageOptions getOptions() {
15761567
return (HttpStorageOptions) super.getOptions();

google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBlobWriteSessionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public void overrideDefaultBufferSize() throws Exception {
6161
GrpcStorageOptions options =
6262
((GrpcStorageOptions) storage.getOptions())
6363
.toBuilder()
64-
.setStorageWriterConfig(BlobWriteSessionConfigs.getDefault().withChunkSize(256 * 1024))
64+
.setBlobWriteSessionConfig(
65+
BlobWriteSessionConfigs.getDefault().withChunkSize(256 * 1024))
6566
.build();
6667
try (Storage s = options.getService()) {
6768
doTest(s);

google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/AbstractStorageProxy.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.google.cloud.storage.Blob;
2626
import com.google.cloud.storage.BlobId;
2727
import com.google.cloud.storage.BlobInfo;
28-
import com.google.cloud.storage.BlobWriteSession;
2928
import com.google.cloud.storage.Bucket;
3029
import com.google.cloud.storage.BucketInfo;
3130
import com.google.cloud.storage.CopyWriter;
@@ -479,11 +478,6 @@ public boolean deleteNotification(String bucket, String notificationId) {
479478
return delegate.deleteNotification(bucket, notificationId);
480479
}
481480

482-
@Override
483-
public BlobWriteSession blobWriteSession(BlobInfo info, BlobWriteOption... options) {
484-
return delegate.blobWriteSession(info, options);
485-
}
486-
487481
@Override
488482
public void close() throws Exception {
489483
delegate.close();

0 commit comments

Comments
 (0)