Package org.kie.test.util.network
Class AvailablePortFinder
- java.lang.Object
-
- org.kie.test.util.network.AvailablePortFinder
-
public class AvailablePortFinder extends java.lang.ObjectFinds currently available server ports.- See Also:
- IANA.org
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_PORT_NUMBERThe maximum number of server port number.static intMIN_PORT_NUMBERThe minimum number of server port number.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanavailable(int port)Checks to see if a specific port is available.static java.util.Set<java.lang.Integer>getAvailablePorts()Returns theSetof currently available port numbers (Integer).static java.util.Set<java.lang.Integer>getAvailablePorts(int fromPort, int toPort)Returns theSetof currently avaliable port numbers (Integer) between the specified port range.static intgetNextAvailable()Gets the next available port starting at the lowest port number.static intgetNextAvailable(int fromPort)Gets the next available port starting at a port.
-
-
-
Field Detail
-
MIN_PORT_NUMBER
public static final int MIN_PORT_NUMBER
The minimum number of server port number.- See Also:
- Constant Field Values
-
MAX_PORT_NUMBER
public static final int MAX_PORT_NUMBER
The maximum number of server port number.- See Also:
- Constant Field Values
-
-
Method Detail
-
getAvailablePorts
public static java.util.Set<java.lang.Integer> getAvailablePorts()
Returns theSetof currently available port numbers (Integer). This method is identical togetAvailablePorts(MIN_PORT_NUMBER, MAX_PORT_NUMBER). WARNING: this can take a very long time.
-
getNextAvailable
public static int getNextAvailable()
Gets the next available port starting at the lowest port number.- Throws:
java.util.NoSuchElementException- if there are no ports available
-
getNextAvailable
public static int getNextAvailable(int fromPort)
Gets the next available port starting at a port.- Parameters:
fromPort- the port to scan for availability- Throws:
java.util.NoSuchElementException- if there are no ports available
-
available
public static boolean available(int port)
Checks to see if a specific port is available.- Parameters:
port- the port to check for availability
-
getAvailablePorts
public static java.util.Set<java.lang.Integer> getAvailablePorts(int fromPort, int toPort)Returns theSetof currently avaliable port numbers (Integer) between the specified port range.- Throws:
java.lang.IllegalArgumentException- if port range is not betweenMIN_PORT_NUMBERandMAX_PORT_NUMBERorfromPortif greater thantoPort.
-
-