Class ContactServiceClient (0.4.0)

GitHub RepositoryProduct Reference

Service Description: Provides methods for handling Contact 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 (ContactServiceClient contactServiceClient = ContactServiceClient.create()) {
   ContactName name = ContactName.of("[NETWORK_CODE]", "[CONTACT]");
   Contact response = contactServiceClient.getContact(name);
 }
 

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

GetContact

API to retrieve a Contact object.

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

  • getContact(GetContactRequest request)

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

  • getContact(ContactName name)

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

  • getContactCallable()

ListContacts

API to retrieve a list of Contact objects.

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

  • listContacts(ListContactsRequest request)

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

  • listContacts(NetworkName parent)

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

  • listContactsPagedCallable()

  • listContactsCallable()

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 ContactServiceSettings 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
 ContactServiceSettings contactServiceSettings =
     ContactServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 ContactServiceClient contactServiceClient = ContactServiceClient.create(contactServiceSettings);
 

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
 ContactServiceSettings contactServiceSettings =
     ContactServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 ContactServiceClient contactServiceClient = ContactServiceClient.create(contactServiceSettings);
 

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

Inheritance

java.lang.Object > ContactServiceClient

Static Methods

create()

public static final ContactServiceClient create()

Constructs an instance of ContactServiceClient with default settings.

Returns
Type Description
ContactServiceClient
Exceptions
Type Description
IOException

create(ContactServiceSettings settings)

public static final ContactServiceClient create(ContactServiceSettings settings)

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

create(ContactServiceStub stub)

public static final ContactServiceClient create(ContactServiceStub stub)

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

Parameter
Name Description
stub ContactServiceStub
Returns
Type Description
ContactServiceClient

Constructors

ContactServiceClient(ContactServiceSettings settings)

protected ContactServiceClient(ContactServiceSettings settings)

Constructs an instance of ContactServiceClient, 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 ContactServiceSettings

ContactServiceClient(ContactServiceStub stub)

protected ContactServiceClient(ContactServiceStub stub)
Parameter
Name Description
stub ContactServiceStub

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

getContact(ContactName name)

public final Contact getContact(ContactName name)

API to retrieve a Contact 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 (ContactServiceClient contactServiceClient = ContactServiceClient.create()) {
   ContactName name = ContactName.of("[NETWORK_CODE]", "[CONTACT]");
   Contact response = contactServiceClient.getContact(name);
 }
 
Parameter
Name Description
name ContactName

Required. The resource name of the Contact. Format: networks/{network_code}/contacts/{contact_id}

Returns
Type Description
Contact

getContact(GetContactRequest request)

public final Contact getContact(GetContactRequest request)

API to retrieve a Contact 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 (ContactServiceClient contactServiceClient = ContactServiceClient.create()) {
   GetContactRequest request =
       GetContactRequest.newBuilder()
           .setName(ContactName.of("[NETWORK_CODE]", "[CONTACT]").toString())
           .build();
   Contact response = contactServiceClient.getContact(request);
 }
 
Parameter
Name Description
request GetContactRequest

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

Returns
Type Description
Contact

getContact(String name)

public final Contact getContact(String name)

API to retrieve a Contact 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 (ContactServiceClient contactServiceClient = ContactServiceClient.create()) {
   String name = ContactName.of("[NETWORK_CODE]", "[CONTACT]").toString();
   Contact response = contactServiceClient.getContact(name);
 }
 
Parameter
Name Description
name String

Required. The resource name of the Contact. Format: networks/{network_code}/contacts/{contact_id}

Returns
Type Description
Contact

getContactCallable()

public final UnaryCallable<GetContactRequest,Contact> getContactCallable()

API to retrieve a Contact 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 (ContactServiceClient contactServiceClient = ContactServiceClient.create()) {
   GetContactRequest request =
       GetContactRequest.newBuilder()
           .setName(ContactName.of("[NETWORK_CODE]", "[CONTACT]").toString())
           .build();
   ApiFuture<Contact> future = contactServiceClient.getContactCallable().futureCall(request);
   // Do something.
   Contact response = future.get();
 }
 
Returns
Type Description
UnaryCallable<GetContactRequest,Contact>

getSettings()

public final ContactServiceSettings getSettings()
Returns
Type Description
ContactServiceSettings

getStub()

public ContactServiceStub getStub()
Returns
Type Description
ContactServiceStub

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

listContacts(ListContactsRequest request)

public final ContactServiceClient.ListContactsPagedResponse listContacts(ListContactsRequest request)

API to retrieve a list of Contact 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 (ContactServiceClient contactServiceClient = ContactServiceClient.create()) {
   ListContactsRequest request =
       ListContactsRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   for (Contact element : contactServiceClient.listContacts(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
request ListContactsRequest

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

Returns
Type Description
ContactServiceClient.ListContactsPagedResponse

listContacts(NetworkName parent)

public final ContactServiceClient.ListContactsPagedResponse listContacts(NetworkName parent)

API to retrieve a list of Contact 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 (ContactServiceClient contactServiceClient = ContactServiceClient.create()) {
   NetworkName parent = NetworkName.of("[NETWORK_CODE]");
   for (Contact element : contactServiceClient.listContacts(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent NetworkName

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

Returns
Type Description
ContactServiceClient.ListContactsPagedResponse

listContacts(String parent)

public final ContactServiceClient.ListContactsPagedResponse listContacts(String parent)

API to retrieve a list of Contact 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 (ContactServiceClient contactServiceClient = ContactServiceClient.create()) {
   String parent = NetworkName.of("[NETWORK_CODE]").toString();
   for (Contact element : contactServiceClient.listContacts(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent String

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

Returns
Type Description
ContactServiceClient.ListContactsPagedResponse

listContactsCallable()

public final UnaryCallable<ListContactsRequest,ListContactsResponse> listContactsCallable()

API to retrieve a list of Contact 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 (ContactServiceClient contactServiceClient = ContactServiceClient.create()) {
   ListContactsRequest request =
       ListContactsRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   while (true) {
     ListContactsResponse response = contactServiceClient.listContactsCallable().call(request);
     for (Contact element : response.getContactsList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
Type Description
UnaryCallable<ListContactsRequest,ListContactsResponse>

listContactsPagedCallable()

public final UnaryCallable<ListContactsRequest,ContactServiceClient.ListContactsPagedResponse> listContactsPagedCallable()

API to retrieve a list of Contact 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 (ContactServiceClient contactServiceClient = ContactServiceClient.create()) {
   ListContactsRequest request =
       ListContactsRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   ApiFuture<Contact> future =
       contactServiceClient.listContactsPagedCallable().futureCall(request);
   // Do something.
   for (Contact element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
Type Description
UnaryCallable<ListContactsRequest,ListContactsPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()