From c5337b101b7980122f135ed323632e5d59f52201 Mon Sep 17 00:00:00 2001 From: Michael Graeb Date: Wed, 25 May 2022 21:01:09 -0700 Subject: [PATCH] add ability to read RpcServer port bound when port auto selected by OS (#280) Co-authored-by: Vitaly Khalmansky --- README.md | 6 +++--- android/iotdevicesdk/build.gradle | 2 +- .../amazon/awssdk/eventstreamrpc/RpcServer.java | 13 +++++++++++++ sdk/pom.xml | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a0154cb31..3c0ab8577 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ mkdir sdk-workspace cd sdk-workspace # Clone the CRT repository # (Use the latest version of the CRT here instead of "v0.16.4") -git clone --branch v0.16.4 --recurse-submodules https://github.com/awslabs/aws-crt-java.git +git clone --branch v0.16.12 --recurse-submodules https://github.com/awslabs/aws-crt-java.git cd aws-crt-java # Compile and install the CRT mvn install -Dmaven.test.skip=true @@ -102,7 +102,7 @@ mkdir sdk-workspace cd sdk-workspace # Clone the CRT repository # (Use the latest version of the CRT here instead of "v0.16.4") -git clone --branch v0.16.4 --recurse-submodules https://github.com/awslabs/aws-crt-java.git +git clone --branch v0.16.12 --recurse-submodules https://github.com/awslabs/aws-crt-java.git # Compile and install the CRT for Android cd aws-crt-java/android ./gradlew connectedCheck # optional, will run the unit tests on any connected devices/emulators @@ -126,7 +126,7 @@ repositories { } dependencies { - implementation 'software.amazon.awssdk.crt:android:0.16.4' + implementation 'software.amazon.awssdk.crt:android:0.16.12' } ``` diff --git a/android/iotdevicesdk/build.gradle b/android/iotdevicesdk/build.gradle index 228557aeb..0af679c1d 100644 --- a/android/iotdevicesdk/build.gradle +++ b/android/iotdevicesdk/build.gradle @@ -91,7 +91,7 @@ repositories { } dependencies { - api 'software.amazon.awssdk.crt:aws-crt-android:0.16.4' + api 'software.amazon.awssdk.crt:aws-crt-android:0.16.12' implementation 'org.slf4j:slf4j-api:1.7.30' implementation 'com.google.code.gson:gson:2.9.0' implementation 'androidx.appcompat:appcompat:1.1.0' diff --git a/sdk/greengrass/event-stream-rpc-server/src/main/java/software/amazon/awssdk/eventstreamrpc/RpcServer.java b/sdk/greengrass/event-stream-rpc-server/src/main/java/software/amazon/awssdk/eventstreamrpc/RpcServer.java index b5a2f047a..dcf2ab143 100644 --- a/sdk/greengrass/event-stream-rpc-server/src/main/java/software/amazon/awssdk/eventstreamrpc/RpcServer.java +++ b/sdk/greengrass/event-stream-rpc-server/src/main/java/software/amazon/awssdk/eventstreamrpc/RpcServer.java @@ -32,6 +32,7 @@ public class RpcServer implements AutoCloseable { private ServerTlsContext tlsContext; private ServerListener listener; private AtomicBoolean serverRunning; + private int boundPort = -1; public RpcServer(EventLoopGroup eventLoopGroup, SocketOptions socketOptions, TlsContextOptions tlsContextOptions, String hostname, int port, EventStreamRPCServiceHandler serviceHandler) { this.eventLoopGroup = eventLoopGroup; @@ -72,9 +73,21 @@ public void onConnectionShutdown(ServerConnection serverConnection, int errorCod LOGGER.info("Server connection closed code [" + CRT.awsErrorString(errorCode) + "]: " + serverConnection.getResourceLogDescription()); } }); + + boundPort = listener.getBoundPort(); + LOGGER.info("IpcServer started..."); } + /** + * Get port bound to. + * + * @return port number that service is bound to. + */ + public int getBoundPort() { + return boundPort; + } + /** * Stops running server and allows the caller to wait on a CompletableFuture */ diff --git a/sdk/pom.xml b/sdk/pom.xml index 518bc75c0..ea2c144e7 100644 --- a/sdk/pom.xml +++ b/sdk/pom.xml @@ -42,7 +42,7 @@ software.amazon.awssdk.crt aws-crt - 0.16.9 + 0.16.12 org.slf4j