Class PortAllocationManager

java.lang.Object
org.jvnet.hudson.plugins.port_allocator.PortAllocationManager

public final class PortAllocationManager extends Object
Manages ports in use.
Author:
Rama Pulavarthi, Kohsuke Kawaguchi
  • Method Details

    • allocateRandom

      public int allocateRandom(AbstractBuild owner, int prefPort) throws InterruptedException, IOException
      Allocates a random port on the Computer where the jobs gets executed.

      If the preferred port is not available, assigns a random available port.

      Parameters:
      prefPort - Preffered port. This method trys to assign this port, and upon failing, fall back to assigning a random port.
      Throws:
      InterruptedException
      IOException
    • allocatePortRange

      public int[] allocatePortRange(AbstractBuild owner, int start, int end, int count, boolean isConsecutive) throws InterruptedException, IOException
      Allocate a continuous range of ports within specified limits. The caller is responsible for freeing the individual ports within the allocated range.
      Parameters:
      owner - current build
      start - first port in the range of allowable ports
      end - the last entry in the range of allowable ports
      count - the number of ports to allocate
      isConsecutive - true if the allocated ports should be consecutive
      Returns:
      the ports allocated
      Throws:
      InterruptedException - if the allocation was interrupted
      IOException - if the allocation failed
    • allocate

      public int allocate(AbstractBuild owner, int port) throws InterruptedException, IOException
      Assigns the requested port. This method blocks until the port becomes available.
      Throws:
      InterruptedException
      IOException
    • isFree

      public boolean isFree(int port)
    • getManager

      public static PortAllocationManager getManager(Computer node)
    • free

      public void free(int n)