Package org.mockserver.socket
Class PortFactory
- java.lang.Object
-
- org.mockserver.socket.PortFactory
-
public class PortFactory extends Object
- Author:
- jamesdbloom
-
-
Constructor Summary
Constructors Constructor Description PortFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intfindFreePort()static int[]findFreePorts(int count)Find multiple free ports.
-
-
-
Method Detail
-
findFreePort
public static int findFreePort()
-
findFreePorts
public static int[] findFreePorts(int count)
Find multiple free ports. Ports are selected from a larger pool of recently-available ports to reduce the chance of collisions. Callers should handleBindExceptionas the returned ports may be claimed by another process before the caller binds them.- Parameters:
count- the number of free ports to find (must be between 1 and 1000 inclusive)- Returns:
- an array of
countdistinct port numbers that were recently free - Throws:
IllegalArgumentException- if count is not between 1 and 1000
-
-