Package org.apache.mina.util
Class AvailablePortFinder
- java.lang.Object
-
- org.apache.mina.util.AvailablePortFinder
-
public class AvailablePortFinder extends Object
Finds currently available server ports.- Author:
- Apache MINA Project
- See Also:
- IANA.org
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_PORT_NUMBER
The maximum number of server port number.static int
MIN_PORT_NUMBER
The minimum number of server port number.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
available(int port)
Checks to see if a specific port is available.static Set<Integer>
getAvailablePorts()
static Set<Integer>
getAvailablePorts(int fromPort, int toPort)
static int
getNextAvailable()
static int
getNextAvailable(int fromPort)
-
-
-
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
-
getNextAvailable
public static int getNextAvailable()
- Returns:
- an available port, selected by the system.
- Throws:
NoSuchElementException
- if there are no ports available
-
getNextAvailable
public static int getNextAvailable(int fromPort)
- Parameters:
fromPort
- the port to scan for availability- Returns:
- the next available port starting at a port.
- Throws:
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- Returns:
- true if the port is available
-
getAvailablePorts
public static Set<Integer> getAvailablePorts(int fromPort, int toPort)
- Parameters:
fromPort
- The port we start fromtoPort
- The posrt we stop at- Returns:
- the
Set
of currently avalaible port numbers (Integer
) between the specified port range. - Throws:
IllegalArgumentException
- if port range is not betweenMIN_PORT_NUMBER
andMAX_PORT_NUMBER
orfromPort
if greater thantoPort
.
-
-