|
| 1 | +/* |
| 2 | + * Copyright 2018 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 | + * https://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 | +package com.google.cloud.bigquery.storage.v1beta1; |
| 17 | + |
| 18 | +import com.google.api.core.ApiFunction; |
| 19 | +import com.google.api.core.BetaApi; |
| 20 | +import com.google.api.gax.core.GoogleCredentialsProvider; |
| 21 | +import com.google.api.gax.core.InstantiatingExecutorProvider; |
| 22 | +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; |
| 23 | +import com.google.api.gax.rpc.ApiClientHeaderProvider; |
| 24 | +import com.google.api.gax.rpc.ClientContext; |
| 25 | +import com.google.api.gax.rpc.ClientSettings; |
| 26 | +import com.google.api.gax.rpc.ServerStreamingCallSettings; |
| 27 | +import com.google.api.gax.rpc.TransportChannelProvider; |
| 28 | +import com.google.api.gax.rpc.UnaryCallSettings; |
| 29 | +import com.google.cloud.bigquery.storage.v1beta1.Storage.BatchCreateReadSessionStreamsRequest; |
| 30 | +import com.google.cloud.bigquery.storage.v1beta1.Storage.BatchCreateReadSessionStreamsResponse; |
| 31 | +import com.google.cloud.bigquery.storage.v1beta1.Storage.CreateReadSessionRequest; |
| 32 | +import com.google.cloud.bigquery.storage.v1beta1.Storage.FinalizeStreamRequest; |
| 33 | +import com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsRequest; |
| 34 | +import com.google.cloud.bigquery.storage.v1beta1.Storage.ReadRowsResponse; |
| 35 | +import com.google.cloud.bigquery.storage.v1beta1.Storage.ReadSession; |
| 36 | +import com.google.cloud.bigquery.storage.v1beta1.Storage.SplitReadStreamRequest; |
| 37 | +import com.google.cloud.bigquery.storage.v1beta1.Storage.SplitReadStreamResponse; |
| 38 | +import com.google.cloud.bigquery.storage.v1beta1.stub.EnhancedBigQueryStorageStubSettings; |
| 39 | +import com.google.protobuf.Empty; |
| 40 | +import java.io.IOException; |
| 41 | +import java.util.List; |
| 42 | + |
| 43 | +/** |
| 44 | + * Settings class to configure an instance of {@link BigQueryStorageClient}. |
| 45 | + * |
| 46 | + * <p>The default instance has everything set to sensible defaults: |
| 47 | + * |
| 48 | + * <ul> |
| 49 | + * <li>The default service address (bigquerystorage.googleapis.com) and default port (443) are |
| 50 | + * used. |
| 51 | + * <li>Credentials are acquired automatically through Application Default Credentials. |
| 52 | + * <li>Retries are configured for idempotent methods but not for non-idempotent methods. |
| 53 | + * </ul> |
| 54 | + * |
| 55 | + * <p>The builder of this class is recursive, so contained classes are themselves builders. When |
| 56 | + * build() is called, the tree of builders is called to create the complete settings object. For |
| 57 | + * example, to set the total timeout of createReadSession to 30 seconds: |
| 58 | + * |
| 59 | + * <pre> |
| 60 | + * <code> |
| 61 | + * BigQueryStorageSettings.Builder settingsBuilder = BaseBigQueryStorageSettings.newBuilder(); |
| 62 | + * settingsBuilder.createReadSessionSettings().getRetrySettings().toBuilder() |
| 63 | + * .setTotalTimeout(Duration.ofSeconds(30)); |
| 64 | + * BaseBigQueryStorageSettings settings = settingsBuilder.build(); |
| 65 | + * </code> |
| 66 | + * </pre> |
| 67 | + */ |
| 68 | +@BetaApi |
| 69 | +public class BigQueryStorageSettings extends ClientSettings<BigQueryStorageSettings> { |
| 70 | + |
| 71 | + /** Returns the object with the settings used for calls to createReadSession. */ |
| 72 | + public UnaryCallSettings<CreateReadSessionRequest, ReadSession> createReadSessionSettings() { |
| 73 | + return getTypedStubSettings().createReadSessionSettings(); |
| 74 | + } |
| 75 | + |
| 76 | + /** Returns the object with the settings used for calls to readRows. */ |
| 77 | + public ServerStreamingCallSettings<ReadRowsRequest, ReadRowsResponse> readRowsSettings() { |
| 78 | + return getTypedStubSettings().readRowsSettings(); |
| 79 | + } |
| 80 | + |
| 81 | + /** Returns the object with the settings used for calls to batchCreateReadSessionStreams. */ |
| 82 | + public UnaryCallSettings< |
| 83 | + BatchCreateReadSessionStreamsRequest, BatchCreateReadSessionStreamsResponse> |
| 84 | + batchCreateReadSessionStreamsSettings() { |
| 85 | + return getTypedStubSettings().batchCreateReadSessionStreamsSettings(); |
| 86 | + } |
| 87 | + |
| 88 | + /** Returns the object with the settings used for calls to finalizeStream. */ |
| 89 | + public UnaryCallSettings<FinalizeStreamRequest, Empty> finalizeStreamSettings() { |
| 90 | + return getTypedStubSettings().finalizeStreamSettings(); |
| 91 | + } |
| 92 | + |
| 93 | + /** Returns the object with the settings used for calls to splitReadStream. */ |
| 94 | + public UnaryCallSettings<SplitReadStreamRequest, SplitReadStreamResponse> |
| 95 | + splitReadStreamSettings() { |
| 96 | + return getTypedStubSettings().splitReadStreamSettings(); |
| 97 | + } |
| 98 | + |
| 99 | + EnhancedBigQueryStorageStubSettings getTypedStubSettings() { |
| 100 | + return (EnhancedBigQueryStorageStubSettings) getStubSettings(); |
| 101 | + } |
| 102 | + |
| 103 | + public static final BigQueryStorageSettings create(EnhancedBigQueryStorageStubSettings settings) |
| 104 | + throws IOException { |
| 105 | + return new BigQueryStorageSettings.Builder(settings.toBuilder()).build(); |
| 106 | + } |
| 107 | + |
| 108 | + /** Returns a builder for the default ExecutorProvider for this service. */ |
| 109 | + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { |
| 110 | + return EnhancedBigQueryStorageStubSettings.defaultExecutorProviderBuilder(); |
| 111 | + } |
| 112 | + |
| 113 | + /** Returns the default service endpoint. */ |
| 114 | + public static String getDefaultEndpoint() { |
| 115 | + return EnhancedBigQueryStorageStubSettings.getDefaultEndpoint(); |
| 116 | + } |
| 117 | + |
| 118 | + /** Returns the default service scopes. */ |
| 119 | + public static List<String> getDefaultServiceScopes() { |
| 120 | + return EnhancedBigQueryStorageStubSettings.getDefaultServiceScopes(); |
| 121 | + } |
| 122 | + |
| 123 | + /** Returns a builder for the default credentials for this service. */ |
| 124 | + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { |
| 125 | + return EnhancedBigQueryStorageStubSettings.defaultCredentialsProviderBuilder(); |
| 126 | + } |
| 127 | + |
| 128 | + /** Returns a builder for the default ChannelProvider for this service. */ |
| 129 | + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { |
| 130 | + return EnhancedBigQueryStorageStubSettings.defaultGrpcTransportProviderBuilder(); |
| 131 | + } |
| 132 | + |
| 133 | + public static TransportChannelProvider defaultTransportChannelProvider() { |
| 134 | + return EnhancedBigQueryStorageStubSettings.defaultTransportChannelProvider(); |
| 135 | + } |
| 136 | + |
| 137 | + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") |
| 138 | + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { |
| 139 | + return EnhancedBigQueryStorageStubSettings.defaultApiClientHeaderProviderBuilder(); |
| 140 | + } |
| 141 | + |
| 142 | + /** Returns a new builder for this class. */ |
| 143 | + public static Builder newBuilder() { |
| 144 | + return Builder.createDefault(); |
| 145 | + } |
| 146 | + |
| 147 | + /** Returns a new builder for this class. */ |
| 148 | + public static Builder newBuilder(ClientContext clientContext) { |
| 149 | + return new Builder(clientContext); |
| 150 | + } |
| 151 | + |
| 152 | + /** Returns a builder containing all the values of this settings class. */ |
| 153 | + public Builder toBuilder() { |
| 154 | + return new Builder(this); |
| 155 | + } |
| 156 | + |
| 157 | + protected BigQueryStorageSettings(Builder settingsBuilder) throws IOException { |
| 158 | + super(settingsBuilder); |
| 159 | + } |
| 160 | + |
| 161 | + /** Builder for BigQueryStorageSettings. */ |
| 162 | + public static class Builder extends ClientSettings.Builder<BigQueryStorageSettings, Builder> { |
| 163 | + protected Builder() throws IOException { |
| 164 | + this((ClientContext) null); |
| 165 | + } |
| 166 | + |
| 167 | + protected Builder(ClientContext clientContext) { |
| 168 | + super(EnhancedBigQueryStorageStubSettings.newBuilder(clientContext)); |
| 169 | + } |
| 170 | + |
| 171 | + private static Builder createDefault() { |
| 172 | + return new Builder(EnhancedBigQueryStorageStubSettings.newBuilder()); |
| 173 | + } |
| 174 | + |
| 175 | + protected Builder(BigQueryStorageSettings settings) { |
| 176 | + super(settings.getStubSettings().toBuilder()); |
| 177 | + } |
| 178 | + |
| 179 | + protected Builder(EnhancedBigQueryStorageStubSettings.Builder stubSettings) { |
| 180 | + super(stubSettings); |
| 181 | + } |
| 182 | + |
| 183 | + public EnhancedBigQueryStorageStubSettings.Builder getStubSettingsBuilder() { |
| 184 | + return ((EnhancedBigQueryStorageStubSettings.Builder) getStubSettings()); |
| 185 | + } |
| 186 | + |
| 187 | + // NEXT_MAJOR_VER: remove 'throws Exception' |
| 188 | + /** |
| 189 | + * Applies the given settings updater function to all of the unary API methods in this service. |
| 190 | + * |
| 191 | + * <p>Note: This method does not support applying settings to streaming methods. |
| 192 | + */ |
| 193 | + public Builder applyToAllUnaryMethods( |
| 194 | + ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater) throws Exception { |
| 195 | + super.applyToAllUnaryMethods( |
| 196 | + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); |
| 197 | + return this; |
| 198 | + } |
| 199 | + |
| 200 | + /** Returns the builder for the settings used for calls to createReadSession. */ |
| 201 | + public UnaryCallSettings.Builder<CreateReadSessionRequest, ReadSession> |
| 202 | + createReadSessionSettings() { |
| 203 | + return getStubSettingsBuilder().createReadSessionSettings(); |
| 204 | + } |
| 205 | + |
| 206 | + /** Returns the builder for the settings used for calls to readRows. */ |
| 207 | + public ServerStreamingCallSettings.Builder<ReadRowsRequest, ReadRowsResponse> |
| 208 | + readRowsSettings() { |
| 209 | + return getStubSettingsBuilder().readRowsSettings(); |
| 210 | + } |
| 211 | + |
| 212 | + /** Returns the builder for the settings used for calls to batchCreateReadSessionStreams. */ |
| 213 | + public UnaryCallSettings.Builder< |
| 214 | + BatchCreateReadSessionStreamsRequest, BatchCreateReadSessionStreamsResponse> |
| 215 | + batchCreateReadSessionStreamsSettings() { |
| 216 | + return getStubSettingsBuilder().batchCreateReadSessionStreamsSettings(); |
| 217 | + } |
| 218 | + |
| 219 | + /** Returns the builder for the settings used for calls to finalizeStream. */ |
| 220 | + public UnaryCallSettings.Builder<FinalizeStreamRequest, Empty> finalizeStreamSettings() { |
| 221 | + return getStubSettingsBuilder().finalizeStreamSettings(); |
| 222 | + } |
| 223 | + |
| 224 | + /** Returns the builder for the settings used for calls to splitReadStream. */ |
| 225 | + public UnaryCallSettings.Builder<SplitReadStreamRequest, SplitReadStreamResponse> |
| 226 | + splitReadStreamSettings() { |
| 227 | + return getStubSettingsBuilder().splitReadStreamSettings(); |
| 228 | + } |
| 229 | + |
| 230 | + @Override |
| 231 | + public BigQueryStorageSettings build() throws IOException { |
| 232 | + return new BigQueryStorageSettings(this); |
| 233 | + } |
| 234 | + } |
| 235 | +} |
0 commit comments