Class BatchControllerClient (3.1.1)

public class BatchControllerClient implements BackgroundResource

Service Description: The BatchController provides methods to manage batch workloads.

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 (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   BatchName name = BatchName.of("[PROJECT]", "[LOCATION]", "[BATCH]");
   Batch response = batchControllerClient.getBatch(name);
 }
 

Note: close() needs to be called on the BatchControllerClient 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:

  1. 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.
  2. 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.
  3. 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 BatchControllerSettings to create(). For example:

To customize credentials:


 BatchControllerSettings batchControllerSettings =
     BatchControllerSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 BatchControllerClient batchControllerClient =
     BatchControllerClient.create(batchControllerSettings);
 

To customize the endpoint:


 BatchControllerSettings batchControllerSettings =
     BatchControllerSettings.newBuilder().setEndpoint(myEndpoint).build();
 BatchControllerClient batchControllerClient =
     BatchControllerClient.create(batchControllerSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > BatchControllerClient

Implements

BackgroundResource

Static Methods

create()

public static final BatchControllerClient create()

Constructs an instance of BatchControllerClient with default settings.

Returns
TypeDescription
BatchControllerClient
Exceptions
TypeDescription
IOException

create(BatchControllerSettings settings)

public static final BatchControllerClient create(BatchControllerSettings settings)

Constructs an instance of BatchControllerClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
NameDescription
settingsBatchControllerSettings
Returns
TypeDescription
BatchControllerClient
Exceptions
TypeDescription
IOException

create(BatchControllerStub stub)

public static final BatchControllerClient create(BatchControllerStub stub)

Constructs an instance of BatchControllerClient, using the given stub for making calls. This is for advanced usage - prefer using create(BatchControllerSettings).

Parameter
NameDescription
stubBatchControllerStub
Returns
TypeDescription
BatchControllerClient

Constructors

BatchControllerClient(BatchControllerSettings settings)

protected BatchControllerClient(BatchControllerSettings settings)

Constructs an instance of BatchControllerClient, 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.

Parameter
NameDescription
settingsBatchControllerSettings

BatchControllerClient(BatchControllerStub stub)

protected BatchControllerClient(BatchControllerStub stub)
Parameter
NameDescription
stubBatchControllerStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
NameDescription
durationlong
unitTimeUnit
Returns
TypeDescription
boolean
Exceptions
TypeDescription
InterruptedException

close()

public final void close()

createBatchAsync(CreateBatchRequest request)

public final OperationFuture<Batch,BatchOperationMetadata> createBatchAsync(CreateBatchRequest request)

Creates a batch workload that executes asynchronously.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   CreateBatchRequest request =
       CreateBatchRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setBatch(Batch.newBuilder().build())
           .setBatchId("batchId-331744779")
           .setRequestId("requestId693933066")
           .build();
   Batch response = batchControllerClient.createBatchAsync(request).get();
 }
 
Parameter
NameDescription
requestCreateBatchRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
OperationFuture<Batch,BatchOperationMetadata>

createBatchAsync(LocationName parent, Batch batch, String batchId)

public final OperationFuture<Batch,BatchOperationMetadata> createBatchAsync(LocationName parent, Batch batch, String batchId)

Creates a batch workload that executes asynchronously.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   Batch batch = Batch.newBuilder().build();
   String batchId = "batchId-331744779";
   Batch response = batchControllerClient.createBatchAsync(parent, batch, batchId).get();
 }
 
Parameters
NameDescription
parentLocationName

Required. The parent resource where this batch will be created.

batchBatch

Required. The batch to create.

batchIdString

Optional. The ID to use for the batch, which will become the final component of the batch's resource name.

This value must be 4-63 characters. Valid characters are /a-z-/.

Returns
TypeDescription
OperationFuture<Batch,BatchOperationMetadata>

createBatchAsync(String parent, Batch batch, String batchId)

public final OperationFuture<Batch,BatchOperationMetadata> createBatchAsync(String parent, Batch batch, String batchId)

Creates a batch workload that executes asynchronously.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   Batch batch = Batch.newBuilder().build();
   String batchId = "batchId-331744779";
   Batch response = batchControllerClient.createBatchAsync(parent, batch, batchId).get();
 }
 
Parameters
NameDescription
parentString

Required. The parent resource where this batch will be created.

batchBatch

Required. The batch to create.

batchIdString

Optional. The ID to use for the batch, which will become the final component of the batch's resource name.

This value must be 4-63 characters. Valid characters are /a-z-/.

Returns
TypeDescription
OperationFuture<Batch,BatchOperationMetadata>

createBatchCallable()

public final UnaryCallable<CreateBatchRequest,Operation> createBatchCallable()

Creates a batch workload that executes asynchronously.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   CreateBatchRequest request =
       CreateBatchRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setBatch(Batch.newBuilder().build())
           .setBatchId("batchId-331744779")
           .setRequestId("requestId693933066")
           .build();
   ApiFuture<Operation> future = batchControllerClient.createBatchCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreateBatchRequest,Operation>

createBatchOperationCallable()

public final OperationCallable<CreateBatchRequest,Batch,BatchOperationMetadata> createBatchOperationCallable()

Creates a batch workload that executes asynchronously.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   CreateBatchRequest request =
       CreateBatchRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setBatch(Batch.newBuilder().build())
           .setBatchId("batchId-331744779")
           .setRequestId("requestId693933066")
           .build();
   OperationFuture<Batch, BatchOperationMetadata> future =
       batchControllerClient.createBatchOperationCallable().futureCall(request);
   // Do something.
   Batch response = future.get();
 }
 
Returns
TypeDescription
OperationCallable<CreateBatchRequest,Batch,BatchOperationMetadata>

deleteBatch(BatchName name)

public final void deleteBatch(BatchName name)

Deletes the batch workload resource. If the batch is not in terminal state, the delete fails and the response returns FAILED_PRECONDITION.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   BatchName name = BatchName.of("[PROJECT]", "[LOCATION]", "[BATCH]");
   batchControllerClient.deleteBatch(name);
 }
 
Parameter
NameDescription
nameBatchName

Required. The name of the batch resource to delete.

deleteBatch(DeleteBatchRequest request)

public final void deleteBatch(DeleteBatchRequest request)

Deletes the batch workload resource. If the batch is not in terminal state, the delete fails and the response returns FAILED_PRECONDITION.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   DeleteBatchRequest request =
       DeleteBatchRequest.newBuilder()
           .setName(BatchName.of("[PROJECT]", "[LOCATION]", "[BATCH]").toString())
           .build();
   batchControllerClient.deleteBatch(request);
 }
 
Parameter
NameDescription
requestDeleteBatchRequest

The request object containing all of the parameters for the API call.

deleteBatch(String name)

public final void deleteBatch(String name)

Deletes the batch workload resource. If the batch is not in terminal state, the delete fails and the response returns FAILED_PRECONDITION.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   String name = BatchName.of("[PROJECT]", "[LOCATION]", "[BATCH]").toString();
   batchControllerClient.deleteBatch(name);
 }
 
Parameter
NameDescription
nameString

Required. The name of the batch resource to delete.

deleteBatchCallable()

public final UnaryCallable<DeleteBatchRequest,Empty> deleteBatchCallable()

Deletes the batch workload resource. If the batch is not in terminal state, the delete fails and the response returns FAILED_PRECONDITION.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   DeleteBatchRequest request =
       DeleteBatchRequest.newBuilder()
           .setName(BatchName.of("[PROJECT]", "[LOCATION]", "[BATCH]").toString())
           .build();
   ApiFuture<Empty> future = batchControllerClient.deleteBatchCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<DeleteBatchRequest,Empty>

getBatch(BatchName name)

public final Batch getBatch(BatchName name)

Gets the batch workload resource representation.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   BatchName name = BatchName.of("[PROJECT]", "[LOCATION]", "[BATCH]");
   Batch response = batchControllerClient.getBatch(name);
 }
 
Parameter
NameDescription
nameBatchName

Required. The name of the batch to retrieve.

Returns
TypeDescription
Batch

getBatch(GetBatchRequest request)

public final Batch getBatch(GetBatchRequest request)

Gets the batch workload resource representation.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   GetBatchRequest request =
       GetBatchRequest.newBuilder()
           .setName(BatchName.of("[PROJECT]", "[LOCATION]", "[BATCH]").toString())
           .build();
   Batch response = batchControllerClient.getBatch(request);
 }
 
Parameter
NameDescription
requestGetBatchRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Batch

getBatch(String name)

public final Batch getBatch(String name)

Gets the batch workload resource representation.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   String name = BatchName.of("[PROJECT]", "[LOCATION]", "[BATCH]").toString();
   Batch response = batchControllerClient.getBatch(name);
 }
 
Parameter
NameDescription
nameString

Required. The name of the batch to retrieve.

Returns
TypeDescription
Batch

getBatchCallable()

public final UnaryCallable<GetBatchRequest,Batch> getBatchCallable()

Gets the batch workload resource representation.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   GetBatchRequest request =
       GetBatchRequest.newBuilder()
           .setName(BatchName.of("[PROJECT]", "[LOCATION]", "[BATCH]").toString())
           .build();
   ApiFuture<Batch> future = batchControllerClient.getBatchCallable().futureCall(request);
   // Do something.
   Batch response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetBatchRequest,Batch>

getOperationsClient()

public final OperationsClient getOperationsClient()

Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.

Returns
TypeDescription
OperationsClient

getSettings()

public final BatchControllerSettings getSettings()
Returns
TypeDescription
BatchControllerSettings

getStub()

public BatchControllerStub getStub()
Returns
TypeDescription
BatchControllerStub

isShutdown()

public boolean isShutdown()
Returns
TypeDescription
boolean

isTerminated()

public boolean isTerminated()
Returns
TypeDescription
boolean

listBatches(ListBatchesRequest request)

public final BatchControllerClient.ListBatchesPagedResponse listBatches(ListBatchesRequest request)

Lists batch workloads.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   ListBatchesRequest request =
       ListBatchesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (Batch element : batchControllerClient.listBatches(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListBatchesRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
BatchControllerClient.ListBatchesPagedResponse

listBatches(LocationName parent)

public final BatchControllerClient.ListBatchesPagedResponse listBatches(LocationName parent)

Lists batch workloads.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   for (Batch element : batchControllerClient.listBatches(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentLocationName

Required. The parent, which owns this collection of batches.

Returns
TypeDescription
BatchControllerClient.ListBatchesPagedResponse

listBatches(String parent)

public final BatchControllerClient.ListBatchesPagedResponse listBatches(String parent)

Lists batch workloads.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   for (Batch element : batchControllerClient.listBatches(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. The parent, which owns this collection of batches.

Returns
TypeDescription
BatchControllerClient.ListBatchesPagedResponse

listBatchesCallable()

public final UnaryCallable<ListBatchesRequest,ListBatchesResponse> listBatchesCallable()

Lists batch workloads.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   ListBatchesRequest request =
       ListBatchesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     ListBatchesResponse response = batchControllerClient.listBatchesCallable().call(request);
     for (Batch element : response.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListBatchesRequest,ListBatchesResponse>

listBatchesPagedCallable()

public final UnaryCallable<ListBatchesRequest,BatchControllerClient.ListBatchesPagedResponse> listBatchesPagedCallable()

Lists batch workloads.

Sample code:


 try (BatchControllerClient batchControllerClient = BatchControllerClient.create()) {
   ListBatchesRequest request =
       ListBatchesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<Batch> future =
       batchControllerClient.listBatchesPagedCallable().futureCall(request);
   // Do something.
   for (Batch element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListBatchesRequest,ListBatchesPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()