Class StorageTransferServiceClient (1.0.4)

public class StorageTransferServiceClient implements BackgroundResource

Service Description: Storage Transfer Service and its protos. Transfers data between between Google Cloud Storage buckets or from a data source external to Google to a Cloud Storage bucket.

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 (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.GetGoogleServiceAccountRequest request =
       TransferProto.GetGoogleServiceAccountRequest.newBuilder()
           .setProjectId("projectId-894832108")
           .build();
   TransferTypes.GoogleServiceAccount response =
       storageTransferServiceClient.getGoogleServiceAccount(request);
 }
 

Note: close() needs to be called on the StorageTransferServiceClient 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 StorageTransferServiceSettings to create(). For example:

To customize credentials:


 StorageTransferServiceSettings storageTransferServiceSettings =
     StorageTransferServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create(storageTransferServiceSettings);
 

To customize the endpoint:


 StorageTransferServiceSettings storageTransferServiceSettings =
     StorageTransferServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create(storageTransferServiceSettings);
 

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

Inheritance

java.lang.Object > StorageTransferServiceClient

Implements

BackgroundResource

Static Methods

create()

public static final StorageTransferServiceClient create()

Constructs an instance of StorageTransferServiceClient with default settings.

Returns
TypeDescription
StorageTransferServiceClient
Exceptions
TypeDescription
IOException

create(StorageTransferServiceSettings settings)

public static final StorageTransferServiceClient create(StorageTransferServiceSettings settings)

Constructs an instance of StorageTransferServiceClient, 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
settingsStorageTransferServiceSettings
Returns
TypeDescription
StorageTransferServiceClient
Exceptions
TypeDescription
IOException

create(StorageTransferServiceStub stub)

public static final StorageTransferServiceClient create(StorageTransferServiceStub stub)

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

Parameter
NameDescription
stubStorageTransferServiceStub
Returns
TypeDescription
StorageTransferServiceClient

Constructors

StorageTransferServiceClient(StorageTransferServiceSettings settings)

protected StorageTransferServiceClient(StorageTransferServiceSettings settings)

Constructs an instance of StorageTransferServiceClient, 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
settingsStorageTransferServiceSettings

StorageTransferServiceClient(StorageTransferServiceStub stub)

protected StorageTransferServiceClient(StorageTransferServiceStub stub)
Parameter
NameDescription
stubStorageTransferServiceStub

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()

createTransferJob(TransferProto.CreateTransferJobRequest request)

public final TransferTypes.TransferJob createTransferJob(TransferProto.CreateTransferJobRequest request)

Creates a transfer job that runs periodically.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.CreateTransferJobRequest request =
       TransferProto.CreateTransferJobRequest.newBuilder()
           .setTransferJob(TransferTypes.TransferJob.newBuilder().build())
           .build();
   TransferTypes.TransferJob response = storageTransferServiceClient.createTransferJob(request);
 }
 
Parameter
NameDescription
requestTransferProto.CreateTransferJobRequest

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

Returns
TypeDescription
TransferTypes.TransferJob

createTransferJobCallable()

public final UnaryCallable<TransferProto.CreateTransferJobRequest,TransferTypes.TransferJob> createTransferJobCallable()

Creates a transfer job that runs periodically.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.CreateTransferJobRequest request =
       TransferProto.CreateTransferJobRequest.newBuilder()
           .setTransferJob(TransferTypes.TransferJob.newBuilder().build())
           .build();
   ApiFuture<TransferTypes.TransferJob> future =
       storageTransferServiceClient.createTransferJobCallable().futureCall(request);
   // Do something.
   TransferTypes.TransferJob response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreateTransferJobRequest,TransferJob>

getGoogleServiceAccount(TransferProto.GetGoogleServiceAccountRequest request)

public final TransferTypes.GoogleServiceAccount getGoogleServiceAccount(TransferProto.GetGoogleServiceAccountRequest request)

Returns the Google service account that is used by Storage Transfer Service to access buckets in the project where transfers run or in other projects. Each Google service account is associated with one Google Cloud Platform Console project. Users should add this service account to the Google Cloud Storage bucket ACLs to grant access to Storage Transfer Service. This service account is created and owned by Storage Transfer Service and can only be used by Storage Transfer Service.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.GetGoogleServiceAccountRequest request =
       TransferProto.GetGoogleServiceAccountRequest.newBuilder()
           .setProjectId("projectId-894832108")
           .build();
   TransferTypes.GoogleServiceAccount response =
       storageTransferServiceClient.getGoogleServiceAccount(request);
 }
 
Parameter
NameDescription
requestTransferProto.GetGoogleServiceAccountRequest

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

Returns
TypeDescription
TransferTypes.GoogleServiceAccount

getGoogleServiceAccountCallable()

public final UnaryCallable<TransferProto.GetGoogleServiceAccountRequest,TransferTypes.GoogleServiceAccount> getGoogleServiceAccountCallable()

Returns the Google service account that is used by Storage Transfer Service to access buckets in the project where transfers run or in other projects. Each Google service account is associated with one Google Cloud Platform Console project. Users should add this service account to the Google Cloud Storage bucket ACLs to grant access to Storage Transfer Service. This service account is created and owned by Storage Transfer Service and can only be used by Storage Transfer Service.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.GetGoogleServiceAccountRequest request =
       TransferProto.GetGoogleServiceAccountRequest.newBuilder()
           .setProjectId("projectId-894832108")
           .build();
   ApiFuture<TransferTypes.GoogleServiceAccount> future =
       storageTransferServiceClient.getGoogleServiceAccountCallable().futureCall(request);
   // Do something.
   TransferTypes.GoogleServiceAccount response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetGoogleServiceAccountRequest,GoogleServiceAccount>

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 StorageTransferServiceSettings getSettings()
Returns
TypeDescription
StorageTransferServiceSettings

getStub()

public StorageTransferServiceStub getStub()
Returns
TypeDescription
StorageTransferServiceStub

getTransferJob(TransferProto.GetTransferJobRequest request)

public final TransferTypes.TransferJob getTransferJob(TransferProto.GetTransferJobRequest request)

Gets a transfer job.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.GetTransferJobRequest request =
       TransferProto.GetTransferJobRequest.newBuilder()
           .setJobName("jobName-1438096408")
           .setProjectId("projectId-894832108")
           .build();
   TransferTypes.TransferJob response = storageTransferServiceClient.getTransferJob(request);
 }
 
Parameter
NameDescription
requestTransferProto.GetTransferJobRequest

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

Returns
TypeDescription
TransferTypes.TransferJob

getTransferJobCallable()

public final UnaryCallable<TransferProto.GetTransferJobRequest,TransferTypes.TransferJob> getTransferJobCallable()

Gets a transfer job.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.GetTransferJobRequest request =
       TransferProto.GetTransferJobRequest.newBuilder()
           .setJobName("jobName-1438096408")
           .setProjectId("projectId-894832108")
           .build();
   ApiFuture<TransferTypes.TransferJob> future =
       storageTransferServiceClient.getTransferJobCallable().futureCall(request);
   // Do something.
   TransferTypes.TransferJob response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetTransferJobRequest,TransferJob>

isShutdown()

public boolean isShutdown()
Returns
TypeDescription
boolean

isTerminated()

public boolean isTerminated()
Returns
TypeDescription
boolean

listTransferJobs(TransferProto.ListTransferJobsRequest request)

public final StorageTransferServiceClient.ListTransferJobsPagedResponse listTransferJobs(TransferProto.ListTransferJobsRequest request)

Lists transfer jobs.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.ListTransferJobsRequest request =
       TransferProto.ListTransferJobsRequest.newBuilder()
           .setFilter("filter-1274492040")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (TransferTypes.TransferJob element :
       storageTransferServiceClient.listTransferJobs(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestTransferProto.ListTransferJobsRequest

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

Returns
TypeDescription
StorageTransferServiceClient.ListTransferJobsPagedResponse

listTransferJobsCallable()

public final UnaryCallable<TransferProto.ListTransferJobsRequest,TransferProto.ListTransferJobsResponse> listTransferJobsCallable()

Lists transfer jobs.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.ListTransferJobsRequest request =
       TransferProto.ListTransferJobsRequest.newBuilder()
           .setFilter("filter-1274492040")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     TransferProto.ListTransferJobsResponse response =
         storageTransferServiceClient.listTransferJobsCallable().call(request);
     for (TransferTypes.TransferJob element : response.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListTransferJobsRequest,ListTransferJobsResponse>

listTransferJobsPagedCallable()

public final UnaryCallable<TransferProto.ListTransferJobsRequest,StorageTransferServiceClient.ListTransferJobsPagedResponse> listTransferJobsPagedCallable()

Lists transfer jobs.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.ListTransferJobsRequest request =
       TransferProto.ListTransferJobsRequest.newBuilder()
           .setFilter("filter-1274492040")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<TransferTypes.TransferJob> future =
       storageTransferServiceClient.listTransferJobsPagedCallable().futureCall(request);
   // Do something.
   for (TransferTypes.TransferJob element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListTransferJobsRequest,ListTransferJobsPagedResponse>

pauseTransferOperation(TransferProto.PauseTransferOperationRequest request)

public final void pauseTransferOperation(TransferProto.PauseTransferOperationRequest request)

Pauses a transfer operation.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.PauseTransferOperationRequest request =
       TransferProto.PauseTransferOperationRequest.newBuilder().setName("name3373707").build();
   storageTransferServiceClient.pauseTransferOperation(request);
 }
 
Parameter
NameDescription
requestTransferProto.PauseTransferOperationRequest

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

pauseTransferOperationCallable()

public final UnaryCallable<TransferProto.PauseTransferOperationRequest,Empty> pauseTransferOperationCallable()

Pauses a transfer operation.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.PauseTransferOperationRequest request =
       TransferProto.PauseTransferOperationRequest.newBuilder().setName("name3373707").build();
   ApiFuture<Empty> future =
       storageTransferServiceClient.pauseTransferOperationCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<PauseTransferOperationRequest,Empty>

resumeTransferOperation(TransferProto.ResumeTransferOperationRequest request)

public final void resumeTransferOperation(TransferProto.ResumeTransferOperationRequest request)

Resumes a transfer operation that is paused.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.ResumeTransferOperationRequest request =
       TransferProto.ResumeTransferOperationRequest.newBuilder().setName("name3373707").build();
   storageTransferServiceClient.resumeTransferOperation(request);
 }
 
Parameter
NameDescription
requestTransferProto.ResumeTransferOperationRequest

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

resumeTransferOperationCallable()

public final UnaryCallable<TransferProto.ResumeTransferOperationRequest,Empty> resumeTransferOperationCallable()

Resumes a transfer operation that is paused.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.ResumeTransferOperationRequest request =
       TransferProto.ResumeTransferOperationRequest.newBuilder().setName("name3373707").build();
   ApiFuture<Empty> future =
       storageTransferServiceClient.resumeTransferOperationCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<ResumeTransferOperationRequest,Empty>

runTransferJobAsync(TransferProto.RunTransferJobRequest request)

public final OperationFuture<Empty,TransferTypes.TransferOperation> runTransferJobAsync(TransferProto.RunTransferJobRequest request)

Attempts to start a new TransferOperation for the current TransferJob. A TransferJob has a maximum of one active TransferOperation. If this method is called while a TransferOperation is active, an error wil be returned.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.RunTransferJobRequest request =
       TransferProto.RunTransferJobRequest.newBuilder()
           .setJobName("jobName-1438096408")
           .setProjectId("projectId-894832108")
           .build();
   storageTransferServiceClient.runTransferJobAsync(request).get();
 }
 
Parameter
NameDescription
requestTransferProto.RunTransferJobRequest

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

Returns
TypeDescription
OperationFuture<Empty,TransferOperation>

runTransferJobCallable()

public final UnaryCallable<TransferProto.RunTransferJobRequest,Operation> runTransferJobCallable()

Attempts to start a new TransferOperation for the current TransferJob. A TransferJob has a maximum of one active TransferOperation. If this method is called while a TransferOperation is active, an error wil be returned.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.RunTransferJobRequest request =
       TransferProto.RunTransferJobRequest.newBuilder()
           .setJobName("jobName-1438096408")
           .setProjectId("projectId-894832108")
           .build();
   ApiFuture<Operation> future =
       storageTransferServiceClient.runTransferJobCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<RunTransferJobRequest,Operation>

runTransferJobOperationCallable()

public final OperationCallable<TransferProto.RunTransferJobRequest,Empty,TransferTypes.TransferOperation> runTransferJobOperationCallable()

Attempts to start a new TransferOperation for the current TransferJob. A TransferJob has a maximum of one active TransferOperation. If this method is called while a TransferOperation is active, an error wil be returned.

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.RunTransferJobRequest request =
       TransferProto.RunTransferJobRequest.newBuilder()
           .setJobName("jobName-1438096408")
           .setProjectId("projectId-894832108")
           .build();
   OperationFuture<Empty, TransferTypes.TransferOperation> future =
       storageTransferServiceClient.runTransferJobOperationCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
OperationCallable<RunTransferJobRequest,Empty,TransferOperation>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()

updateTransferJob(TransferProto.UpdateTransferJobRequest request)

public final TransferTypes.TransferJob updateTransferJob(TransferProto.UpdateTransferJobRequest request)

Updates a transfer job. Updating a job's transfer spec does not affect transfer operations that are running already.

**Note:** The job's status field can be modified using this RPC (for example, to set a job's status to DELETED, DISABLED, or ENABLED).

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.UpdateTransferJobRequest request =
       TransferProto.UpdateTransferJobRequest.newBuilder()
           .setJobName("jobName-1438096408")
           .setProjectId("projectId-894832108")
           .setTransferJob(TransferTypes.TransferJob.newBuilder().build())
           .setUpdateTransferJobFieldMask(FieldMask.newBuilder().build())
           .build();
   TransferTypes.TransferJob response = storageTransferServiceClient.updateTransferJob(request);
 }
 
Parameter
NameDescription
requestTransferProto.UpdateTransferJobRequest

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

Returns
TypeDescription
TransferTypes.TransferJob

updateTransferJobCallable()

public final UnaryCallable<TransferProto.UpdateTransferJobRequest,TransferTypes.TransferJob> updateTransferJobCallable()

Updates a transfer job. Updating a job's transfer spec does not affect transfer operations that are running already.

**Note:** The job's status field can be modified using this RPC (for example, to set a job's status to DELETED, DISABLED, or ENABLED).

Sample code:


 try (StorageTransferServiceClient storageTransferServiceClient =
     StorageTransferServiceClient.create()) {
   TransferProto.UpdateTransferJobRequest request =
       TransferProto.UpdateTransferJobRequest.newBuilder()
           .setJobName("jobName-1438096408")
           .setProjectId("projectId-894832108")
           .setTransferJob(TransferTypes.TransferJob.newBuilder().build())
           .setUpdateTransferJobFieldMask(FieldMask.newBuilder().build())
           .build();
   ApiFuture<TransferTypes.TransferJob> future =
       storageTransferServiceClient.updateTransferJobCallable().futureCall(request);
   // Do something.
   TransferTypes.TransferJob response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<UpdateTransferJobRequest,TransferJob>