Github user abhishekagarwal87 commented on a diff in the pull request:
https://github.com/apache/storm/pull/1073#discussion_r52822345
--- Diff: storm-core/src/jvm/org/apache/storm/utils/Utils.java ---
@@ -1446,6 +1448,22 @@ public static RuntimeException
wrapInRuntime(Exception e){
}
}
+ public static int getAvailablePort(int prefferedPort) {
+ int localPort = -1;
+ try(ServerSocket socket = new ServerSocket(prefferedPort)) {
+ localPort = socket.getLocalPort();
+ } catch(IOException exp) {
+ if (prefferedPort > 0) {
+ return getAvailablePort(0);
+ }
+ }
+ return localPort;
--- End diff --
one minor comment. previous version never returns -1. can we just bubble up
the exception in catch block if preferredPort is not greater than zero and not
return a negative port? Other than that +1.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---