Merged 5.0.N (5.0.3) to 5.1.N (5.1.1)

113194 abalmus: Merged DEV to 5.0.N (5.0.3)
      113149: MNT-13706 : Admin console unusable after we set any  busy port in Port Number Value for subsystem
         - Fixed issue that caused ACE-4194


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@113251 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-09-28 21:48:32 +00:00
parent 159ecc46fb
commit 884c49c228
7 changed files with 171 additions and 71 deletions

View File

@@ -19,7 +19,9 @@
package org.alfresco.util;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -35,20 +37,22 @@ public class PortUtil
/**
* Check if specified port is free.
* @param port Port number to check.
* @return true if port is free or false if it's already in use.
* @param host A local address to bind to; if null, "" or "0.0.0.0" then all local addresses will be considered.
*/
public static boolean isPortFree(int port)
public static void checkPort(int port, String host) throws IOException
{
boolean isFree = true;
ServerSocket serverSocket = null;
try
{
serverSocket = new ServerSocket(port);
}
catch (IOException ioe)
{
isFree = false;
if (host != null && !host.equals("") && !"0.0.0.0".equals(host.trim()))
{
serverSocket = new ServerSocket(port, 0, InetAddress.getByName(host.trim()));
}
else
{
serverSocket = new ServerSocket(port);
}
}
finally
{
@@ -67,7 +71,5 @@ public class PortUtil
}
}
}
return isFree;
}
}