|
| 1 | +package com.google.showcase.grpcrest.v1beta1; |
| 2 | + |
| 3 | +import com.google.api.core.BetaApi; |
| 4 | +import com.google.api.gax.core.BackgroundResource; |
| 5 | +import com.google.showcase.grpcrest.v1beta1.stub.EchoEmpyStub; |
| 6 | +import com.google.showcase.grpcrest.v1beta1.stub.EchoEmpyStubSettings; |
| 7 | +import java.io.IOException; |
| 8 | +import java.util.concurrent.TimeUnit; |
| 9 | +import javax.annotation.Generated; |
| 10 | + |
| 11 | +// AUTO-GENERATED DOCUMENTATION AND CLASS. |
| 12 | +/** |
| 13 | + * This class provides the ability to make remote calls to the backing service through method calls |
| 14 | + * that map to API methods. Sample code to get started: |
| 15 | + * |
| 16 | + * <pre>{@code |
| 17 | + * // This snippet has been automatically generated for illustrative purposes only. |
| 18 | + * // It may require modifications to work in your environment. |
| 19 | + * try (EchoEmpyClient echoEmpyClient = EchoEmpyClient.create()) {} |
| 20 | + * }</pre> |
| 21 | + * |
| 22 | + * <p>Note: close() needs to be called on the EchoEmpyClient object to clean up resources such as |
| 23 | + * threads. In the example above, try-with-resources is used, which automatically calls close(). |
| 24 | + * |
| 25 | + * <p>The surface of this class includes several types of Java methods for each of the API's |
| 26 | + * methods: |
| 27 | + * |
| 28 | + * <ol> |
| 29 | + * <li>A "flattened" method. With this type of method, the fields of the request type have been |
| 30 | + * converted into function parameters. It may be the case that not all fields are available as |
| 31 | + * parameters, and not every API method will have a flattened method entry point. |
| 32 | + * <li>A "request object" method. This type of method only takes one parameter, a request object, |
| 33 | + * which must be constructed before the call. Not every API method will have a request object |
| 34 | + * method. |
| 35 | + * <li>A "callable" method. This type of method takes no parameters and returns an immutable API |
| 36 | + * callable object, which can be used to initiate calls to the service. |
| 37 | + * </ol> |
| 38 | + * |
| 39 | + * <p>See the individual methods for example code. |
| 40 | + * |
| 41 | + * <p>Many parameters require resource names to be formatted in a particular way. To assist with |
| 42 | + * these names, this class includes a format method for each type of name, and additionally a parse |
| 43 | + * method to extract the individual identifiers contained within names that are returned. |
| 44 | + * |
| 45 | + * <p>This class can be customized by passing in a custom instance of EchoEmpySettings to create(). |
| 46 | + * For example: |
| 47 | + * |
| 48 | + * <p>To customize credentials: |
| 49 | + * |
| 50 | + * <pre>{@code |
| 51 | + * // This snippet has been automatically generated for illustrative purposes only. |
| 52 | + * // It may require modifications to work in your environment. |
| 53 | + * EchoEmpySettings echoEmpySettings = |
| 54 | + * EchoEmpySettings.newBuilder() |
| 55 | + * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) |
| 56 | + * .build(); |
| 57 | + * EchoEmpyClient echoEmpyClient = EchoEmpyClient.create(echoEmpySettings); |
| 58 | + * }</pre> |
| 59 | + * |
| 60 | + * <p>To customize the endpoint: |
| 61 | + * |
| 62 | + * <pre>{@code |
| 63 | + * // This snippet has been automatically generated for illustrative purposes only. |
| 64 | + * // It may require modifications to work in your environment. |
| 65 | + * EchoEmpySettings echoEmpySettings = |
| 66 | + * EchoEmpySettings.newBuilder().setEndpoint(myEndpoint).build(); |
| 67 | + * EchoEmpyClient echoEmpyClient = EchoEmpyClient.create(echoEmpySettings); |
| 68 | + * }</pre> |
| 69 | + * |
| 70 | + * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending an receiving requests over |
| 71 | + * the wire: |
| 72 | + * |
| 73 | + * <pre>{@code |
| 74 | + * // This snippet has been automatically generated for illustrative purposes only. |
| 75 | + * // It may require modifications to work in your environment. |
| 76 | + * EchoEmpySettings echoEmpySettings = |
| 77 | + * EchoEmpySettings.newBuilder() |
| 78 | + * .setTransportChannelProvider( |
| 79 | + * EchoEmpySettings.defaultHttpJsonTransportProviderBuilder().build()) |
| 80 | + * .build(); |
| 81 | + * EchoEmpyClient echoEmpyClient = EchoEmpyClient.create(echoEmpySettings); |
| 82 | + * }</pre> |
| 83 | + * |
| 84 | + * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. |
| 85 | + */ |
| 86 | +@BetaApi |
| 87 | +@Generated("by gapic-generator-java") |
| 88 | +public class EchoEmpyClient implements BackgroundResource { |
| 89 | + private final EchoEmpySettings settings; |
| 90 | + private final EchoEmpyStub stub; |
| 91 | + |
| 92 | + /** Constructs an instance of EchoEmpyClient with default settings. */ |
| 93 | + public static final EchoEmpyClient create() throws IOException { |
| 94 | + return create(EchoEmpySettings.newBuilder().build()); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Constructs an instance of EchoEmpyClient, using the given settings. The channels are created |
| 99 | + * based on the settings passed in, or defaults for any settings that are not set. |
| 100 | + */ |
| 101 | + public static final EchoEmpyClient create(EchoEmpySettings settings) throws IOException { |
| 102 | + return new EchoEmpyClient(settings); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Constructs an instance of EchoEmpyClient, using the given stub for making calls. This is for |
| 107 | + * advanced usage - prefer using create(EchoEmpySettings). |
| 108 | + */ |
| 109 | + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") |
| 110 | + public static final EchoEmpyClient create(EchoEmpyStub stub) { |
| 111 | + return new EchoEmpyClient(stub); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Constructs an instance of EchoEmpyClient, using the given settings. This is protected so that |
| 116 | + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. |
| 117 | + */ |
| 118 | + protected EchoEmpyClient(EchoEmpySettings settings) throws IOException { |
| 119 | + this.settings = settings; |
| 120 | + this.stub = ((EchoEmpyStubSettings) settings.getStubSettings()).createStub(); |
| 121 | + } |
| 122 | + |
| 123 | + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") |
| 124 | + protected EchoEmpyClient(EchoEmpyStub stub) { |
| 125 | + this.settings = null; |
| 126 | + this.stub = stub; |
| 127 | + } |
| 128 | + |
| 129 | + public final EchoEmpySettings getSettings() { |
| 130 | + return settings; |
| 131 | + } |
| 132 | + |
| 133 | + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") |
| 134 | + public EchoEmpyStub getStub() { |
| 135 | + return stub; |
| 136 | + } |
| 137 | + |
| 138 | + @Override |
| 139 | + public final void close() { |
| 140 | + stub.close(); |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + public void shutdown() { |
| 145 | + stub.shutdown(); |
| 146 | + } |
| 147 | + |
| 148 | + @Override |
| 149 | + public boolean isShutdown() { |
| 150 | + return stub.isShutdown(); |
| 151 | + } |
| 152 | + |
| 153 | + @Override |
| 154 | + public boolean isTerminated() { |
| 155 | + return stub.isTerminated(); |
| 156 | + } |
| 157 | + |
| 158 | + @Override |
| 159 | + public void shutdownNow() { |
| 160 | + stub.shutdownNow(); |
| 161 | + } |
| 162 | + |
| 163 | + @Override |
| 164 | + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { |
| 165 | + return stub.awaitTermination(duration, unit); |
| 166 | + } |
| 167 | +} |
0 commit comments