Skip to content

Commit e12e2d4

Browse files
aribraygcf-owl-bot[bot]
authored andcommitted
docs(samples): add try blocks to clean up resources in samples and sample tests (#521)
* add try block to clean up resources Change-Id: Ie68f4715646942d2e78189b3477cb9a5a31713b8 * docs: add try block to clean up resources Change-Id: Ibaa2bd6a9f687b67af61a5f958c37e2faf087434 * add try block to clean up resources Change-Id: I60fff4d6c83d42b8921b4ed4ce6c0eea76a952c6 * add try block to clean up resources Change-Id: I2facb88a81c1d76d5b2316da04cebdffba6634b9 * add Thread.sleep to try blocks, fix checkstyle Change-Id: I0eab8286ac21a8becf64b541100050581016ca5d * add Thread.sleep Change-Id: I94553a4501a6bdfbdcad1360833cd5e4352d9a77 * add Thread.sleep Change-Id: I123c577193306dc4625d2d56637e71e13cd06f70 * add try block to clean up resources Change-Id: I38d51da44e19b7c50d09d3e32aa6b5378c8fc0e2 * change fulfillmentInfo tag Change-Id: I8f0b7e31a2283c5dae7c6b377861ee03e8cbe621 * add try block to clean up resources Change-Id: I3ee67b4c3ce45b18138d9382fd18f5f4646372db * add ; Change-Id: I10cb37ff93f4c28c1f94d8e221c893fe4b74835a * remove try block Change-Id: I9b5f96d7c0ee75745084ed2a277fb9dc8b76a98f * move try block Change-Id: I17eeaf75673cb24682552dd59916c0ad5d68b89a * remove try block Change-Id: I001e1bd68b5c0953d2c634239828d81bf2576a25 * change fulfillmentInfo tag Change-Id: I1454736df9212b36afcd322ef3ce8c677b3500e8 * checkstyle Change-Id: I10d3750668a4acb9ff18f58fdb4f1a19faf6eacc * add try block to clean up resources Change-Id: I2a56b4f9b558fbebb816fb409fdabff4ee194f2f * add catch Change-Id: I7dd46f9543256427e9d86ab4f60b4806bdb8bd9a * remove println Change-Id: Idb0f4d75d0e7902a666248c48ed4fc54aeef5e59 * checkstyle Change-Id: Ie28023c2bf6422a50dc5e09128ede1e49679c95d * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * add try-with-resources comment to client object creation lines in snippets Change-Id: Ic1acaa6097e972b2db35cca2f5928e826ef08964 * add string.format Change-Id: I25e7e803c8d0b40e6503b6ed8c5fd1c872c4506b * update parentPath Change-Id: Id387695b0d86c30c74f796e7f57db6e1f8be43bd * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 07b8703 commit e12e2d4

29 files changed

+157
-78
lines changed

dialogflow-cx/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ public void service(HttpRequest request, HttpResponse response) throws Exception
5757
Gson gson = new GsonBuilder().setPrettyPrinting().create();
5858
String jsonResponseObject = gson.toJson(webhookResponse);
5959

60-
System.out.println("Response Object: \n");
61-
System.out.println(jsonResponseObject.toString());
62-
6360
/* {
6461
* "page_info": {
6562
* "form_info": {

dialogflow-cx/snippets/src/main/java/dialogflow/cx/CreateAgent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public static Agent createAgent(String parent, String displayName) throws IOExce
3939
String apiEndpoint = "global-dialogflow.googleapis.com:443";
4040

4141
AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build();
42+
// Note: close() needs to be called on the AgentsClient object to clean up resources
43+
// such as threads. In the example below, try-with-resources is used,
44+
// which automatically calls close().
4245
try (AgentsClient client = AgentsClient.create(agentsSettings)) {
4346
// Set the details of the Agent to create
4447
Builder build = Agent.newBuilder();

dialogflow-cx/snippets/src/main/java/dialogflow/cx/CreateFlow.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public static Flow createFlow(
5050
}
5151
FlowsSettings flowsSettings = flowsSettingsBuilder.build();
5252

53-
// Instantiates a client
53+
// Instantiates a client.
54+
// Note: close() needs to be called on the FlowsClient object to clean up resources
55+
// such as threads. In the example below, try-with-resources is used,
56+
// which automatically calls close().
5457
try (FlowsClient flowsClient = FlowsClient.create(flowsSettings)) {
5558
// Set the project agent name using the projectID (my-project-id), locationID (global), and
5659
// agentID (UUID).

dialogflow-cx/snippets/src/main/java/dialogflow/cx/CreateIntent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public static Intent createIntent(
4848
IntentsSettings intentsSettings = intentsSettingsBuilder.build();
4949

5050
// Instantiates a client
51+
// Note: close() needs to be called on the IntentsClient object to clean up resources
52+
// such as threads. In the example below, try-with-resources is used,
53+
// which automatically calls close().
5154
try (IntentsClient intentsClient = IntentsClient.create(intentsSettings)) {
5255
// Set the project agent name using the projectID (my-project-id), locationID (global), and
5356
// agentID (UUID).

dialogflow-cx/snippets/src/main/java/dialogflow/cx/CreatePage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public static Page createPage(
5252
PagesSettings pagesSettings = pagesSettingsBuilder.build();
5353

5454
// Instantiates a client
55+
// Note: close() needs to be called on the PagesClient object to clean up resources
56+
// such as threads. In the example below, try-with-resources is used,
57+
// which automatically calls close().
5558
try (PagesClient pagesClient = PagesClient.create(pagesSettings)) {
5659
// Set the flow name using the projectID (my-project-id), locationID (global), agentID (UUID)
5760
// and flowID (UUID).

dialogflow-cx/snippets/src/main/java/dialogflow/cx/CreateSimplePage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public static Page createPage(
5959
.setPage(pageBuilder);
6060

6161
// Make API request to create page
62+
// Note: close() needs to be called on the PagesClient object to clean up resources
63+
// such as threads. In the example below, try-with-resources is used,
64+
// which automatically calls close().
6265
try (PagesClient client = PagesClient.create()) {
6366
response = client.createPage(createRequestBuilder.build());
6467
System.out.println("Successfully created page!");

dialogflow-cx/snippets/src/main/java/dialogflow/cx/DeletePage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public static void main(String[] args) throws IOException {
4040
public static void deletePage(
4141
String projectId, String agentId, String flowId, String pageId, String location)
4242
throws IOException {
43+
44+
// Note: close() needs to be called on the PagesClient object to clean up resources
45+
// such as threads. In the example below, try-with-resources is used,
46+
// which automatically calls close().
4347
try (PagesClient client = PagesClient.create()) {
4448
Builder deleteRequestBuilder = DeletePageRequest.newBuilder();
4549

dialogflow-cx/snippets/src/main/java/dialogflow/cx/DetectIntent.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ public static Map<String, QueryResult> detectIntent(
5252
SessionsSettings sessionsSettings = sessionsSettingsBuilder.build();
5353

5454
Map<String, QueryResult> queryResults = Maps.newHashMap();
55-
// Instantiates a client
55+
// Instantiates a client.
56+
57+
// Note: close() needs to be called on the SessionsClient object to clean up resources
58+
// such as threads. In the example below, try-with-resources is used,
59+
// which automatically calls close().
5660
try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
5761
// Set the session name using the projectID (my-project-id), locationID (global), agentID
5862
// (UUID), and sessionId (UUID).

dialogflow-cx/snippets/src/main/java/dialogflow/cx/DetectIntentAudioInput.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public static void detectIntent(
7676

7777
// Instantiates a client by setting the session name.
7878
// Format:`projects/<ProjectID>/locations/<LocationID>/agents/<AgentID>/sessions/<SessionID>`
79+
80+
// Note: close() needs to be called on the SessionsClient object to clean up resources
81+
// such as threads. In the example below, try-with-resources is used,
82+
// which automatically calls close().
7983
try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
8084
SessionName session =
8185
SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId);

dialogflow-cx/snippets/src/main/java/dialogflow/cx/DetectIntentDisableWebhook.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public static Map<String, QueryResult> detectIntent(
6868

6969
// Instantiates a client by setting the session name.
7070
// Format:`projects/<ProjectID>/locations/<LocationID>/agents/<AgentID>/sessions/<SessionID>`
71+
72+
// Note: close() needs to be called on the SessionsClient object to clean up resources
73+
// such as threads. In the example below, try-with-resources is used,
74+
// which automatically calls close().
7175
try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
7276
SessionName session =
7377
SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId);

0 commit comments

Comments
 (0)