Class ContentServiceClient (0.39.0)

GitHub RepositoryProduct Reference

Service Description: Provides methods for handling Content objects.

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:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (ContentServiceClient contentServiceClient = ContentServiceClient.create()) {
   ContentName name = ContentName.of("[NETWORK_CODE]", "[CONTENT]");
   Content response = contentServiceClient.getContent(name);
 }
 

Note: close() needs to be called on the ContentServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
Method Description Method Variants

GetContent

API to retrieve a Content object.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getContent(GetContentRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getContent(ContentName name)

  • getContent(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getContentCallable()

ListContent

API to retrieve a list of Content objects.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listContent(ListContentRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listContent(NetworkName parent)

  • listContent(String parent)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listContentPagedCallable()

  • listContentCallable()

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 ContentServiceSettings to create(). For example:

To customize credentials:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 ContentServiceSettings contentServiceSettings =
     ContentServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 ContentServiceClient contentServiceClient = ContentServiceClient.create(contentServiceSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 ContentServiceSettings contentServiceSettings =
     ContentServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 ContentServiceClient contentServiceClient = ContentServiceClient.create(contentServiceSettings);
 

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

Inheritance

java.lang.Object > ContentServiceClient

Static Methods

create()

public static final ContentServiceClient create()

Constructs an instance of ContentServiceClient with default settings.

Returns
Type Description
ContentServiceClient
Exceptions
Type Description
IOException

create(ContentServiceSettings settings)

public static final ContentServiceClient create(ContentServiceSettings settings)

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

Parameter
Name Description
settings ContentServiceSettings
Returns
Type Description
ContentServiceClient
Exceptions
Type Description
IOException

create(ContentServiceStub stub)

public static final ContentServiceClient create(ContentServiceStub stub)

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

Parameter
Name Description
stub ContentServiceStub
Returns
Type Description
ContentServiceClient

Constructors

ContentServiceClient(ContentServiceSettings settings)

protected ContentServiceClient(ContentServiceSettings settings)

Constructs an instance of ContentServiceClient, 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
Name Description
settings ContentServiceSettings

ContentServiceClient(ContentServiceStub stub)

protected ContentServiceClient(ContentServiceStub stub)
Parameter
Name Description
stub ContentServiceStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
Name Description
duration long
unit TimeUnit
Returns
Type Description
boolean
Exceptions
Type Description
InterruptedException

close()

public final void close()

getContent(ContentName name)

public final Content getContent(ContentName name)

API to retrieve a Content object.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (ContentServiceClient contentServiceClient = ContentServiceClient.create()) {
   ContentName name = ContentName.of("[NETWORK_CODE]", "[CONTENT]");
   Content response = contentServiceClient.getContent(name);
 }
 
Parameter
Name Description
name ContentName

Required. The resource name of the Content. Format: networks/{network_code}/content/{content_id}

Returns
Type Description
Content

getContent(GetContentRequest request)

public final Content getContent(GetContentRequest request)

API to retrieve a Content object.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (ContentServiceClient contentServiceClient = ContentServiceClient.create()) {
   GetContentRequest request =
       GetContentRequest.newBuilder()
           .setName(ContentName.of("[NETWORK_CODE]", "[CONTENT]").toString())
           .build();
   Content response = contentServiceClient.getContent(request);
 }
 
Parameter
Name Description
request GetContentRequest

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

Returns
Type Description
Content

getContent(String name)

public final Content getContent(String name)

API to retrieve a Content object.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (ContentServiceClient contentServiceClient = ContentServiceClient.create()) {
   String name = ContentName.of("[NETWORK_CODE]", "[CONTENT]").toString();
   Content response = contentServiceClient.getContent(name);
 }
 
Parameter
Name Description
name String

Required. The resource name of the Content. Format: networks/{network_code}/content/{content_id}

Returns
Type Description
Content

getContentCallable()

public final UnaryCallable<GetContentRequest,Content> getContentCallable()

API to retrieve a Content object.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (ContentServiceClient contentServiceClient = ContentServiceClient.create()) {
   GetContentRequest request =
       GetContentRequest.newBuilder()
           .setName(ContentName.of("[NETWORK_CODE]", "[CONTENT]").toString())
           .build();
   ApiFuture<Content> future = contentServiceClient.getContentCallable().futureCall(request);
   // Do something.
   Content response = future.get();
 }
 
Returns
Type Description
UnaryCallable<GetContentRequest,Content>

getSettings()

public final ContentServiceSettings getSettings()
Returns
Type Description
ContentServiceSettings

getStub()

public ContentServiceStub getStub()
Returns
Type Description
ContentServiceStub

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

listContent(ListContentRequest request)

public final ContentServiceClient.ListContentPagedResponse listContent(ListContentRequest request)

API to retrieve a list of Content objects.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (ContentServiceClient contentServiceClient = ContentServiceClient.create()) {
   ListContentRequest request =
       ListContentRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   for (Content element : contentServiceClient.listContent(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
request ListContentRequest

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

Returns
Type Description
ContentServiceClient.ListContentPagedResponse

listContent(NetworkName parent)

public final ContentServiceClient.ListContentPagedResponse listContent(NetworkName parent)

API to retrieve a list of Content objects.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (ContentServiceClient contentServiceClient = ContentServiceClient.create()) {
   NetworkName parent = NetworkName.of("[NETWORK_CODE]");
   for (Content element : contentServiceClient.listContent(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent NetworkName

Required. The parent, which owns this collection of Content. Format: networks/{network_code}

Returns
Type Description
ContentServiceClient.ListContentPagedResponse

listContent(String parent)

public final ContentServiceClient.ListContentPagedResponse listContent(String parent)

API to retrieve a list of Content objects.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (ContentServiceClient contentServiceClient = ContentServiceClient.create()) {
   String parent = NetworkName.of("[NETWORK_CODE]").toString();
   for (Content element : contentServiceClient.listContent(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent String

Required. The parent, which owns this collection of Content. Format: networks/{network_code}

Returns
Type Description
ContentServiceClient.ListContentPagedResponse

listContentCallable()

public final UnaryCallable<ListContentRequest,ListContentResponse> listContentCallable()

API to retrieve a list of Content objects.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (ContentServiceClient contentServiceClient = ContentServiceClient.create()) {
   ListContentRequest request =
       ListContentRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   while (true) {
     ListContentResponse response = contentServiceClient.listContentCallable().call(request);
     for (Content element : response.getContentList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
Type Description
UnaryCallable<ListContentRequest,ListContentResponse>

listContentPagedCallable()

public final UnaryCallable<ListContentRequest,ContentServiceClient.ListContentPagedResponse> listContentPagedCallable()

API to retrieve a list of Content objects.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (ContentServiceClient contentServiceClient = ContentServiceClient.create()) {
   ListContentRequest request =
       ListContentRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   ApiFuture<Content> future =
       contentServiceClient.listContentPagedCallable().futureCall(request);
   // Do something.
   for (Content element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
Type Description
UnaryCallable<ListContentRequest,ListContentPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()