use of org.openucx.jucx.UcxException in project twister2 by DSC-SPIDAL.
the class TWSUCXChannel method createUcpListener.
/**
* create a UcpListener on a random port between 15k and 65k
* if a chosen port is taken, try other random ports
* @param ucpWorker
* @param wIP
* @return
*/
private static UcpListener createUcpListener(UcpWorker ucpWorker, InetAddress wIP) {
Random rg = new Random();
UcpListenerParams ucpListenerParams = new UcpListenerParams();
int tryCount = 0;
int maxTryCount = 10;
while (tryCount++ < maxTryCount) {
// generate random port numbers in the range of 15k to 65k
int port = rg.nextInt(40000) + 15000;
ucpListenerParams.setSockAddr(new InetSocketAddress(wIP.getHostAddress(), port));
try {
UcpListener ucpListener = ucpWorker.newListener(ucpListenerParams);
return ucpListener;
} catch (UcxException ucxException) {
if (tryCount == maxTryCount) {
throw new Twister2RuntimeException(ucxException);
}
}
}
return null;
}
Aggregations