Commit ddbf92e1 authored by Adrien's avatar Adrien Committed by Romain Bioteau

fix(launch) avoid errors when launching several Studio on macos (#1813)


[BST-417](https://bonitasoft.atlassian.net/browse/BST-417)
parent c8147204
......@@ -67,7 +67,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jdt.core,
org.eclipse.e4.ui.workbench,
org.bonitasoft.studio.ui,
org.eclipse.core.expressions
org.eclipse.core.expressions,
org.eclipse.wst.server.core;bundle-version="1.10.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: org.bonitasoft.engine.bpm.bar,
......
......@@ -19,11 +19,12 @@ import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
......@@ -254,16 +255,16 @@ public class UIDesignerServerManager implements IBonitaProjectListener {
"-httpPort",
String.valueOf(port));
}
private String getProductApplicationId() {
return Platform.getProduct() != null ? Platform.getProduct().getApplication() : null;
}
private static boolean isPortAvailable(int port) {
try (Socket ignored = new Socket("localhost", port)) {
return false;
} catch (IOException ignored) {
return true;
try {
return org.eclipse.wst.server.core.util.SocketUtil.isPortInUse(InetAddress.getByName("localhost"), port);
} catch (UnknownHostException e) {
return org.eclipse.wst.server.core.util.SocketUtil.isPortInUse(port);
}
}
......
......@@ -18,6 +18,8 @@ import static com.google.common.collect.Iterators.forArray;
import static com.google.common.collect.Maps.uniqueIndex;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
......@@ -128,7 +130,11 @@ public class PortConfigurator {
}
protected boolean isPortInUse(final int port) {
return SocketUtil.isPortInUse(port);
try {
return SocketUtil.isPortInUse(InetAddress.getByName("localhost"), port);
} catch (UnknownHostException e) {
return SocketUtil.isPortInUse(port);
}
}
protected int findUnusedPort(final int low, final int hight) {
......
......@@ -5,12 +5,10 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
......@@ -55,9 +53,10 @@ public class WatchdogManager {
@Override
public void run() {
try {
if (SocketUtil.isPortInUse(WATCHDOG_PORT)) {
if (portIsUsed()) {
final int oldPort = WATCHDOG_PORT;
WATCHDOG_PORT = SocketUtil.findUnusedPort(PortConfigurator.MIN_PORT_NUMBER, PortConfigurator.MAX_PORT_NUMBER);
WATCHDOG_PORT = SocketUtil.findUnusedPort(PortConfigurator.MIN_PORT_NUMBER,
PortConfigurator.MAX_PORT_NUMBER);
BonitaStudioLog.debug("Port "
+ oldPort
+ " is not available for server watchdog, studio will use next available port : "
......@@ -86,6 +85,14 @@ public class WatchdogManager {
}
}
private boolean portIsUsed() {
try {
return SocketUtil.isPortInUse(InetAddress.getByName("localhost"), WATCHDOG_PORT);
} catch (UnknownHostException e) {
return SocketUtil.isPortInUse(WATCHDOG_PORT);
}
}
protected void logErrorDuringWatchDogUsage(final IOException e) {
BonitaStudioLog.error("Exception during Watchdog usage.", e, EnginePlugin.PLUGIN_ID);
}
......@@ -117,7 +124,8 @@ public class WatchdogManager {
i++;
}
if (i == 100 && watchdogServer == null) {
BonitaStudioLog.error("Watchdog server wasn't able to start in less than 5 seconds. It may lead to issue.", EnginePlugin.PLUGIN_ID);
BonitaStudioLog.error("Watchdog server wasn't able to start in less than 5 seconds. It may lead to issue.",
EnginePlugin.PLUGIN_ID);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment