nl.topicus.jdbc.shaded.com.google.longrunning.OperationsClient Maven / Gradle / Ivy
Show all versions of spanner-jdbc Show documentation
/*
* Copyright 2017, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package nl.topicus.jdbc.shaded.com.google.longrunning;
import static nl.topicus.jdbc.shaded.com.google.longrunning.PagedResponseWrappers.ListOperationsPagedResponse;
import nl.topicus.jdbc.shaded.com.google.api.core.BetaApi;
import nl.topicus.jdbc.shaded.com.google.api.gax.core.BackgroundResource;
import nl.topicus.jdbc.shaded.com.google.api.gax.rpc.UnaryCallable;
import nl.topicus.jdbc.shaded.com.google.longrunning.stub.OperationsStub;
import nl.topicus.jdbc.shaded.com.google.protobuf.Empty;
import java.nl.topicus.jdbc.shaded.io.IOException;
import java.util.concurrent.TimeUnit;
import nl.topicus.jdbc.shaded.javax.annotation.Generated;
// AUTO-GENERATED DOCUMENTATION AND SERVICE
/**
* Service Description: Manages long-running operations with an API service.
*
* When an API method normally takes long time to nl.topicus.jdbc.shaded.com.lete, it can be designed to return
* [Operation][google.longrunning.Operation] to the client, and the client can use this interface to
* receive the real response asynchronously by polling the operation resource, or pass the operation
* resource to another API (such as Google Cloud Pub/Sub API) to receive the response. Any API
* service that returns long-running operations should implement the `Operations` interface so
* developers can have a consistent client experience.
*
*
This class provides the ability to make remote calls to the backing service through method
* calls that map to API methods. Sample code to get started:
*
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* Operation response = operationsClient.getOperation(name);
* }
*
*
*
* Note: close() needs to be called on the operationsClient object to clean up resources such as
* threads. In the example above, try-with-resources is used, which automatically calls close().
*
*
The surface of this class includes several types of Java methods for each of the API's
* methods:
*
*
* - A "flattened" method. With this type of method, the fields of the request type have been
* converted into function parameters. It may be the case that not all fields are available as
* parameters, and not every API method will have a flattened method entry point.
*
- A "request object" method. This type of method only takes one parameter, a request object,
* which must be constructed before the call. Not every API method will have a request object
* method.
*
- A "callable" method. This type of method takes no parameters and returns an immutable API
* callable object, which can be used to initiate calls to the service.
*
*
* See the individual methods for example code.
*
*
Many parameters require resource names to be formatted in a particular way. To assist with
* these names, this class includes a format method for each type of name, and additionally a parse
* method to extract the individual identifiers contained within names that are returned.
*
*
This class can be customized by passing in a custom instance of OperationsSettings to
* create(). For example:
*
*
*
* OperationsSettings operationsSettings =
* OperationsSettings.defaultBuilder()
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
* .build();
* OperationsClient operationsClient =
* OperationsClient.create(operationsSettings);
*
*
*/
@Generated("by GAPIC v0.0.5")
@BetaApi
public class OperationsClient implements BackgroundResource {
private final OperationsSettings settings;
private final OperationsStub stub;
/**
* Constructs an instance of OperationsClient, using the given settings. The channels are created
* based on the settings passed in, or defaults for any settings that are not set.
*/
public static final OperationsClient create(OperationsSettings settings) throws IOException {
return new OperationsClient(settings);
}
/**
* Constructs an instance of OperationsClient, using the given stub for making calls. This is for
* advanced usage - prefer to use OperationsSettings}.
*/
public static final OperationsClient create(OperationsStub stub) {
return new OperationsClient(stub);
}
/**
* Constructs an instance of OperationsClient, using the given settings. This is protected so that
* it easy to make a subclass, but otherwise, the static factory methods should be preferred.
*/
protected OperationsClient(OperationsSettings settings) throws IOException {
this.settings = settings;
this.stub = settings.createStub();
}
protected OperationsClient(OperationsStub stub) {
this.settings = null;
this.stub = stub;
}
public final OperationsSettings getSettings() {
return settings;
}
public OperationsStub getStub() {
return stub;
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Gets the latest state of a long-running operation. Clients can use this method to poll the
* operation result at intervals as recommended by the API service.
*
* Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* Operation response = operationsClient.getOperation(name);
* }
*
*
* @param name The name of the operation resource.
* @throws nl.topicus.jdbc.shaded.com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Operation getOperation(String name) {
GetOperationRequest request = GetOperationRequest.newBuilder().setName(name).build();
return getOperation(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Gets the latest state of a long-running operation. Clients can use this method to poll the
* operation result at intervals as recommended by the API service.
*
* Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* GetOperationRequest request = GetOperationRequest.newBuilder()
* .setName(name)
* .build();
* Operation response = operationsClient.getOperation(request);
* }
*
*
* @param request The request object containing all of the parameters for the API call.
* @throws nl.topicus.jdbc.shaded.com.google.api.gax.rpc.ApiException if the remote call fails
*/
private final Operation getOperation(GetOperationRequest request) {
return getOperationCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Gets the latest state of a long-running operation. Clients can use this method to poll the
* operation result at intervals as recommended by the API service.
*
* Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* GetOperationRequest request = GetOperationRequest.newBuilder()
* .setName(name)
* .build();
* ApiFuture<Operation> future = operationsClient.getOperationCallable().futureCall(request);
* // Do something
* Operation response = future.get();
* }
*
*/
public final UnaryCallable getOperationCallable() {
return stub.getOperationCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Lists operations that match the specified filter in the request. If the server doesn't support
* this method, it returns `UNIMPLEMENTED`.
*
* NOTE: the `name` binding below allows API services to override the binding to use different
* resource name schemes, such as `users/*/operations`.
*
*
Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* String filter = "";
* for (Operation element : operationsClient.listOperations(name, filter).iterateAll()) {
* // doThingsWith(element);
* }
* }
*
*
* @param name The name of the operation collection.
* @param filter The standard list filter.
* @throws nl.topicus.jdbc.shaded.com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListOperationsPagedResponse listOperations(String name, String filter) {
ListOperationsRequest request =
ListOperationsRequest.newBuilder().setName(name).setFilter(filter).build();
return listOperations(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Lists operations that match the specified filter in the request. If the server doesn't support
* this method, it returns `UNIMPLEMENTED`.
*
* NOTE: the `name` binding below allows API services to override the binding to use different
* resource name schemes, such as `users/*/operations`.
*
*
Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* String filter = "";
* ListOperationsRequest request = ListOperationsRequest.newBuilder()
* .setName(name)
* .setFilter(filter)
* .build();
* for (Operation element : operationsClient.listOperations(request).iterateAll()) {
* // doThingsWith(element);
* }
* }
*
*
* @param request The request object containing all of the parameters for the API call.
* @throws nl.topicus.jdbc.shaded.com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListOperationsPagedResponse listOperations(ListOperationsRequest request) {
return listOperationsPagedCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Lists operations that match the specified filter in the request. If the server doesn't support
* this method, it returns `UNIMPLEMENTED`.
*
* NOTE: the `name` binding below allows API services to override the binding to use different
* resource name schemes, such as `users/*/operations`.
*
*
Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* String filter = "";
* ListOperationsRequest request = ListOperationsRequest.newBuilder()
* .setName(name)
* .setFilter(filter)
* .build();
* ApiFuture<ListOperationsPagedResponse> future = operationsClient.listOperationsPagedCallable().futureCall(request);
* // Do something
* for (Operation element : future.get().iterateAll()) {
* // doThingsWith(element);
* }
* }
*
*/
public final UnaryCallable
listOperationsPagedCallable() {
return stub.listOperationsPagedCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Lists operations that match the specified filter in the request. If the server doesn't support
* this method, it returns `UNIMPLEMENTED`.
*
* NOTE: the `name` binding below allows API services to override the binding to use different
* resource name schemes, such as `users/*/operations`.
*
*
Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* String filter = "";
* ListOperationsRequest request = ListOperationsRequest.newBuilder()
* .setName(name)
* .setFilter(filter)
* .build();
* while (true) {
* ListOperationsResponse response = operationsClient.listOperationsCallable().call(request);
* for (Operation element : response.getOperationsList()) {
* // doThingsWith(element);
* }
* String nextPageToken = response.getNextPageToken();
* if (!Strings.isNullOrEmpty(nextPageToken)) {
* request = request.toBuilder().setPageToken(nextPageToken).build();
* } else {
* break;
* }
* }
* }
*
*/
public final UnaryCallable
listOperationsCallable() {
return stub.listOperationsCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Starts asynchronous cancellation on a long-running operation. The server makes a best effort to
* cancel the operation, but success is not guaranteed. If the server doesn't support this method,
* it returns `google.rpc.Code.UNIMPLEMENTED`. Clients can use
* [Operations.GetOperation][google.longrunning.Operations.GetOperation] or other methods to check
* whether the cancellation succeeded or whether the operation nl.topicus.jdbc.shaded.com.leted despite cancellation. On
* successful cancellation, the operation is not deleted; instead, it becomes an operation with an
* [Operation.error][google.longrunning.Operation.error] value with a
* [google.rpc.Status.code][google.rpc.Status.code] of 1, corresponding to `Code.CANCELLED`.
*
* Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* operationsClient.cancelOperation(name);
* }
*
*
* @param name The name of the operation resource to be cancelled.
* @throws nl.topicus.jdbc.shaded.com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void cancelOperation(String name) {
CancelOperationRequest request = CancelOperationRequest.newBuilder().setName(name).build();
cancelOperation(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Starts asynchronous cancellation on a long-running operation. The server makes a best effort to
* cancel the operation, but success is not guaranteed. If the server doesn't support this method,
* it returns `google.rpc.Code.UNIMPLEMENTED`. Clients can use
* [Operations.GetOperation][google.longrunning.Operations.GetOperation] or other methods to check
* whether the cancellation succeeded or whether the operation nl.topicus.jdbc.shaded.com.leted despite cancellation. On
* successful cancellation, the operation is not deleted; instead, it becomes an operation with an
* [Operation.error][google.longrunning.Operation.error] value with a
* [google.rpc.Status.code][google.rpc.Status.code] of 1, corresponding to `Code.CANCELLED`.
*
* Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* CancelOperationRequest request = CancelOperationRequest.newBuilder()
* .setName(name)
* .build();
* operationsClient.cancelOperation(request);
* }
*
*
* @param request The request object containing all of the parameters for the API call.
* @throws nl.topicus.jdbc.shaded.com.google.api.gax.rpc.ApiException if the remote call fails
*/
private final void cancelOperation(CancelOperationRequest request) {
cancelOperationCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Starts asynchronous cancellation on a long-running operation. The server makes a best effort to
* cancel the operation, but success is not guaranteed. If the server doesn't support this method,
* it returns `google.rpc.Code.UNIMPLEMENTED`. Clients can use
* [Operations.GetOperation][google.longrunning.Operations.GetOperation] or other methods to check
* whether the cancellation succeeded or whether the operation nl.topicus.jdbc.shaded.com.leted despite cancellation. On
* successful cancellation, the operation is not deleted; instead, it becomes an operation with an
* [Operation.error][google.longrunning.Operation.error] value with a
* [google.rpc.Status.code][google.rpc.Status.code] of 1, corresponding to `Code.CANCELLED`.
*
* Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* CancelOperationRequest request = CancelOperationRequest.newBuilder()
* .setName(name)
* .build();
* ApiFuture<Void> future = operationsClient.cancelOperationCallable().futureCall(request);
* // Do something
* future.get();
* }
*
*/
public final UnaryCallable cancelOperationCallable() {
return stub.cancelOperationCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Deletes a long-running operation. This method indicates that the client is no longer interested
* in the operation result. It does not cancel the operation. If the server doesn't support this
* method, it returns `google.rpc.Code.UNIMPLEMENTED`.
*
* Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* operationsClient.deleteOperation(name);
* }
*
*
* @param name The name of the operation resource to be deleted.
* @throws nl.topicus.jdbc.shaded.com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void deleteOperation(String name) {
DeleteOperationRequest request = DeleteOperationRequest.newBuilder().setName(name).build();
deleteOperation(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Deletes a long-running operation. This method indicates that the client is no longer interested
* in the operation result. It does not cancel the operation. If the server doesn't support this
* method, it returns `google.rpc.Code.UNIMPLEMENTED`.
*
* Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* DeleteOperationRequest request = DeleteOperationRequest.newBuilder()
* .setName(name)
* .build();
* operationsClient.deleteOperation(request);
* }
*
*
* @param request The request object containing all of the parameters for the API call.
* @throws nl.topicus.jdbc.shaded.com.google.api.gax.rpc.ApiException if the remote call fails
*/
private final void deleteOperation(DeleteOperationRequest request) {
deleteOperationCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Deletes a long-running operation. This method indicates that the client is no longer interested
* in the operation result. It does not cancel the operation. If the server doesn't support this
* method, it returns `google.rpc.Code.UNIMPLEMENTED`.
*
* Sample code:
*
*
* try (OperationsClient operationsClient = OperationsClient.create()) {
* String name = "";
* DeleteOperationRequest request = DeleteOperationRequest.newBuilder()
* .setName(name)
* .build();
* ApiFuture<Void> future = operationsClient.deleteOperationCallable().futureCall(request);
* // Do something
* future.get();
* }
*
*/
public final UnaryCallable deleteOperationCallable() {
return stub.deleteOperationCallable();
}
@Override
public final void close() throws Exception {
stub.close();
}
@Override
public void shutdown() {
stub.shutdown();
}
@Override
public boolean isShutdown() {
return stub.isShutdown();
}
@Override
public boolean isTerminated() {
return stub.isTerminated();
}
@Override
public void shutdownNow() {
stub.shutdownNow();
}
@Override
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
return stub.awaitTermination(duration, unit);
}
}