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

sirius.kernel.settings.PortMapper Maven / Gradle / Ivy

Go to download

Provides common core classes and the microkernel powering all Sirius applications

There is a newer version: 12.9.1
Show newest version
/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - [email protected]
 */

package sirius.kernel.settings;

import sirius.kernel.commons.Tuple;
import sirius.kernel.health.Exceptions;

/**
 * Maps a given destination port to the effective port assigned.
 * 

* This is mainly used in test environments where we provision external * dependencies via docker composer. As docker assigns a more or less * random port per test run, we need to determine and assign this. *

* As we do not want a production dependency against docker, we * use this bridge class and provide an appropriate implementation * as DockerHelper in the test scope. */ public abstract class PortMapper { private static PortMapper mapper; /** * Determines which port mapper to use. * * @param mapper the mapper to use. */ public static void setMapper(PortMapper mapper) { PortMapper.mapper = mapper; } /** * Maps the given port for the given service. * * @param service the service used to identify to container which provides the service * @param host the host to map * @param port the port to map * @return the mapped port number or port if no mapper is present. */ public static Tuple mapPort(String service, String host, int port) { if (mapper == null) { return Tuple.create(host, port); } try { return mapper.map(service, host, port); } catch (Exception e) { Exceptions.ignore(e); return Tuple.create(host, port); } } /** * Maps the given port for the given service. * * @param service the service used to identify to container which provides the service * @param host the host to map * @param port the port to map * @return the mapped port number or port if no mapping is present. */ protected abstract Tuple map(String service, String host, int port); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy