All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mikesafonov.smpp.server.Utils Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package com.github.mikesafonov.smpp.server;

import lombok.experimental.UtilityClass;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.UUID;

/**
 * @author Mike Safonov
 */
@UtilityClass
public class Utils {
    static int checkPortOrGetFree(int port) {
        if (port == MockSmppServer.RANDOM_PORT) {
            return findRandomOpenPortOnAllLocalInterfaces();
        } else {
            return port;
        }
    }

    static String randomUuidName() {
        return UUID.randomUUID().toString();
    }

    static synchronized Integer findRandomOpenPortOnAllLocalInterfaces() {
        try (ServerSocket socket = new ServerSocket(0)) {
            return socket.getLocalPort();
        } catch (IOException e) {
            throw new RuntimeException("Unable to find port", e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy