Class AvailablePortFinder

java.lang.Object
org.apache.camel.quarkus.test.AvailablePortFinder

public final class AvailablePortFinder extends Object
Finds currently available server ports.
  • Method Details

    • getNextAvailable

      public static int getNextAvailable()
      Gets the next available TCP port.
      Returns:
      the available port
      Throws:
      IllegalStateException - if there are no ports available
    • getNextAvailable

      public static int getNextAvailable(AvailablePortFinder.Protocol protocol)
      Gets the next available port for the given protocol.
      Parameters:
      protocol - the network protocol to reserve the port for. Either TCP or UDP
      Returns:
      the available port
      Throws:
      IllegalStateException - if there are no ports available
    • reserveNetworkPorts

      public static Map<String,Integer> reserveNetworkPorts(String... names)
      Reserve a list of random and not in use TCP network ports and places them in Map.
    • reserveNetworkPorts

      public static Map<String,Integer> reserveNetworkPorts(AvailablePortFinder.Protocol protocol, String... names)
      Reserve a list of random and not in use network ports for the given protocol and places them in Map.
    • reserveNetworkPorts

      public static <T> Map<String,T> reserveNetworkPorts(Function<Integer,T> converter, String... names)
      Reserve a list of random and not in use TCP network ports and places them in Map.
    • reserveNetworkPorts

      public static <T> Map<String,T> reserveNetworkPorts(AvailablePortFinder.Protocol protocol, Function<Integer,T> converter, String... names)
      Reserve a list of random and not in use network ports for the given protocol and places them in Map.
    • releaseReservedPorts

      public static void releaseReservedPorts()