Class PortFinder

java.lang.Object
org.codice.ddf.test.common.configurators.PortFinder
All Implemented Interfaces:
Closeable, AutoCloseable

public class PortFinder extends Object implements Closeable
Class used to find and reserve a range of ports, and assign ports within that range by name. For instance, creating a new instance of PortFinder will reserve a block of ports, calling getPort(String) or getPortAsString(String) the first time will assign a specific port in that range with the name provided, and calling one of those two methods with that name will return the same port number afterwards.
  • Constructor Details

    • PortFinder

      public PortFinder()
      Default constructor. Finds and reserves a range of ports.
  • Method Details

    • getPort

      public int getPort(String portKey)
      Gets the port number associated with the key provided. Assigns a new port number if the key couldn't be found.
      Parameters:
      portKey - key of the port to look up
      Returns:
      port number associated with the key provided
    • getPortAsString

      public String getPortAsString(String portKey)
      Gets the port number associated with the key provided as a string. Assigns a new port number if the key couldn't be found.
      Parameters:
      portKey - key of the port to look up
      Returns:
      port number associated with the key provided
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException