Class OperationsClient (2.19.6)
Stay organized with collections
Save and categorize content based on your preferences.
- 2.72.1 (latest)
- 2.71.0
- 2.70.3
- 2.69.0
- 2.68.2
- 2.67.0
- 2.66.0
- 2.65.0
- 2.63.1
- 2.62.0
- 2.61.0
- 2.60.0
- 2.59.1
- 2.58.0
- 2.57.0
- 2.55.0
- 2.54.1
- 2.53.0
- 2.52.0
- 2.51.0
- 2.50.0
- 2.49.0
- 2.48.1
- 2.47.0
- 2.46.1
- 2.45.0
- 2.43.0
- 2.42.0
- 2.41.0
- 2.39.0
- 2.38.0
- 2.37.0
- 2.36.0
- 2.35.0
- 2.34.1
- 2.33.0
- 2.32.1
- 2.31.1
- 2.30.1
- 2.24.0
- 2.23.3
- 2.22.0
- 2.21.0
- 2.20.1
- 2.19.6
- 2.18.7
- 2.17.0
- 2.16.0
- 2.15.0
- 2.14.0
- 2.13.0
- 2.12.2
- 2.11.0
- 2.10.0
- 2.9.0
- 2.8.1
- 2.7.1
publicclass OperationsClientimplementsBackgroundResourceService Description: Manages long-running operations with an API service.
When an API method normally takes long time to complete, it can be designed to return
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(OperationsClientoperationsClient=OperationsClient.create()){
Stringname="name3373707";
Operationresponse=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:
To customize credentials:
OperationsSettingsoperationsSettings=
OperationsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
OperationsClientoperationsClient=OperationsClient.create(operationsSettings);
To customize the endpoint:
OperationsSettingsoperationsSettings=
OperationsSettings.newBuilder().setEndpoint(myEndpoint).build();
OperationsClientoperationsClient=OperationsClient.create(operationsSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Implements
BackgroundResourceInherited Members
Static Methods
create()
publicstaticfinalOperationsClientcreate()Constructs an instance of OperationsClient with default settings.
create(BackgroundResource stub)
publicstaticfinalOperationsClientcreate(BackgroundResourcestub)Constructs an instance of OperationsClient, using the given stub for making calls. This is for advanced usage - prefer using create(OperationsSettings).
create(OperationsSettings settings)
publicstaticfinalOperationsClientcreate(OperationsSettingssettings)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.
create(OperationsStub stub)
publicstaticfinalOperationsClientcreate(OperationsStubstub)Constructs an instance of OperationsClient, using the given stub for making calls. This is for advanced usage - prefer using create(OperationsSettings).
Constructors
OperationsClient(OperationsSettings settings)
protectedOperationsClient(OperationsSettingssettings)Constructs an instance of OperationsClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
OperationsClient(OperationsStub stub)
protectedOperationsClient(OperationsStubstub)Methods
awaitTermination(long duration, TimeUnit unit)
publicbooleanawaitTermination(longduration,TimeUnitunit)Blocks until all work has completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
cancelOperation(CancelOperationRequest request)
publicfinalvoidcancelOperation(CancelOperationRequestrequest)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 or other methods to check
whether the cancellation succeeded or whether the operation completed despite cancellation. On
successful cancellation, the operation is not deleted; instead, it becomes an operation with an
Operation.error value with a
google.rpc.Status.code of 1, corresponding to Code.CANCELLED.
Sample code:
try(OperationsClientoperationsClient=OperationsClient.create()){
CancelOperationRequestrequest=
CancelOperationRequest.newBuilder().setName("name3373707").build();
operationsClient.cancelOperation(request);
}
CancelOperationRequest The request object containing all of the parameters for the API call.
cancelOperation(String name)
publicfinalvoidcancelOperation(Stringname)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 or other methods to check
whether the cancellation succeeded or whether the operation completed despite cancellation. On
successful cancellation, the operation is not deleted; instead, it becomes an operation with an
Operation.error value with a
google.rpc.Status.code of 1, corresponding to Code.CANCELLED.
Sample code:
try(OperationsClientoperationsClient=OperationsClient.create()){
Stringname="name3373707";
operationsClient.cancelOperation(name);
}
cancelOperationCallable()
publicfinalUnaryCallable<CancelOperationRequest,Empty>cancelOperationCallable()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 or other methods to check
whether the cancellation succeeded or whether the operation completed despite cancellation. On
successful cancellation, the operation is not deleted; instead, it becomes an operation with an
Operation.error value with a
google.rpc.Status.code of 1, corresponding to Code.CANCELLED.
Sample code:
try(OperationsClientoperationsClient=OperationsClient.create()){
CancelOperationRequestrequest=
CancelOperationRequest.newBuilder().setName("name3373707").build();
ApiFuture<Empty>future=operationsClient.cancelOperationCallable().futureCall(request);
// Do something.
future.get();
}
close()
publicfinalvoidclose()deleteOperation(DeleteOperationRequest request)
publicfinalvoiddeleteOperation(DeleteOperationRequestrequest)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(OperationsClientoperationsClient=OperationsClient.create()){
DeleteOperationRequestrequest=
DeleteOperationRequest.newBuilder().setName("name3373707").build();
operationsClient.deleteOperation(request);
}
DeleteOperationRequest The request object containing all of the parameters for the API call.
deleteOperation(String name)
publicfinalvoiddeleteOperation(Stringname)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(OperationsClientoperationsClient=OperationsClient.create()){
Stringname="name3373707";
operationsClient.deleteOperation(name);
}
deleteOperationCallable()
publicfinalUnaryCallable<DeleteOperationRequest,Empty>deleteOperationCallable()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(OperationsClientoperationsClient=OperationsClient.create()){
DeleteOperationRequestrequest=
DeleteOperationRequest.newBuilder().setName("name3373707").build();
ApiFuture<Empty>future=operationsClient.deleteOperationCallable().futureCall(request);
// Do something.
future.get();
}
getOperation(GetOperationRequest request)
publicfinalOperationgetOperation(GetOperationRequestrequest)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(OperationsClientoperationsClient=OperationsClient.create()){
GetOperationRequestrequest=GetOperationRequest.newBuilder().setName("name3373707").build();
Operationresponse=operationsClient.getOperation(request);
}
getOperation(String name)
publicfinalOperationgetOperation(Stringname)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(OperationsClientoperationsClient=OperationsClient.create()){
Stringname="name3373707";
Operationresponse=operationsClient.getOperation(name);
}
getOperationCallable()
publicfinalUnaryCallable<GetOperationRequest,Operation>getOperationCallable()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(OperationsClientoperationsClient=OperationsClient.create()){
GetOperationRequestrequest=GetOperationRequest.newBuilder().setName("name3373707").build();
ApiFuture<Operation>future=operationsClient.getOperationCallable().futureCall(request);
// Do something.
Operationresponse=future.get();
}
getSettings()
publicfinalOperationsSettingsgetSettings()getStub()
publicOperationsStubgetStub()isShutdown()
publicbooleanisShutdown()Returns true if this background resource has been shut down.
isTerminated()
publicbooleanisTerminated()Returns true if all work has completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.
listOperations(ListOperationsRequest request)
publicfinalOperationsClient.ListOperationsPagedResponselistOperations(ListOperationsRequestrequest)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 allows API services to override the binding to use different
resource name schemes, such as users/*/operations. To override the binding, API services
can add a binding such as "/v1/{name=users/*}/operations" to their service configuration.
For backwards compatibility, the default name includes the operations collection id, however
overriding users must ensure the name binding is the parent resource, without the operations
collection id.
Sample code:
try(OperationsClientoperationsClient=OperationsClient.create()){
ListOperationsRequestrequest=
ListOperationsRequest.newBuilder()
.setName("name3373707")
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for(Operationelement:operationsClient.listOperations(request).iterateAll()){
// doThingsWith(element);
}
}
listOperations(String name, String filter)
publicfinalOperationsClient.ListOperationsPagedResponselistOperations(Stringname,Stringfilter)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 allows API services to override the binding to use different
resource name schemes, such as users/*/operations. To override the binding, API services
can add a binding such as "/v1/{name=users/*}/operations" to their service configuration.
For backwards compatibility, the default name includes the operations collection id, however
overriding users must ensure the name binding is the parent resource, without the operations
collection id.
Sample code:
try(OperationsClientoperationsClient=OperationsClient.create()){
Stringname="name3373707";
Stringfilter="filter-1274492040";
for(Operationelement:operationsClient.listOperations(name,filter).iterateAll()){
// doThingsWith(element);
}
}
listOperationsCallable()
publicfinalUnaryCallable<ListOperationsRequest,ListOperationsResponse>listOperationsCallable()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 allows API services to override the binding to use different
resource name schemes, such as users/*/operations. To override the binding, API services
can add a binding such as "/v1/{name=users/*}/operations" to their service configuration.
For backwards compatibility, the default name includes the operations collection id, however
overriding users must ensure the name binding is the parent resource, without the operations
collection id.
Sample code:
try(OperationsClientoperationsClient=OperationsClient.create()){
ListOperationsRequestrequest=
ListOperationsRequest.newBuilder()
.setName("name3373707")
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while(true){
ListOperationsResponseresponse=operationsClient.listOperationsCallable().call(request);
for(Operationelement:response.getResponsesList()){
// doThingsWith(element);
}
StringnextPageToken=response.getNextPageToken();
if(!Strings.isNullOrEmpty(nextPageToken)){
request=request.toBuilder().setPageToken(nextPageToken).build();
}else{
break;
}
}
}
listOperationsPagedCallable()
publicfinalUnaryCallable<ListOperationsRequest,OperationsClient.ListOperationsPagedResponse>listOperationsPagedCallable()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 allows API services to override the binding to use different
resource name schemes, such as users/*/operations. To override the binding, API services
can add a binding such as "/v1/{name=users/*}/operations" to their service configuration.
For backwards compatibility, the default name includes the operations collection id, however
overriding users must ensure the name binding is the parent resource, without the operations
collection id.
Sample code:
try(OperationsClientoperationsClient=OperationsClient.create()){
ListOperationsRequestrequest=
ListOperationsRequest.newBuilder()
.setName("name3373707")
.setFilter("filter-1274492040")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<Operation>future=
operationsClient.listOperationsPagedCallable().futureCall(request);
// Do something.
for(Operationelement:future.get().iterateAll()){
// doThingsWith(element);
}
}
shutdown()
publicvoidshutdown()Initiates an orderly shutdown in which previously submitted work is finished, but no new work will be accepted. Invocation has no additional effect if already shut down.
This method does not wait for previously submitted work to complete execution. Use awaitTermination to do that.
shutdownNow()
publicvoidshutdownNow()Attempts to stop all actively executing work and halts the processing of waiting work.
This method does not wait for actively executing work to terminate. Use awaitTermination to do that.
There are no guarantees beyond best-effort attempts to stop processing actively executing work. For example, typical implementations will cancel via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.