Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Close channel after getting a response #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ gradlew.bat
out/
.DS_Store
src/generated # Generated source files
local-repo/
15 changes: 14 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,17 @@ accept your pull requests.
[Google Cloud Platform Samples Style Guide](https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the
recommended coding standards for this organization.
1. Ensure that your code has an appropriate set of unit tests which all pass.
1. Submit a pull request.
1. Submit a pull request.

## Compiling Locally

1. Use Java 8 for compilation. Otherwise compilation will fail while looking for `javax.annotation.Generated`.

1. Install bundled jars to the local repository:

mvn install:install-file@install-actions-bindings
mvn install:install-file@install-dialogflow-bindings

1. Compile the project:

mvn compile
14 changes: 11 additions & 3 deletions src/main/kotlin/com/google/actions/api/smarthome/SmartHomeApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.grpc.ManagedChannelBuilder
import io.grpc.auth.MoreCallCredentials
import java.io.FileInputStream
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit

abstract class SmartHomeApp : App {
var credentials: GoogleCredentials? = null
Expand Down Expand Up @@ -107,7 +108,6 @@ abstract class SmartHomeApp : App {
.build()

return blockingStub.requestSyncDevices(request)

}

/**
Expand All @@ -129,8 +129,16 @@ abstract class SmartHomeApp : App {
// See https://grpc.io/docs/guides/auth.html#authenticate-with-google-3.
.withCallCredentials(MoreCallCredentials.from(this.credentials))

return blockingStub.reportStateAndNotification(request)
val response = blockingStub.reportStateAndNotification(request)

channel.shutdown()
try {
channel.awaitTermination(500, TimeUnit.MILLISECONDS)
} catch (e: InterruptedException) {
e.printStackTrace()
}

return response
}

override fun handleRequest(inputJson: String?, headers: Map<*, *>?): CompletableFuture<String> {
Expand Down Expand Up @@ -188,4 +196,4 @@ abstract class SmartHomeApp : App {
private fun getAsJson(response: SmartHomeResponse): String {
return response.build().toString()
}
}
}