Skip to content

Commit 8332e1b

Browse files
committed
chore: AppendableBlobUpload{,Config} -> BlobAppendableUpload{,Config}
1 parent e4688a0 commit 8332e1b

File tree

11 files changed

+146
-106
lines changed

11 files changed

+146
-106
lines changed

google-cloud-storage/clirr-ignored-differences.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
<difference>
131131
<differenceType>7012</differenceType>
132132
<className>com/google/cloud/storage/Storage</className>
133-
<method>com.google.cloud.storage.AppendableBlobUpload appendableBlobUpload(com.google.cloud.storage.BlobInfo, com.google.cloud.storage.AppendableBlobUploadConfig, com.google.cloud.storage.Storage$BlobWriteOption[])</method>
133+
<method>com.google.cloud.storage.BlobAppendableUpload blobAppendableUpload(com.google.cloud.storage.BlobInfo, com.google.cloud.storage.BlobAppendableUploadConfig, com.google.cloud.storage.Storage$BlobWriteOption[])</method>
134134
</difference>
135135
<difference>
136136
<differenceType>7005</differenceType>

google-cloud-storage/src/main/java/com/google/cloud/storage/AppendableBlobUpload.java renamed to google-cloud-storage/src/main/java/com/google/cloud/storage/BlobAppendableUpload.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@
1616

1717
package com.google.cloud.storage;
1818

19+
import com.google.api.core.ApiFuture;
1920
import com.google.api.core.BetaApi;
2021
import com.google.api.core.InternalExtensionOnly;
2122
import com.google.cloud.storage.Storage.BlobWriteOption;
2223
import java.io.IOException;
2324
import java.nio.ByteBuffer;
2425
import java.nio.channels.WritableByteChannel;
25-
import java.util.concurrent.ExecutionException;
2626

2727
/**
2828
* Interface representing those methods which can be used to write to and interact with an
2929
* appendable upload.
3030
*
31-
* @see Storage#appendableBlobUpload(BlobInfo, AppendableBlobUploadConfig, BlobWriteOption...)
31+
* @see Storage#blobAppendableUpload(BlobInfo, BlobAppendableUploadConfig, BlobWriteOption...)
3232
*/
3333
@BetaApi
3434
@InternalExtensionOnly
35-
public interface AppendableBlobUpload extends AutoCloseable, WritableByteChannel {
35+
public interface BlobAppendableUpload extends AutoCloseable, WritableByteChannel {
3636

3737
/**
3838
* Write some bytes to the appendable session. Whether a flush happens will depend on how many
3939
* bytes have been written prior, how many bytes are being written now and what {@link
40-
* AppendableBlobUploadConfig} was provided when creating the {@link AppendableBlobUpload}.
40+
* BlobAppendableUploadConfig} was provided when creating the {@link BlobAppendableUpload}.
4141
*
4242
* <p>This method can block the invoking thread in order to ensure written bytes are acknowledged
4343
* by Google Cloud Storage.
4444
*
45-
* @see Storage#appendableBlobUpload(BlobInfo, AppendableBlobUploadConfig, BlobWriteOption...)
45+
* @see Storage#blobAppendableUpload(BlobInfo, BlobAppendableUploadConfig, BlobWriteOption...)
4646
*/
4747
@Override
4848
int write(ByteBuffer src) throws IOException;
@@ -61,8 +61,8 @@ public interface AppendableBlobUpload extends AutoCloseable, WritableByteChannel
6161
* Finalize the appendable upload, close any underlying stream and release any releasable
6262
* resources once out of scope.
6363
*
64-
* <p>Once this method is called, and returns no more write to the object will be allowed by GCS.
64+
* <p>Once this method is called, and returns no more writes to the object will be allowed by GCS.
6565
*/
6666
@BetaApi
67-
BlobInfo finalizeUpload() throws IOException, ExecutionException, InterruptedException;
67+
ApiFuture<BlobInfo> finalizeUpload() throws IOException;
6868
}

google-cloud-storage/src/main/java/com/google/cloud/storage/AppendableBlobUploadConfig.java renamed to google-cloud-storage/src/main/java/com/google/cloud/storage/BlobAppendableUploadConfig.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@
2929
*
3030
* <p>Instances of this class are immutable and thread safe.
3131
*
32-
* @see Storage#appendableBlobUpload(BlobInfo, AppendableBlobUploadConfig, BlobWriteOption...)
32+
* @see Storage#blobAppendableUpload(BlobInfo, BlobAppendableUploadConfig, BlobWriteOption...)
3333
* @since 2.51.0 This new api is in preview and is subject to breaking changes.
3434
*/
3535
@Immutable
3636
@BetaApi
3737
@TransportCompatibility({Transport.GRPC})
38-
public final class AppendableBlobUploadConfig {
38+
public final class BlobAppendableUploadConfig {
3939

40-
private static final AppendableBlobUploadConfig INSTANCE =
41-
new AppendableBlobUploadConfig(FlushPolicy.minFlushSize(_256KiB));
40+
private static final BlobAppendableUploadConfig INSTANCE =
41+
new BlobAppendableUploadConfig(FlushPolicy.minFlushSize(_256KiB));
4242

4343
private final FlushPolicy flushPolicy;
4444

45-
private AppendableBlobUploadConfig(FlushPolicy flushPolicy) {
45+
private BlobAppendableUploadConfig(FlushPolicy flushPolicy) {
4646
this.flushPolicy = flushPolicy;
4747
}
4848

@@ -69,12 +69,12 @@ public FlushPolicy getFlushPolicy() {
6969
* @since 2.51.0 This new api is in preview and is subject to breaking changes.
7070
*/
7171
@BetaApi
72-
public AppendableBlobUploadConfig withFlushPolicy(FlushPolicy flushPolicy) {
72+
public BlobAppendableUploadConfig withFlushPolicy(FlushPolicy flushPolicy) {
7373
requireNonNull(flushPolicy, "flushPolicy must be non null");
7474
if (this.flushPolicy.equals(flushPolicy)) {
7575
return this;
7676
}
77-
return new AppendableBlobUploadConfig(flushPolicy);
77+
return new BlobAppendableUploadConfig(flushPolicy);
7878
}
7979

8080
/**
@@ -83,15 +83,15 @@ public AppendableBlobUploadConfig withFlushPolicy(FlushPolicy flushPolicy) {
8383
* <p>The {@link FlushPolicy} of this instance is equivalent to the following:
8484
*
8585
* <pre>{@code
86-
* AppendableBlobUploadConfig.of()
86+
* BlobAppendableUploadConfig.of()
8787
* .withFlushPolicy(FlushPolicy.minFlushSize(256 * 1024))
8888
* }</pre>
8989
*
9090
* @since 2.51.0 This new api is in preview and is subject to breaking changes.
9191
* @see FlushPolicy#minFlushSize(int)
9292
*/
9393
@BetaApi
94-
public static AppendableBlobUploadConfig of() {
94+
public static BlobAppendableUploadConfig of() {
9595
return INSTANCE;
9696
}
9797
}

google-cloud-storage/src/main/java/com/google/cloud/storage/AppendableBlobUploadImpl.java renamed to google-cloud-storage/src/main/java/com/google/cloud/storage/BlobAppendableUploadImpl.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
import com.google.cloud.storage.BufferedWritableByteChannelSession.BufferedWritableByteChannel;
2222
import java.io.IOException;
2323
import java.nio.ByteBuffer;
24-
import java.util.concurrent.ExecutionException;
2524
import java.util.concurrent.locks.ReentrantLock;
2625

2726
@BetaApi
28-
final class AppendableBlobUploadImpl implements AppendableBlobUpload {
27+
final class BlobAppendableUploadImpl implements BlobAppendableUpload {
2928
private final AppendableObjectBufferedWritableByteChannel channel;
3029
private final ApiFuture<BlobInfo> result;
3130

32-
private AppendableBlobUploadImpl(BlobInfo blob, BlobWriteSession session, boolean takeover)
31+
private BlobAppendableUploadImpl(BlobInfo blob, BlobWriteSession session, boolean takeover)
3332
throws IOException {
3433
channel = (AppendableObjectBufferedWritableByteChannel) (session.open());
3534
result = session.getResult();
@@ -38,25 +37,25 @@ private AppendableBlobUploadImpl(BlobInfo blob, BlobWriteSession session, boolea
3837
}
3938
}
4039

41-
static AppendableBlobUpload createNewAppendableBlob(BlobInfo blob, BlobWriteSession session)
40+
static BlobAppendableUpload createNewAppendableBlob(BlobInfo blob, BlobWriteSession session)
4241
throws IOException {
43-
return new AppendableBlobUploadImpl(blob, session, false);
42+
return new BlobAppendableUploadImpl(blob, session, false);
4443
}
4544

46-
static AppendableBlobUpload resumeAppendableUpload(BlobInfo blob, BlobWriteSession session)
45+
static BlobAppendableUpload resumeAppendableUpload(BlobInfo blob, BlobWriteSession session)
4746
throws IOException {
48-
return new AppendableBlobUploadImpl(blob, session, true);
47+
return new BlobAppendableUploadImpl(blob, session, true);
4948
}
5049

5150
void startTakeoverStream() {
5251
channel.startTakeoverStream();
5352
}
5453

5554
@BetaApi
56-
public BlobInfo finalizeUpload() throws IOException, ExecutionException, InterruptedException {
55+
public ApiFuture<BlobInfo> finalizeUpload() throws IOException {
5756
channel.finalizeWrite();
5857
close();
59-
return result.get();
58+
return result;
6059
}
6160

6261
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ BufferedWritableByteChannelSession<BidiWriteObjectResponse> build() {
236236
Retrying::newCallContext))
237237
.andThen(
238238
c ->
239-
new AppendableBlobUploadImpl.AppendableObjectBufferedWritableByteChannel(
239+
new BlobAppendableUploadImpl.AppendableObjectBufferedWritableByteChannel(
240240
flushPolicy.createBufferedChannel(c), c)));
241241
}
242242
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,15 +1423,15 @@ public BlobWriteSession blobWriteSession(BlobInfo info, BlobWriteOption... optio
14231423

14241424
@BetaApi
14251425
@Override
1426-
public AppendableBlobUpload appendableBlobUpload(
1427-
BlobInfo blob, AppendableBlobUploadConfig uploadConfig, BlobWriteOption... options)
1426+
public BlobAppendableUpload blobAppendableUpload(
1427+
BlobInfo blobInfo, BlobAppendableUploadConfig uploadConfig, BlobWriteOption... options)
14281428
throws IOException {
1429-
boolean takeOver = blob.getGeneration() != null;
1430-
Opts<ObjectTargetOpt> opts = Opts.unwrap(options).resolveFrom(blob);
1429+
boolean takeOver = blobInfo.getGeneration() != null;
1430+
Opts<ObjectTargetOpt> opts = Opts.unwrap(options).resolveFrom(blobInfo);
14311431
BidiWriteObjectRequest req =
14321432
takeOver
1433-
? getBidiWriteObjectRequestForTakeover(blob, opts)
1434-
: getBidiWriteObjectRequest(blob, opts);
1433+
? getBidiWriteObjectRequestForTakeover(blobInfo, opts)
1434+
: getBidiWriteObjectRequest(blobInfo, opts);
14351435
BidiAppendableWrite baw = new BidiAppendableWrite(req, takeOver);
14361436
ApiFuture<BidiAppendableWrite> startAppendableWrite = ApiFutures.immediateFuture(baw);
14371437
WritableByteChannelSession<BufferedWritableByteChannel, BidiWriteObjectResponse> build =
@@ -1476,8 +1476,8 @@ public boolean shouldRetry(
14761476
build, BidiBlobWriteSessionConfig.Factory.WRITE_OBJECT_RESPONSE_BLOB_INFO_DECODER);
14771477
BlobWriteSession session = BlobWriteSessions.of(dec);
14781478
return takeOver
1479-
? AppendableBlobUploadImpl.resumeAppendableUpload(blob, session)
1480-
: AppendableBlobUploadImpl.createNewAppendableBlob(blob, session);
1479+
? BlobAppendableUploadImpl.resumeAppendableUpload(blobInfo, session)
1480+
: BlobAppendableUploadImpl.createNewAppendableBlob(blobInfo, session);
14811481
}
14821482

14831483
@Override

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import java.nio.file.Path;
5959
import java.util.List;
6060
import java.util.Locale;
61-
import java.util.concurrent.ExecutionException;
6261
import java.util.concurrent.TimeUnit;
6362
import java.util.function.UnaryOperator;
6463
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -1506,14 +1505,14 @@ public ApiFuture<BlobReadSession> blobReadSession(BlobId id, BlobSourceOption...
15061505
}
15071506

15081507
@Override
1509-
public AppendableBlobUpload appendableBlobUpload(
1510-
BlobInfo blob, AppendableBlobUploadConfig uploadConfig, BlobWriteOption... options)
1508+
public BlobAppendableUpload blobAppendableUpload(
1509+
BlobInfo blobInfo, BlobAppendableUploadConfig uploadConfig, BlobWriteOption... options)
15111510
throws IOException {
15121511
Span span = tracer.spanBuilder("appendableBlobUpload").startSpan();
15131512
try (Scope ignore = span.makeCurrent()) {
15141513

1515-
return new OtelDecoratingAppendableBlobUpload(
1516-
delegate.appendableBlobUpload(blob, uploadConfig, options), span, Context.current());
1514+
return new OtelDecoratingBlobAppendableUpload(
1515+
delegate.blobAppendableUpload(blobInfo, uploadConfig, options), span, Context.current());
15171516

15181517
} catch (Throwable t) {
15191518
span.recordException(t);
@@ -2103,13 +2102,13 @@ public String toString() {
21032102
}
21042103
}
21052104

2106-
final class OtelDecoratingAppendableBlobUpload implements AppendableBlobUpload {
2107-
private final AppendableBlobUpload delegate;
2105+
final class OtelDecoratingBlobAppendableUpload implements BlobAppendableUpload {
2106+
private final BlobAppendableUpload delegate;
21082107
private final Span openSpan;
21092108
private final Context openContext;
21102109

2111-
private OtelDecoratingAppendableBlobUpload(
2112-
AppendableBlobUpload delegate, Span openSpan, Context openContext) {
2110+
private OtelDecoratingBlobAppendableUpload(
2111+
BlobAppendableUpload delegate, Span openSpan, Context openContext) {
21132112
this.delegate = delegate;
21142113
this.openSpan = openSpan;
21152114
this.openContext = openContext;
@@ -2135,7 +2134,7 @@ public void close() throws IOException {
21352134

21362135
@Override
21372136
@BetaApi
2138-
public BlobInfo finalizeUpload() throws IOException, ExecutionException, InterruptedException {
2137+
public ApiFuture<BlobInfo> finalizeUpload() throws IOException {
21392138
Span span =
21402139
tracer
21412140
.spanBuilder("appendableBlobUpload/finalizeUpload")

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5882,13 +5882,52 @@ default ApiFuture<BlobReadSession> blobReadSession(BlobId id, BlobSourceOption..
58825882
}
58835883

58845884
/**
5885-
* @throws IOException
5885+
* Create a new {@link BlobAppendableUpload} for the specified {@code blobInfo} and {@code
5886+
* options}.
5887+
*
5888+
* <p>The returned {@code BlobWriteSession} can be used to write an individual version, a new
5889+
* session must be created each time you want to create a new version.
5890+
*
5891+
* <p>If your object exists, but is still in an appendable state ensure you provide the generation
5892+
* of the object in the provided {@code blobInfo} ({@link BlobInfo#getBlobId()
5893+
* blobInfo.getBlobId()}{@link BlobId#getGeneration() .getGeneration()}) to enable takeover.
5894+
*
5895+
* <h4>Example of creating an object using {@code BlobAppendableUpload}:</h4>
5896+
*
5897+
* <pre>{@code
5898+
* String bucketName = "my-unique-bucket";
5899+
* String blobName = "my-blobInfo-name";
5900+
* BlobId blobId = BlobId.of(bucketName, blobName);
5901+
* BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
5902+
* ReadableByteChannel readableByteChannel = ...;
5903+
*
5904+
* try (
5905+
* BlobAppendableUpload blobAppendableUpload = storage.blobAppendableUpload(
5906+
* blobInfo,
5907+
* BlobAppendableUploadConfig.of()
5908+
* )
5909+
* ) {
5910+
* // copy all bytes
5911+
* ByteStreams.copy(readableByteChannel, blobAppendableUpload);
5912+
* // get the resulting object metadata
5913+
* ApiFuture<BlobInfo> resultFuture = blobAppendableUpload.finalizeUpload();
5914+
* BlobInfo gen1 = resultFuture.get();
5915+
*
5916+
* } catch (IOException e) {
5917+
* // handle IOException
5918+
* }
5919+
* }</pre>
5920+
*
5921+
* @param blobInfo blobInfo to create
5922+
* @param uploadConfig the configuration parameters for the channel
5923+
* @param options blobInfo write options
58865924
* @since 2.51.0 This new api is in preview and is subject to breaking changes.
5925+
* @see StorageOptions#grpc()
58875926
*/
58885927
@BetaApi
58895928
@TransportCompatibility({Transport.GRPC})
5890-
default AppendableBlobUpload appendableBlobUpload(
5891-
BlobInfo blob, AppendableBlobUploadConfig uploadConfig, BlobWriteOption... options)
5929+
default BlobAppendableUpload blobAppendableUpload(
5930+
BlobInfo blobInfo, BlobAppendableUploadConfig uploadConfig, BlobWriteOption... options)
58925931
throws IOException {
58935932
return throwGrpcOnly(
58945933
fmtMethodName("appendableBlobUpload", BlobId.class, BlobWriteOption.class));

0 commit comments

Comments
 (0)