@BetaApi @Generated(value="by gapic-generator-java") public class EnvironmentsClient extends Object implements BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
AgentName parent = AgentName.ofProjectName("[PROJECT]");
for (Environment element : environmentsClient.listEnvironments(parent).iterateAll()) {
// doThingsWith(element);
}
}
Note: close() needs to be called on the EnvironmentsClient 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:
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 EnvironmentsSettings to create(). For example:
To customize credentials:
EnvironmentsSettings environmentsSettings =
EnvironmentsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
EnvironmentsClient environmentsClient = EnvironmentsClient.create(environmentsSettings);
To customize the endpoint:
EnvironmentsSettings environmentsSettings =
EnvironmentsSettings.newBuilder().setEndpoint(myEndpoint).build();
EnvironmentsClient environmentsClient = EnvironmentsClient.create(environmentsSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Modifier and Type | Class and Description |
---|---|
static class |
EnvironmentsClient.ListEnvironmentsFixedSizeCollection |
static class |
EnvironmentsClient.ListEnvironmentsPage |
static class |
EnvironmentsClient.ListEnvironmentsPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
EnvironmentsClient(EnvironmentsSettings settings)
Constructs an instance of EnvironmentsClient, using the given settings.
|
protected |
EnvironmentsClient(EnvironmentsStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static EnvironmentsClient |
create()
Constructs an instance of EnvironmentsClient with default settings.
|
static EnvironmentsClient |
create(EnvironmentsSettings settings)
Constructs an instance of EnvironmentsClient, using the given settings.
|
static EnvironmentsClient |
create(EnvironmentsStub stub)
Constructs an instance of EnvironmentsClient, using the given stub for making calls.
|
EnvironmentsSettings |
getSettings() |
EnvironmentsStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
EnvironmentsClient.ListEnvironmentsPagedResponse |
listEnvironments(AgentName parent)
Returns the list of all non-draft environments of the specified agent.
|
EnvironmentsClient.ListEnvironmentsPagedResponse |
listEnvironments(ListEnvironmentsRequest request)
Returns the list of all non-draft environments of the specified agent.
|
EnvironmentsClient.ListEnvironmentsPagedResponse |
listEnvironments(String parent)
Returns the list of all non-draft environments of the specified agent.
|
UnaryCallable<ListEnvironmentsRequest,ListEnvironmentsResponse> |
listEnvironmentsCallable()
Returns the list of all non-draft environments of the specified agent.
|
UnaryCallable<ListEnvironmentsRequest,EnvironmentsClient.ListEnvironmentsPagedResponse> |
listEnvironmentsPagedCallable()
Returns the list of all non-draft environments of the specified agent.
|
void |
shutdown() |
void |
shutdownNow() |
protected EnvironmentsClient(EnvironmentsSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected EnvironmentsClient(EnvironmentsStub stub)
public static final EnvironmentsClient create() throws IOException
IOException
public static final EnvironmentsClient create(EnvironmentsSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final EnvironmentsClient create(EnvironmentsStub stub)
public final EnvironmentsSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public EnvironmentsStub getStub()
public final EnvironmentsClient.ListEnvironmentsPagedResponse listEnvironments(AgentName parent)
Sample code:
try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
AgentName parent = AgentName.ofProjectName("[PROJECT]");
for (Environment element : environmentsClient.listEnvironments(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The agent to list all environments from. Format: -
`projects/<Project Number / ID>/agent` - `projects/<Project Number /
ID>/locations/<Location ID>/agent`ApiException
- if the remote call failspublic final EnvironmentsClient.ListEnvironmentsPagedResponse listEnvironments(String parent)
Sample code:
try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
String parent =
EnvironmentName.ofProjectEnvironmentName("[PROJECT]", "[ENVIRONMENT]").toString();
for (Environment element : environmentsClient.listEnvironments(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The agent to list all environments from. Format: -
`projects/<Project Number / ID>/agent` - `projects/<Project Number /
ID>/locations/<Location ID>/agent`ApiException
- if the remote call failspublic final EnvironmentsClient.ListEnvironmentsPagedResponse listEnvironments(ListEnvironmentsRequest request)
Sample code:
try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
ListEnvironmentsRequest request =
ListEnvironmentsRequest.newBuilder()
.setParent(
EnvironmentName.ofProjectEnvironmentName("[PROJECT]", "[ENVIRONMENT]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (Environment element : environmentsClient.listEnvironments(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<ListEnvironmentsRequest,EnvironmentsClient.ListEnvironmentsPagedResponse> listEnvironmentsPagedCallable()
Sample code:
try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
ListEnvironmentsRequest request =
ListEnvironmentsRequest.newBuilder()
.setParent(
EnvironmentName.ofProjectEnvironmentName("[PROJECT]", "[ENVIRONMENT]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<Environment> future =
environmentsClient.listEnvironmentsPagedCallable().futureCall(request);
// Do something.
for (Environment element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<ListEnvironmentsRequest,ListEnvironmentsResponse> listEnvironmentsCallable()
Sample code:
try (EnvironmentsClient environmentsClient = EnvironmentsClient.create()) {
while (true) {
ListEnvironmentsResponse response =
environmentsClient.listEnvironmentsCallable().call(request);
for (Environment element : response.getResponsesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2021 Google LLC. All rights reserved.