public final class SocketUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PORT_RANGE_MAX |
static int |
DEFAULT_PORT_RANGE_MIN |
Constructor and Description |
---|
SocketUtils()
The constructor is intentionally public.
|
Modifier and Type | Method and Description |
---|---|
static int |
findAvailableServerSocket()
Determines a free available server socket (port) using an automatically
chosen start seed port.
|
static int |
findAvailableServerSocket(int seed)
Determines a free available server socket (port) using the 'seed' value as
the starting port.
|
static List<Integer> |
findAvailableServerSockets(int seed,
int numberOfRequestedPorts)
Determines a free available server socket (port) using the 'seed' value as
the starting port.
|
static int |
findAvailableUdpSocket()
Determines a free available Udp socket using an automatically
chosen start seed port.
|
static int |
findAvailableUdpSocket(int seed)
Determines a free available Udp socket (port) using the 'seed' value as
the starting port.
|
static List<Integer> |
findAvailableUdpSockets(int seed,
int numberOfRequestedPorts)
Determines free available udp socket(s) (port) using the 'seed' value as
the starting port.
|
static int |
getRandomSeedPort()
|
public static final int DEFAULT_PORT_RANGE_MIN
public static final int DEFAULT_PORT_RANGE_MAX
public SocketUtils()
...port="#{T(org.springframework.integration.test.util.SocketUtils).findAvailableServerSocket(12000)}"
But unfortunately, you would need to repeat the package for each usage.
This will be acceptable for single use, but if you need to invoke the
methods numerous time, you may instead want to do this:
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
...port="#{tcpIpUtils.findAvailableServerSocket(12000)}"
public static int findAvailableServerSocket(int seed)
seed
- The starting port, which must not be negative.IllegalStateException
- when no open port was found.public static List<Integer> findAvailableServerSockets(int seed, int numberOfRequestedPorts)
seed
- The starting port, which must not be negative.numberOfRequestedPorts
- How many open ports shall be retrieved?IllegalStateException
- when no open port was found.public static int findAvailableServerSocket()
IllegalStateException
- when no open port was found.public static int findAvailableUdpSocket(int seed)
seed
- The starting port, which must not be negative.IllegalStateException
- when no open port was found.public static List<Integer> findAvailableUdpSockets(int seed, int numberOfRequestedPorts)
seed
- The starting port, which must not be negative.numberOfRequestedPorts
- How many open ports shall be retrieved?IllegalStateException
- when no open port was found.public static int findAvailableUdpSocket()
IllegalStateException
- when no open port was found.public static int getRandomSeedPort()