Class PortAllocationManager
java.lang.Object
org.jvnet.hudson.plugins.port_allocator.PortAllocationManager
Manages ports in use.
- Author:
- Rama Pulavarthi, Kohsuke Kawaguchi
-
Method Summary
Modifier and TypeMethodDescriptionint
allocate
(AbstractBuild owner, int port) Assigns the requested port.int[]
allocatePortRange
(AbstractBuild owner, int start, int end, int count, boolean isConsecutive) Allocate a continuous range of ports within specified limits.int
allocateRandom
(AbstractBuild owner, int prefPort) Allocates a random port on the Computer where the jobs gets executed.void
free
(int n) static PortAllocationManager
getManager
(Computer node) boolean
isFree
(int port)
-
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 buildstart
- first port in the range of allowable portsend
- the last entry in the range of allowable portscount
- the number of ports to allocateisConsecutive
- true if the allocated ports should be consecutive- Returns:
- the ports allocated
- Throws:
InterruptedException
- if the allocation was interruptedIOException
- if the allocation failed
-
allocate
Assigns the requested port. This method blocks until the port becomes available.- Throws:
InterruptedException
IOException
-
isFree
public boolean isFree(int port) -
getManager
-
free
public void free(int n)
-