|
| 1 | +/* |
| 2 | + * Copyright 2023 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.cloud.storage; |
| 18 | + |
| 19 | +import com.google.api.core.ApiFuture; |
| 20 | +import com.google.api.core.BetaApi; |
| 21 | +import java.io.IOException; |
| 22 | +import java.nio.channels.WritableByteChannel; |
| 23 | + |
| 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 | + */ |
| 41 | +@BetaApi |
| 42 | +public interface BlobWriteSession { |
| 43 | + |
| 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 |
| 59 | + WritableByteChannel open() throws IOException; |
| 60 | + |
| 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 |
| 72 | + ApiFuture<BlobInfo> getResult(); |
| 73 | +} |
0 commit comments