Package org.apache.camel.test
Class AvailablePortFinder
- java.lang.Object
-
- org.apache.camel.test.AvailablePortFinder
-
public final class AvailablePortFinder extends Object
Finds currently available server ports.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
AvailablePortFinder.Port
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AvailablePortFinder.Port
find()
static int
getNextAvailable()
Gets the next available port.static int
getNextAvailable(int fromPort, int toPort)
Gets the next available port in the given range.static <T> int
getSpecificPort(int portNumber, T failurePayload, Function<T,Integer> failureHandler)
Gets the next available port in the given range.
-
-
-
Method Detail
-
find
public static AvailablePortFinder.Port find()
-
getNextAvailable
public static int getNextAvailable()
Gets the next available port.- Returns:
- the available port
- Throws:
IllegalStateException
- if there are no ports available
-
getNextAvailable
public static int getNextAvailable(int fromPort, int toPort)
Gets the next available port in the given range.- Parameters:
fromPort
- port number start range.toPort
- port number end range.- Returns:
- the available port
- Throws:
IllegalStateException
- if there are no ports available
-
getSpecificPort
public static <T> int getSpecificPort(int portNumber, T failurePayload, Function<T,Integer> failureHandler)
Gets the next available port in the given range.- Parameters:
portNumber
- port number start range.failurePayload
- handover data in case port allocation fails (i.e.: a default one to use)failureHandler
- a handler in case the requested port is not available- Returns:
- the available port
- Throws:
IllegalStateException
- if there are no ports available
-
-