private int regeneratePortNumber(String myInstallation) { if (!regeneratePortNumbersOnClash) { throw new RuntimeException("Port number already assigned to another installation."); } properties.removeInstallationPort(myInstallation); int portNumber = properties.calculateNextPortNumber(); properties.setInstallationPort(myInstallation, portNumber); return portNumber; }
public int getPortNumberForInstallation(String myInstallation) { String installationPortNumberString = properties.getInstallationPort(myInstallation); if (installationPortNumberString == null) { int portNumber = properties.calculateNextPortNumber(); properties.setInstallationPort(myInstallation, portNumber); return portNumber; } else { if (!properties.isPortNumberUnique(myInstallation, installationPortNumberString)) { return regeneratePortNumber(myInstallation); } else { return Integer.parseInt(installationPortNumberString); } } }