Class ConnectionServiceClient (2.12.0)

publicclass ConnectionServiceClientimplementsBackgroundResource

Service Description: Manages external data source connections and credentials.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
LocationNameparent=LocationName.of("[PROJECT]","[LOCATION]");
Connectionconnection=Connection.newBuilder().build();
StringconnectionId="connectionId1923106969";
Connectionresponse=
connectionServiceClient.createConnection(parent,connection,connectionId);
}

Note: close() needs to be called on the ConnectionServiceClient 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 ConnectionServiceSettings 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
ConnectionServiceSettingsconnectionServiceSettings=
ConnectionServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
ConnectionServiceClientconnectionServiceClient=
ConnectionServiceClient.create(connectionServiceSettings);

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
ConnectionServiceSettingsconnectionServiceSettings=
ConnectionServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
ConnectionServiceClientconnectionServiceClient=
ConnectionServiceClient.create(connectionServiceSettings);

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
ConnectionServiceSettingsconnectionServiceSettings=
ConnectionServiceSettings.newHttpJsonBuilder().build();
ConnectionServiceClientconnectionServiceClient=
ConnectionServiceClient.create(connectionServiceSettings);

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

Inheritance

java.lang.Object > ConnectionServiceClient

Implements

BackgroundResource

Static Methods

create()

publicstaticfinalConnectionServiceClientcreate()

Constructs an instance of ConnectionServiceClient with default settings.

Returns
Type Description
Exceptions
Type Description

create(ConnectionServiceSettings settings)

publicstaticfinalConnectionServiceClientcreate(ConnectionServiceSettingssettings)

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

create(ConnectionServiceStub stub)

publicstaticfinalConnectionServiceClientcreate(ConnectionServiceStubstub)

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

Parameter
Name Description
Returns
Type Description

Constructors

ConnectionServiceClient(ConnectionServiceSettings settings)

protectedConnectionServiceClient(ConnectionServiceSettingssettings)

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

ConnectionServiceClient(ConnectionServiceStub stub)

protectedConnectionServiceClient(ConnectionServiceStubstub)
Parameter
Name Description

Methods

awaitTermination(long duration, TimeUnit unit)

publicbooleanawaitTermination(longduration,TimeUnitunit)
Parameters
Name Description
duration long
unit TimeUnit
Returns
Type Description
Exceptions
Type Description

close()

publicfinalvoidclose()

createConnection(CreateConnectionRequest request)

publicfinalConnectioncreateConnection(CreateConnectionRequestrequest)

Creates a new connection.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
CreateConnectionRequestrequest=
CreateConnectionRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setConnectionId("connectionId1923106969")
.setConnection(Connection.newBuilder().build())
.build();
Connectionresponse=connectionServiceClient.createConnection(request);
}
Parameter
Name Description
request CreateConnectionRequest

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

Returns
Type Description

createConnection(LocationName parent, Connection connection, String connectionId)

publicfinalConnectioncreateConnection(LocationNameparent,Connectionconnection,StringconnectionId)

Creates a new connection.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
LocationNameparent=LocationName.of("[PROJECT]","[LOCATION]");
Connectionconnection=Connection.newBuilder().build();
StringconnectionId="connectionId1923106969";
Connectionresponse=
connectionServiceClient.createConnection(parent,connection,connectionId);
}
Parameters
Name Description
parent LocationName

Required. Parent resource name. Must be in the format projects/{project_id}/locations/{location_id}

connection Connection

Required. Connection to create.

connectionId String

Optional. Connection id that should be assigned to the created connection.

Returns
Type Description

createConnection(String parent, Connection connection, String connectionId)

publicfinalConnectioncreateConnection(Stringparent,Connectionconnection,StringconnectionId)

Creates a new connection.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
Stringparent=LocationName.of("[PROJECT]","[LOCATION]").toString();
Connectionconnection=Connection.newBuilder().build();
StringconnectionId="connectionId1923106969";
Connectionresponse=
connectionServiceClient.createConnection(parent,connection,connectionId);
}
Parameters
Name Description
parent String

Required. Parent resource name. Must be in the format projects/{project_id}/locations/{location_id}

connection Connection

Required. Connection to create.

connectionId String

Optional. Connection id that should be assigned to the created connection.

Returns
Type Description

createConnectionCallable()

publicfinalUnaryCallable<CreateConnectionRequest,Connection>createConnectionCallable()

Creates a new connection.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
CreateConnectionRequestrequest=
CreateConnectionRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setConnectionId("connectionId1923106969")
.setConnection(Connection.newBuilder().build())
.build();
ApiFuture<Connection>future=
connectionServiceClient.createConnectionCallable().futureCall(request);
// Do something.
Connectionresponse=future.get();
}
Returns
Type Description

deleteConnection(ConnectionName name)

publicfinalvoiddeleteConnection(ConnectionNamename)

Deletes connection and associated credential.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
ConnectionNamename=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]");
connectionServiceClient.deleteConnection(name);
}
Parameter
Name Description
name ConnectionName

Required. Name of the deleted connection, for example: projects/{project_id}/locations/{location_id}/connections/{connection_id}

deleteConnection(DeleteConnectionRequest request)

publicfinalvoiddeleteConnection(DeleteConnectionRequestrequest)

Deletes connection and associated credential.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
DeleteConnectionRequestrequest=
DeleteConnectionRequest.newBuilder()
.setName(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.build();
connectionServiceClient.deleteConnection(request);
}
Parameter
Name Description
request DeleteConnectionRequest

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

deleteConnection(String name)

publicfinalvoiddeleteConnection(Stringname)

Deletes connection and associated credential.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
Stringname=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString();
connectionServiceClient.deleteConnection(name);
}
Parameter
Name Description
name String

Required. Name of the deleted connection, for example: projects/{project_id}/locations/{location_id}/connections/{connection_id}

deleteConnectionCallable()

publicfinalUnaryCallable<DeleteConnectionRequest,Empty>deleteConnectionCallable()

Deletes connection and associated credential.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
DeleteConnectionRequestrequest=
DeleteConnectionRequest.newBuilder()
.setName(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.build();
ApiFuture<Empty>future=
connectionServiceClient.deleteConnectionCallable().futureCall(request);
// Do something.
future.get();
}
Returns
Type Description

getConnection(ConnectionName name)

publicfinalConnectiongetConnection(ConnectionNamename)

Returns specified connection.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
ConnectionNamename=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]");
Connectionresponse=connectionServiceClient.getConnection(name);
}
Parameter
Name Description
name ConnectionName

Required. Name of the requested connection, for example: projects/{project_id}/locations/{location_id}/connections/{connection_id}

Returns
Type Description

getConnection(GetConnectionRequest request)

publicfinalConnectiongetConnection(GetConnectionRequestrequest)

Returns specified connection.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
GetConnectionRequestrequest=
GetConnectionRequest.newBuilder()
.setName(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.build();
Connectionresponse=connectionServiceClient.getConnection(request);
}
Parameter
Name Description
request GetConnectionRequest

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

Returns
Type Description

getConnection(String name)

publicfinalConnectiongetConnection(Stringname)

Returns specified connection.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
Stringname=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString();
Connectionresponse=connectionServiceClient.getConnection(name);
}
Parameter
Name Description
name String

Required. Name of the requested connection, for example: projects/{project_id}/locations/{location_id}/connections/{connection_id}

Returns
Type Description

getConnectionCallable()

publicfinalUnaryCallable<GetConnectionRequest,Connection>getConnectionCallable()

Returns specified connection.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
GetConnectionRequestrequest=
GetConnectionRequest.newBuilder()
.setName(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.build();
ApiFuture<Connection>future=
connectionServiceClient.getConnectionCallable().futureCall(request);
// Do something.
Connectionresponse=future.get();
}
Returns
Type Description

getIamPolicy(ResourceName resource, GetPolicyOptions options)

publicfinalPolicygetIamPolicy(ResourceNameresource,GetPolicyOptionsoptions)

Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
ResourceNameresource=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]");
GetPolicyOptionsoptions=GetPolicyOptions.newBuilder().build();
Policyresponse=connectionServiceClient.getIamPolicy(resource,options);
}
Parameters
Name Description
resource com.google.api.resourcenames.ResourceName

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

options com.google.iam.v1.GetPolicyOptions

OPTIONAL: A GetPolicyOptions object for specifying options to GetIamPolicy.

Returns
Type Description
com.google.iam.v1.Policy

getIamPolicy(GetIamPolicyRequest request)

publicfinalPolicygetIamPolicy(GetIamPolicyRequestrequest)

Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
GetIamPolicyRequestrequest=
GetIamPolicyRequest.newBuilder()
.setResource(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.setOptions(GetPolicyOptions.newBuilder().build())
.build();
Policyresponse=connectionServiceClient.getIamPolicy(request);
}
Parameter
Name Description
request com.google.iam.v1.GetIamPolicyRequest

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

Returns
Type Description
com.google.iam.v1.Policy

getIamPolicy(String resource, GetPolicyOptions options)

publicfinalPolicygetIamPolicy(Stringresource,GetPolicyOptionsoptions)

Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
Stringresource=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString();
GetPolicyOptionsoptions=GetPolicyOptions.newBuilder().build();
Policyresponse=connectionServiceClient.getIamPolicy(resource,options);
}
Parameters
Name Description
resource String

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

options com.google.iam.v1.GetPolicyOptions

OPTIONAL: A GetPolicyOptions object for specifying options to GetIamPolicy.

Returns
Type Description
com.google.iam.v1.Policy

getIamPolicyCallable()

publicfinalUnaryCallable<GetIamPolicyRequest,Policy>getIamPolicyCallable()

Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
GetIamPolicyRequestrequest=
GetIamPolicyRequest.newBuilder()
.setResource(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.setOptions(GetPolicyOptions.newBuilder().build())
.build();
ApiFuture<Policy>future=connectionServiceClient.getIamPolicyCallable().futureCall(request);
// Do something.
Policyresponse=future.get();
}
Returns
Type Description
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy>

getSettings()

publicfinalConnectionServiceSettingsgetSettings()
Returns
Type Description

getStub()

publicConnectionServiceStubgetStub()
Returns
Type Description

isShutdown()

publicbooleanisShutdown()
Returns
Type Description

isTerminated()

publicbooleanisTerminated()
Returns
Type Description

listConnections(ListConnectionsRequest request)

publicfinalConnectionServiceClient.ListConnectionsPagedResponselistConnections(ListConnectionsRequestrequest)

Returns a list of connections in the given project.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
ListConnectionsRequestrequest=
ListConnectionsRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for(Connectionelement:connectionServiceClient.listConnections(request).iterateAll()){
// doThingsWith(element);
}
}
Parameter
Name Description
request ListConnectionsRequest

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

Returns
Type Description

listConnections(LocationName parent)

publicfinalConnectionServiceClient.ListConnectionsPagedResponselistConnections(LocationNameparent)

Returns a list of connections in the given project.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
LocationNameparent=LocationName.of("[PROJECT]","[LOCATION]");
for(Connectionelement:connectionServiceClient.listConnections(parent).iterateAll()){
// doThingsWith(element);
}
}
Parameter
Name Description
parent LocationName

Required. Parent resource name. Must be in the form: projects/{project_id}/locations/{location_id}

Returns
Type Description

listConnections(String parent)

publicfinalConnectionServiceClient.ListConnectionsPagedResponselistConnections(Stringparent)

Returns a list of connections in the given project.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
Stringparent=LocationName.of("[PROJECT]","[LOCATION]").toString();
for(Connectionelement:connectionServiceClient.listConnections(parent).iterateAll()){
// doThingsWith(element);
}
}
Parameter
Name Description
parent String

Required. Parent resource name. Must be in the form: projects/{project_id}/locations/{location_id}

Returns
Type Description

listConnectionsCallable()

publicfinalUnaryCallable<ListConnectionsRequest,ListConnectionsResponse>listConnectionsCallable()

Returns a list of connections in the given project.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
ListConnectionsRequestrequest=
ListConnectionsRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while(true){
ListConnectionsResponseresponse=
connectionServiceClient.listConnectionsCallable().call(request);
for(Connectionelement:response.getConnectionsList()){
// doThingsWith(element);
}
StringnextPageToken=response.getNextPageToken();
if(!Strings.isNullOrEmpty(nextPageToken)){
request=request.toBuilder().setPageToken(nextPageToken).build();
}else{
break;
}
}
}
Returns
Type Description

listConnectionsPagedCallable()

publicfinalUnaryCallable<ListConnectionsRequest,ConnectionServiceClient.ListConnectionsPagedResponse>listConnectionsPagedCallable()

Returns a list of connections in the given project.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
ListConnectionsRequestrequest=
ListConnectionsRequest.newBuilder()
.setParent(LocationName.of("[PROJECT]","[LOCATION]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<Connection>future=
connectionServiceClient.listConnectionsPagedCallable().futureCall(request);
// Do something.
for(Connectionelement:future.get().iterateAll()){
// doThingsWith(element);
}
}
Returns
Type Description

setIamPolicy(ResourceName resource, Policy policy)

publicfinalPolicysetIamPolicy(ResourceNameresource,Policypolicy)

Sets the access control policy on the specified resource. Replaces any existing policy.

Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
ResourceNameresource=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]");
Policypolicy=Policy.newBuilder().build();
Policyresponse=connectionServiceClient.setIamPolicy(resource,policy);
}
Parameters
Name Description
resource com.google.api.resourcenames.ResourceName

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policy com.google.iam.v1.Policy

REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.

Returns
Type Description
com.google.iam.v1.Policy

setIamPolicy(SetIamPolicyRequest request)

publicfinalPolicysetIamPolicy(SetIamPolicyRequestrequest)

Sets the access control policy on the specified resource. Replaces any existing policy.

Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
SetIamPolicyRequestrequest=
SetIamPolicyRequest.newBuilder()
.setResource(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.setPolicy(Policy.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
Policyresponse=connectionServiceClient.setIamPolicy(request);
}
Parameter
Name Description
request com.google.iam.v1.SetIamPolicyRequest

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

Returns
Type Description
com.google.iam.v1.Policy

setIamPolicy(String resource, Policy policy)

publicfinalPolicysetIamPolicy(Stringresource,Policypolicy)

Sets the access control policy on the specified resource. Replaces any existing policy.

Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
Stringresource=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString();
Policypolicy=Policy.newBuilder().build();
Policyresponse=connectionServiceClient.setIamPolicy(resource,policy);
}
Parameters
Name Description
resource String

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policy com.google.iam.v1.Policy

REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.

Returns
Type Description
com.google.iam.v1.Policy

setIamPolicyCallable()

publicfinalUnaryCallable<SetIamPolicyRequest,Policy>setIamPolicyCallable()

Sets the access control policy on the specified resource. Replaces any existing policy.

Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
SetIamPolicyRequestrequest=
SetIamPolicyRequest.newBuilder()
.setResource(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.setPolicy(Policy.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture<Policy>future=connectionServiceClient.setIamPolicyCallable().futureCall(request);
// Do something.
Policyresponse=future.get();
}
Returns
Type Description
UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy>

shutdown()

publicvoidshutdown()

shutdownNow()

publicvoidshutdownNow()

testIamPermissions(ResourceName resource, List<String> permissions)

publicfinalTestIamPermissionsResponsetestIamPermissions(ResourceNameresource,List<String>permissions)

Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.

Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
ResourceNameresource=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]");
List<String>permissions=newArrayList<>();
TestIamPermissionsResponseresponse=
connectionServiceClient.testIamPermissions(resource,permissions);
}
Parameters
Name Description
resource com.google.api.resourcenames.ResourceName

REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.

permissions List<String>

The set of permissions to check for the resource. Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see IAM Overview.

Returns
Type Description
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissions(TestIamPermissionsRequest request)

publicfinalTestIamPermissionsResponsetestIamPermissions(TestIamPermissionsRequestrequest)

Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.

Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
TestIamPermissionsRequestrequest=
TestIamPermissionsRequest.newBuilder()
.setResource(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.addAllPermissions(newArrayList<String>())
.build();
TestIamPermissionsResponseresponse=connectionServiceClient.testIamPermissions(request);
}
Parameter
Name Description
request com.google.iam.v1.TestIamPermissionsRequest

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

Returns
Type Description
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissions(String resource, List<String> permissions)

publicfinalTestIamPermissionsResponsetestIamPermissions(Stringresource,List<String>permissions)

Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.

Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
Stringresource=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString();
List<String>permissions=newArrayList<>();
TestIamPermissionsResponseresponse=
connectionServiceClient.testIamPermissions(resource,permissions);
}
Parameters
Name Description
resource String

REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.

permissions List<String>

The set of permissions to check for the resource. Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see IAM Overview.

Returns
Type Description
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissionsCallable()

publicfinalUnaryCallable<TestIamPermissionsRequest,TestIamPermissionsResponse>testIamPermissionsCallable()

Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.

Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
TestIamPermissionsRequestrequest=
TestIamPermissionsRequest.newBuilder()
.setResource(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.addAllPermissions(newArrayList<String>())
.build();
ApiFuture<TestIamPermissionsResponse>future=
connectionServiceClient.testIamPermissionsCallable().futureCall(request);
// Do something.
TestIamPermissionsResponseresponse=future.get();
}
Returns
Type Description
UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse>

updateConnection(ConnectionName name, Connection connection, FieldMask updateMask)

publicfinalConnectionupdateConnection(ConnectionNamename,Connectionconnection,FieldMaskupdateMask)

Updates the specified connection. For security reasons, also resets credential if connection properties are in the update field mask.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
ConnectionNamename=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]");
Connectionconnection=Connection.newBuilder().build();
FieldMaskupdateMask=FieldMask.newBuilder().build();
Connectionresponse=connectionServiceClient.updateConnection(name,connection,updateMask);
}
Parameters
Name Description
name ConnectionName

Required. Name of the connection to update, for example: projects/{project_id}/locations/{location_id}/connections/{connection_id}

connection Connection

Required. Connection containing the updated fields.

updateMask FieldMask

Required. Update mask for the connection fields to be updated.

Returns
Type Description

updateConnection(UpdateConnectionRequest request)

publicfinalConnectionupdateConnection(UpdateConnectionRequestrequest)

Updates the specified connection. For security reasons, also resets credential if connection properties are in the update field mask.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
UpdateConnectionRequestrequest=
UpdateConnectionRequest.newBuilder()
.setName(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.setConnection(Connection.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
Connectionresponse=connectionServiceClient.updateConnection(request);
}
Parameter
Name Description
request UpdateConnectionRequest

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

Returns
Type Description

updateConnection(String name, Connection connection, FieldMask updateMask)

publicfinalConnectionupdateConnection(Stringname,Connectionconnection,FieldMaskupdateMask)

Updates the specified connection. For security reasons, also resets credential if connection properties are in the update field mask.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
Stringname=ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString();
Connectionconnection=Connection.newBuilder().build();
FieldMaskupdateMask=FieldMask.newBuilder().build();
Connectionresponse=connectionServiceClient.updateConnection(name,connection,updateMask);
}
Parameters
Name Description
name String

Required. Name of the connection to update, for example: projects/{project_id}/locations/{location_id}/connections/{connection_id}

connection Connection

Required. Connection containing the updated fields.

updateMask FieldMask

Required. Update mask for the connection fields to be updated.

Returns
Type Description

updateConnectionCallable()

publicfinalUnaryCallable<UpdateConnectionRequest,Connection>updateConnectionCallable()

Updates the specified connection. For security reasons, also resets credential if connection properties are in the update field mask.

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(ConnectionServiceClientconnectionServiceClient=ConnectionServiceClient.create()){
UpdateConnectionRequestrequest=
UpdateConnectionRequest.newBuilder()
.setName(ConnectionName.of("[PROJECT]","[LOCATION]","[CONNECTION]").toString())
.setConnection(Connection.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture<Connection>future=
connectionServiceClient.updateConnectionCallable().futureCall(request);
// Do something.
Connectionresponse=future.get();
}
Returns
Type Description

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年11月19日 UTC.