[ 
https://issues.apache.org/jira/browse/STORM-1523?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15145760#comment-15145760
 ] 

ASF GitHub Bot commented on STORM-1523:
---------------------------------------

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.  


> Translate Available Ports task in util.java
> -------------------------------------------
>
>                 Key: STORM-1523
>                 URL: https://issues.apache.org/jira/browse/STORM-1523
>             Project: Apache Storm
>          Issue Type: Sub-task
>          Components: storm-core
>            Reporter: Sanket Reddy
>




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to