Search in sources :

Example 1 with UcxException

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;
}
Also used : Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) Random(java.util.Random) InetSocketAddress(java.net.InetSocketAddress) UcpListener(org.openucx.jucx.ucp.UcpListener) UcpListenerParams(org.openucx.jucx.ucp.UcpListenerParams) UcpEndpoint(org.openucx.jucx.ucp.UcpEndpoint) UcxException(org.openucx.jucx.UcxException)

Aggregations

Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)1 InetSocketAddress (java.net.InetSocketAddress)1 Random (java.util.Random)1 UcxException (org.openucx.jucx.UcxException)1 UcpEndpoint (org.openucx.jucx.ucp.UcpEndpoint)1 UcpListener (org.openucx.jucx.ucp.UcpListener)1 UcpListenerParams (org.openucx.jucx.ucp.UcpListenerParams)1