|
| 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.bigtable.admin.v2; |
| 17 | + |
| 18 | +import com.google.bigtable.admin.v2.ProjectName; |
| 19 | +import com.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStubSettings; |
| 20 | +import com.google.common.base.Preconditions; |
| 21 | +import com.google.common.base.Verify; |
| 22 | +import java.io.IOException; |
| 23 | +import javax.annotation.Nonnull; |
| 24 | +import javax.annotation.Nullable; |
| 25 | + |
| 26 | +/** |
| 27 | + * Settings class to configure an instance of {@link BigtableInstanceAdminClient}. |
| 28 | + * |
| 29 | + * <p>It must be configured with a {@link ProjectName} and can be used to change default RPC settings. |
| 30 | + * |
| 31 | + * <p>Example usage: |
| 32 | + * |
| 33 | + * <pre>{@code |
| 34 | + * BigtableInstanceAdminSettings.Builder settingsBuilder = BigtableInstanceAdminSettings.newBuilder() |
| 35 | + * .setProjectName(ProjectName.of("my-project")); |
| 36 | + * |
| 37 | + * settingsBuilder.stubSettings().createInstanceSettings() |
| 38 | + * .setRetrySettings( |
| 39 | + * RetrySettings.newBuilder() |
| 40 | + * .setTotalTimeout(Duration.ofMinutes(15)) |
| 41 | + * .build()); |
| 42 | + * |
| 43 | + * BigtableInstanceAdminSettings settings = settingsBuilder.build(); |
| 44 | + * }</pre> |
| 45 | + */ |
| 46 | +public class BigtableInstanceAdminSettings { |
| 47 | + private final ProjectName projectName; |
| 48 | + private final BigtableInstanceAdminStubSettings stubSettings; |
| 49 | + |
| 50 | + private BigtableInstanceAdminSettings(Builder builder) throws IOException { |
| 51 | + Preconditions.checkNotNull(builder.projectName, "ProjectName must be set"); |
| 52 | + Verify.verifyNotNull(builder.stubSettings, "stubSettings should never be null"); |
| 53 | + |
| 54 | + this.projectName = builder.projectName; |
| 55 | + this.stubSettings = builder.stubSettings.build(); |
| 56 | + } |
| 57 | + |
| 58 | + /** Gets the anme of the project whose instances the client will manager. */ |
| 59 | + @Nonnull |
| 60 | + public ProjectName getProjectName() { |
| 61 | + return projectName; |
| 62 | + } |
| 63 | + |
| 64 | + /** Gets the underlying RPC settings. */ |
| 65 | + @Nonnull |
| 66 | + public BigtableInstanceAdminStubSettings getStubSettings() { |
| 67 | + return stubSettings; |
| 68 | + } |
| 69 | + |
| 70 | + /** Returns a builder containing all the values of this settings class. */ |
| 71 | + public Builder toBuilder() { |
| 72 | + return new Builder(this); |
| 73 | + } |
| 74 | + |
| 75 | + /** Returns a new builder for this class. */ |
| 76 | + public static Builder newBuilder() { |
| 77 | + return new Builder(); |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | + /** Builder for BigtableInstanceAdminSettings. */ |
| 82 | + public static final class Builder { |
| 83 | + @Nullable |
| 84 | + private ProjectName projectName; |
| 85 | + private final BigtableInstanceAdminStubSettings.Builder stubSettings; |
| 86 | + |
| 87 | + private Builder() { |
| 88 | + stubSettings = BigtableInstanceAdminStubSettings.newBuilder(); |
| 89 | + } |
| 90 | + |
| 91 | + private Builder(BigtableInstanceAdminSettings settings) { |
| 92 | + this.projectName = settings.projectName; |
| 93 | + this.stubSettings = settings.stubSettings.toBuilder(); |
| 94 | + } |
| 95 | + |
| 96 | + /** Sets the name of instance whose tables the client will manage. */ |
| 97 | + public Builder setProjectName(@Nonnull ProjectName projectName) { |
| 98 | + Preconditions.checkNotNull(projectName); |
| 99 | + this.projectName = projectName; |
| 100 | + return this; |
| 101 | + } |
| 102 | + |
| 103 | + /** Gets the name of the project whose instances the client will manage. */ |
| 104 | + @Nullable |
| 105 | + public ProjectName getProjectName() { |
| 106 | + return projectName; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Returns the builder for the settings used for all RPCs. |
| 111 | + * |
| 112 | + * <p>This is meant for advanced usage. The default RPC settings are set to their recommended |
| 113 | + * values. |
| 114 | + */ |
| 115 | + public BigtableInstanceAdminStubSettings.Builder stubSettings() { |
| 116 | + return stubSettings; |
| 117 | + } |
| 118 | + |
| 119 | + /** Builds an instance of the settings. */ |
| 120 | + public BigtableInstanceAdminSettings build() throws IOException { |
| 121 | + return new BigtableInstanceAdminSettings(this); |
| 122 | + } |
| 123 | + } |
| 124 | +} |
0 commit comments