This commit is contained in:
Egor.Ushakov
2016-05-24 20:45:46 +03:00
parent 1a8dc9e470
commit 0469379207
@@ -146,8 +146,7 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{
}
@Override
public String findAvailableDebugAddress(final boolean useSockets) throws ExecutionException {
final TransportServiceWrapper transportService = TransportServiceWrapper.getTransportService(useSockets);
public String findAvailableDebugAddress(boolean useSockets) throws ExecutionException {
if (useSockets) {
final int freePort;
try {
@@ -158,31 +157,34 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{
}
return Integer.toString(freePort);
}
try {
TransportService.ListenKey listenKey = transportService.startListening();
final String address = listenKey.address();
transportService.stopListening(listenKey);
return address;
}
catch (IOException e) {
int tryNum = 0;
while (true) {
try {
TransportService.ListenKey listenKey = transportService.startListening("javadebug_" + (int)(Math.random()*1000));
final String address = listenKey.address();
transportService.stopListening(listenKey);
return address;
}
catch (Exception ex) {
if (tryNum++ > 10) {
throw new ExecutionException(DebugProcessImpl.processError(ex));
else {
TransportServiceWrapper transportService = TransportServiceWrapper.getTransportService(false);
try {
return tryShmemConnect(transportService, null);
}
catch (IOException e) {
int tryNum = 0;
while (true) {
try {
return tryShmemConnect(transportService, "javadebug_" + (int)(Math.random() * 1000));
}
catch (Exception ex) {
if (tryNum++ > 10) {
throw new ExecutionException(DebugProcessImpl.processError(ex));
}
}
}
}
}
}
private static String tryShmemConnect(TransportServiceWrapper transportService, String address) throws IOException {
TransportService.ListenKey listenKey = transportService.startListening(address);
address = listenKey.address();
transportService.stopListening(listenKey);
return address;
}
public static boolean isRemote(DebugProcess debugProcess) {
return Boolean.TRUE.equals(debugProcess.getUserData(BatchEvaluator.REMOTE_SESSION_KEY));
}