Package org.apache.camel.test
Class AvailablePortFinder
java.lang.Object
org.apache.camel.test.AvailablePortFinder
Finds currently available server ports.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic AvailablePortFinder.Portfind()static intDeprecated.static intgetNextAvailable(int fromPort, int toPort) Deprecated.usefind()insteadstatic intDeprecated.usefind()insteadstatic <T> intgetSpecificPort(int portNumber, T failurePayload, Function<T, Integer> failureHandler) Deprecated.usefind()insteadstatic intprobePort(int port) Deprecated.internal API, do not use directly
-
Method Details
-
find
-
getNextAvailable
Deprecated.usefind()instead, which returns aAvailablePortFinder.Portthat reserves the port until released. This method immediately releases the port, creating a race condition where another process can grab the port before the caller binds to it.Gets the next available port.- Returns:
- the available port
- Throws:
IllegalStateException- if there are no ports available
-
getNextRandomAvailable
Deprecated.usefind()insteadGets the next available port.- Returns:
- the available port
- Throws:
IllegalStateException- if there are no ports available
-
getNextAvailable
Deprecated.usefind()insteadGets 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
@Deprecated public static <T> int getSpecificPort(int portNumber, T failurePayload, Function<T, Integer> failureHandler) Deprecated.usefind()insteadGets 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
-
probePort
Deprecated.internal API, do not use directlyProbe a port to see if it is free- Parameters:
port- an integer port number to be tested. If port is 0, then the next available port is returned.- Returns:
- the port number itself if the port is free or, in case of port 0, the first available port number.
- Throws:
IllegalStateException- if the port is not free or, in case of port 0, if there are no ports available at all.
-
find()instead, which returns aAvailablePortFinder.Portthat reserves the port until released.