diff --git a/.gitignore b/.gitignore index 79d5793..1c32dc6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ gradlew.bat out/ .DS_Store src/generated # Generated source files +local-repo/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a7f954a..8ec3803 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. \ No newline at end of file +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 diff --git a/src/main/kotlin/com/google/actions/api/smarthome/SmartHomeApp.kt b/src/main/kotlin/com/google/actions/api/smarthome/SmartHomeApp.kt index 2957b56..22171ba 100644 --- a/src/main/kotlin/com/google/actions/api/smarthome/SmartHomeApp.kt +++ b/src/main/kotlin/com/google/actions/api/smarthome/SmartHomeApp.kt @@ -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 @@ -107,7 +108,6 @@ abstract class SmartHomeApp : App { .build() return blockingStub.requestSyncDevices(request) - } /** @@ -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 { @@ -188,4 +196,4 @@ abstract class SmartHomeApp : App { private fun getAsJson(response: SmartHomeResponse): String { return response.build().toString() } -} \ No newline at end of file +}