Class CommentServiceClient (0.29.0)

GitHub RepositoryProduct Reference

Service Description: A service to manage comments on cases.

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 (CommentServiceClient commentServiceClient = CommentServiceClient.create()) {
   CaseName parent = CaseName.ofProjectCaseName("[PROJECT]", "[CASE]");
   Comment comment = Comment.newBuilder().build();
   Comment response = commentServiceClient.createComment(parent, comment);
 }
 

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

ListComments

Retrieve all Comments associated with the Case object.

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

  • listComments(ListCommentsRequest request)

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

  • listComments(CaseName parent)

  • listComments(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.

  • listCommentsPagedCallable()

  • listCommentsCallable()

CreateComment

Add a new comment to the specified Case. The comment object must have the following fields set: body.

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

  • createComment(CreateCommentRequest request)

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

  • createComment(CaseName parent, Comment comment)

  • createComment(String parent, Comment comment)

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

  • createCommentCallable()

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 CommentServiceSettings 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
 CommentServiceSettings commentServiceSettings =
     CommentServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 CommentServiceClient commentServiceClient = CommentServiceClient.create(commentServiceSettings);
 

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
 CommentServiceSettings commentServiceSettings =
     CommentServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 CommentServiceClient commentServiceClient = CommentServiceClient.create(commentServiceSettings);
 

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


 // 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
 CommentServiceSettings commentServiceSettings =
     CommentServiceSettings.newHttpJsonBuilder().build();
 CommentServiceClient commentServiceClient = CommentServiceClient.create(commentServiceSettings);
 

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

Inheritance

java.lang.Object > CommentServiceClient

Static Methods

create()

public static final CommentServiceClient create()

Constructs an instance of CommentServiceClient with default settings.

Returns
Type Description
CommentServiceClient
Exceptions
Type Description
IOException

create(CommentServiceSettings settings)

public static final CommentServiceClient create(CommentServiceSettings settings)

Constructs an instance of CommentServiceClient, 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 CommentServiceSettings
Returns
Type Description
CommentServiceClient
Exceptions
Type Description
IOException

create(CommentServiceStub stub)

public static final CommentServiceClient create(CommentServiceStub stub)

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

Parameter
Name Description
stub CommentServiceStub
Returns
Type Description
CommentServiceClient

Constructors

CommentServiceClient(CommentServiceSettings settings)

protected CommentServiceClient(CommentServiceSettings settings)

Constructs an instance of CommentServiceClient, 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 CommentServiceSettings

CommentServiceClient(CommentServiceStub stub)

protected CommentServiceClient(CommentServiceStub stub)
Parameter
Name Description
stub CommentServiceStub

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

createComment(CaseName parent, Comment comment)

public final Comment createComment(CaseName parent, Comment comment)

Add a new comment to the specified Case. The comment object must have the following fields set: body.

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 (CommentServiceClient commentServiceClient = CommentServiceClient.create()) {
   CaseName parent = CaseName.ofProjectCaseName("[PROJECT]", "[CASE]");
   Comment comment = Comment.newBuilder().build();
   Comment response = commentServiceClient.createComment(parent, comment);
 }
 
Parameters
Name Description
parent CaseName

Required. The resource name of Case to which this comment should be added.

comment Comment

Required. The Comment object to be added to this Case.

Returns
Type Description
Comment

createComment(CreateCommentRequest request)

public final Comment createComment(CreateCommentRequest request)

Add a new comment to the specified Case. The comment object must have the following fields set: body.

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 (CommentServiceClient commentServiceClient = CommentServiceClient.create()) {
   CreateCommentRequest request =
       CreateCommentRequest.newBuilder()
           .setParent(CaseName.ofProjectCaseName("[PROJECT]", "[CASE]").toString())
           .setComment(Comment.newBuilder().build())
           .build();
   Comment response = commentServiceClient.createComment(request);
 }
 
Parameter
Name Description
request CreateCommentRequest

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

Returns
Type Description
Comment

createComment(String parent, Comment comment)

public final Comment createComment(String parent, Comment comment)

Add a new comment to the specified Case. The comment object must have the following fields set: body.

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 (CommentServiceClient commentServiceClient = CommentServiceClient.create()) {
   String parent = CaseName.ofOrganizationCaseName("[ORGANIZATION]", "[CASE]").toString();
   Comment comment = Comment.newBuilder().build();
   Comment response = commentServiceClient.createComment(parent, comment);
 }
 
Parameters
Name Description
parent String

Required. The resource name of Case to which this comment should be added.

comment Comment

Required. The Comment object to be added to this Case.

Returns
Type Description
Comment

createCommentCallable()

public final UnaryCallable<CreateCommentRequest,Comment> createCommentCallable()

Add a new comment to the specified Case. The comment object must have the following fields set: body.

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 (CommentServiceClient commentServiceClient = CommentServiceClient.create()) {
   CreateCommentRequest request =
       CreateCommentRequest.newBuilder()
           .setParent(CaseName.ofProjectCaseName("[PROJECT]", "[CASE]").toString())
           .setComment(Comment.newBuilder().build())
           .build();
   ApiFuture<Comment> future = commentServiceClient.createCommentCallable().futureCall(request);
   // Do something.
   Comment response = future.get();
 }
 
Returns
Type Description
UnaryCallable<CreateCommentRequest,Comment>

getSettings()

public final CommentServiceSettings getSettings()
Returns
Type Description
CommentServiceSettings

getStub()

public CommentServiceStub getStub()
Returns
Type Description
CommentServiceStub

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

listComments(CaseName parent)

public final CommentServiceClient.ListCommentsPagedResponse listComments(CaseName parent)

Retrieve all Comments associated with the Case 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 (CommentServiceClient commentServiceClient = CommentServiceClient.create()) {
   CaseName parent = CaseName.ofProjectCaseName("[PROJECT]", "[CASE]");
   for (Comment element : commentServiceClient.listComments(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent CaseName

Required. The resource name of Case object for which comments should be listed.

Returns
Type Description
CommentServiceClient.ListCommentsPagedResponse

listComments(ListCommentsRequest request)

public final CommentServiceClient.ListCommentsPagedResponse listComments(ListCommentsRequest request)

Retrieve all Comments associated with the Case 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 (CommentServiceClient commentServiceClient = CommentServiceClient.create()) {
   ListCommentsRequest request =
       ListCommentsRequest.newBuilder()
           .setParent(CaseName.ofProjectCaseName("[PROJECT]", "[CASE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (Comment element : commentServiceClient.listComments(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
request ListCommentsRequest

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

Returns
Type Description
CommentServiceClient.ListCommentsPagedResponse

listComments(String parent)

public final CommentServiceClient.ListCommentsPagedResponse listComments(String parent)

Retrieve all Comments associated with the Case 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 (CommentServiceClient commentServiceClient = CommentServiceClient.create()) {
   String parent = CaseName.ofOrganizationCaseName("[ORGANIZATION]", "[CASE]").toString();
   for (Comment element : commentServiceClient.listComments(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent String

Required. The resource name of Case object for which comments should be listed.

Returns
Type Description
CommentServiceClient.ListCommentsPagedResponse

listCommentsCallable()

public final UnaryCallable<ListCommentsRequest,ListCommentsResponse> listCommentsCallable()

Retrieve all Comments associated with the Case 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 (CommentServiceClient commentServiceClient = CommentServiceClient.create()) {
   ListCommentsRequest request =
       ListCommentsRequest.newBuilder()
           .setParent(CaseName.ofProjectCaseName("[PROJECT]", "[CASE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     ListCommentsResponse response = commentServiceClient.listCommentsCallable().call(request);
     for (Comment element : response.getCommentsList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
Type Description
UnaryCallable<ListCommentsRequest,ListCommentsResponse>

listCommentsPagedCallable()

public final UnaryCallable<ListCommentsRequest,CommentServiceClient.ListCommentsPagedResponse> listCommentsPagedCallable()

Retrieve all Comments associated with the Case 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 (CommentServiceClient commentServiceClient = CommentServiceClient.create()) {
   ListCommentsRequest request =
       ListCommentsRequest.newBuilder()
           .setParent(CaseName.ofProjectCaseName("[PROJECT]", "[CASE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<Comment> future =
       commentServiceClient.listCommentsPagedCallable().futureCall(request);
   // Do something.
   for (Comment element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
Type Description
UnaryCallable<ListCommentsRequest,ListCommentsPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()