/** * Find the requested number of available TCP ports, each randomly selected * from the range [{@value #PORT_RANGE_MIN}, {@value #PORT_RANGE_MAX}]. * @param numRequested the number of available ports to find * @return a sorted set of available TCP port numbers * @throws IllegalStateException if the requested number of available ports could not be found */ public static SortedSet<Integer> findAvailableTcpPorts(int numRequested) { return findAvailableTcpPorts(numRequested, PORT_RANGE_MIN, PORT_RANGE_MAX); }
/** * Find the requested number of available TCP ports, each randomly selected * from the range [{@value #PORT_RANGE_MIN}, {@value #PORT_RANGE_MAX}]. * @param numRequested the number of available ports to find * @return a sorted set of available TCP port numbers * @throws IllegalStateException if the requested number of available ports could not be found */ public static SortedSet<Integer> findAvailableTcpPorts(int numRequested) { return findAvailableTcpPorts(numRequested, PORT_RANGE_MIN, PORT_RANGE_MAX); }
private void findAvailableTcpPorts(int numRequested) { SortedSet<Integer> ports = SocketUtils.findAvailableTcpPorts(numRequested); assertAvailablePorts(ports, numRequested, PORT_RANGE_MIN, PORT_RANGE_MAX); }
private void findAvailableTcpPorts(int numRequested, int minPort, int maxPort) { SortedSet<Integer> ports = SocketUtils.findAvailableTcpPorts(numRequested, minPort, maxPort); assertAvailablePorts(ports, numRequested, minPort, maxPort); }
/** * Find the requested number of available TCP ports, each randomly selected * from the range [{@value #PORT_RANGE_MIN}, {@value #PORT_RANGE_MAX}]. * @param numRequested the number of available ports to find * @return a sorted set of available TCP port numbers * @throws IllegalStateException if the requested number of available ports could not be found */ public static SortedSet<Integer> findAvailableTcpPorts(int numRequested) { return findAvailableTcpPorts(numRequested, PORT_RANGE_MIN, PORT_RANGE_MAX); }
/** * Find the requested number of available TCP ports, each randomly selected * from the range [{@value #PORT_RANGE_MIN}, {@value #PORT_RANGE_MAX}]. * @param numRequested the number of available ports to find * @return a sorted set of available TCP port numbers * @throws IllegalStateException if the requested number of available ports could not be found */ public static SortedSet<Integer> findAvailableTcpPorts(int numRequested) { return findAvailableTcpPorts(numRequested, PORT_RANGE_MIN, PORT_RANGE_MAX); }
int randomInt = ThreadLocalRandom.current().nextInt(20000, 61000); try { availPorts = SocketUtils.findAvailableTcpPorts(5, randomInt, randomInt + 5); try {