public class PortHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
ADDRESS_ALREADY_IN_USE |
static long |
MAX_RETRY_MS |
static long |
THROTTLE_MS |
static String |
UNRECOGNIZED_SOCKET |
| Constructor and Description |
|---|
PortHelper() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
addressAlreadyInUse(Throwable t)
Returns true if a cause of the given (non-null) exception is a
BindException with message containing
ADDRESS_ALREADY_IN_USE. |
static int |
getRandomPort()
Selects a random port not already in use on the local host.
|
static boolean |
reservePort(String host,
int port) |
static boolean |
retrySocketBind(IOException e,
long startTimeMs)
Answers whether the caller should retry the operation that threw
the given IOException.
|
public static final String ADDRESS_ALREADY_IN_USE
public static final String UNRECOGNIZED_SOCKET
public static final long MAX_RETRY_MS
public static final long THROTTLE_MS
public static int getRandomPort()
public static boolean reservePort(String host, int port)
public static boolean retrySocketBind(IOException e, long startTimeMs)
addressAlreadyInUse(Throwable) and the retry limit of
MAX_RETRY_MS ms has not been exceeded.
The method first logs network statistics to help diagnose the exception,
regardless of its cause. It also throttles for THROTTLE_MS ms
before returning true.
public static boolean addressAlreadyInUse(Throwable t)
ADDRESS_ALREADY_IN_USE.
or a SocketException with message containing UNRECOGNIZED_SOCKET.Copyright © 2010-2015 Pivotal Software, Inc. All rights reserved.