org.apache.camel.test
Class AvailablePortFinder

java.lang.Object
  extended by org.apache.camel.test.AvailablePortFinder

public final class AvailablePortFinder
extends Object

Finds currently available server ports.


Field Summary
static int MAX_PORT_NUMBER
          The maximum server currentMinPort number for IPv4.
static int MIN_PORT_NUMBER
          The minimum server currentMinPort number for IPv4.
 
Method Summary
static boolean available(int port)
          Checks to see if a specific port is available.
static int getNextAvailable()
          Gets the next available port starting at the lowest number.
static int getNextAvailable(int fromPort)
          Gets the next available port starting at a given from port.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_PORT_NUMBER

public static final int MIN_PORT_NUMBER
The minimum server currentMinPort number for IPv4. Set at 1100 to avoid returning privileged currentMinPort numbers.

See Also:
Constant Field Values

MAX_PORT_NUMBER

public static final int MAX_PORT_NUMBER
The maximum server currentMinPort number for IPv4.

See Also:
Constant Field Values
Method Detail

getNextAvailable

public static int getNextAvailable()
Gets the next available port starting at the lowest number. This is the preferred method to use. The port return is immediately marked in use and doesn't rely on the caller actually opening the port.

Returns:
the available port
Throws:
IllegalArgumentException - is thrown if the port number is out of range
NoSuchElementException - if there are no ports available

getNextAvailable

public static int getNextAvailable(int fromPort)
Gets the next available port starting at a given from port.

Parameters:
fromPort - the from port to scan for availability
Returns:
the available port
Throws:
IllegalArgumentException - is thrown if the port number is out of range
NoSuchElementException - if there are no ports available

available

public static boolean available(int port)
                         throws IllegalArgumentException
Checks to see if a specific port is available.

Parameters:
port - the port number to check for availability
Returns:
true if the port is available, or false if not
Throws:
IllegalArgumentException - is thrown if the port number is out of range


Apache Camel