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

redis.embedded.ports.EphemeralPortProvider Maven / Gradle / Ivy

There is a newer version: 0.11.0
Show newest version
package redis.embedded.ports;

import redis.embedded.PortProvider;
import redis.embedded.exceptions.RedisBuildingException;

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

/**
 * Created by piotrturek on 29/01/15.
 */
public class EphemeralPortProvider implements PortProvider {
    @Override
    public int next() {
        try {
            final ServerSocket socket = new ServerSocket(0);
            socket.setReuseAddress(false);
            int port = socket.getLocalPort();
            socket.close();
            return port;
        } catch (IOException e) {
            //should not ever happen
            throw new RedisBuildingException("Could not provide ephemeral port", e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy