mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-7987
This commit is contained in:
+7
-3
@@ -43,7 +43,7 @@ public abstract class SocketConnectionBase<Request extends AbstractRequest, Resp
|
||||
private final AtomicReference<ConnectionState> myState = new AtomicReference<ConnectionState>(new ConnectionState(ConnectionStatus.NOT_CONNECTED));
|
||||
private boolean myStopping;
|
||||
private final EventDispatcher<SocketConnectionListener> myDispatcher = EventDispatcher.create(SocketConnectionListener.class);
|
||||
private List<Thread> myThreadsToInterrupt = new ArrayList<Thread>();
|
||||
private final List<Thread> myThreadsToInterrupt = new ArrayList<Thread>();
|
||||
private final RequestResponseExternalizerFactory<Request, Response> myExternalizerFactory;
|
||||
private final LinkedBlockingQueue<Request> myRequests = new LinkedBlockingQueue<Request>();
|
||||
private final TIntObjectHashMap<TimeoutInfo> myTimeouts = new TIntObjectHashMap<TimeoutInfo>();
|
||||
@@ -122,10 +122,12 @@ public abstract class SocketConnectionBase<Request extends AbstractRequest, Resp
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
LOG.debug("Firefox connection disposed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return myPort;
|
||||
}
|
||||
@@ -137,6 +139,7 @@ public abstract class SocketConnectionBase<Request extends AbstractRequest, Resp
|
||||
myDispatcher.getMulticaster().statusChanged(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ConnectionState getState() {
|
||||
synchronized (myLock) {
|
||||
@@ -144,6 +147,7 @@ public abstract class SocketConnectionBase<Request extends AbstractRequest, Resp
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(@NotNull SocketConnectionListener listener, @Nullable Disposable parentDisposable) {
|
||||
if (parentDisposable != null) {
|
||||
myDispatcher.addListener(listener, parentDisposable);
|
||||
@@ -188,8 +192,8 @@ public abstract class SocketConnectionBase<Request extends AbstractRequest, Resp
|
||||
}
|
||||
|
||||
private static class TimeoutInfo {
|
||||
private int myTimeout;
|
||||
private Runnable myOnTimeout;
|
||||
private final int myTimeout;
|
||||
private final Runnable myOnTimeout;
|
||||
|
||||
private TimeoutInfo(int timeout, Runnable onTimeout) {
|
||||
myTimeout = timeout;
|
||||
|
||||
+13
-2
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -49,6 +50,7 @@ public class SocketConnectionImpl<Request extends AbstractRequest, Response exte
|
||||
final Socket socket = createSocket();
|
||||
setPort(socket.getPort());
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
attachToSocket(socket);
|
||||
@@ -63,7 +65,16 @@ public class SocketConnectionImpl<Request extends AbstractRequest, Response exte
|
||||
|
||||
@NotNull
|
||||
private Socket createSocket() throws IOException {
|
||||
final InetAddress host = myHost != null ? myHost : InetAddress.getLocalHost();
|
||||
InetAddress host = myHost;
|
||||
if (host == null) {
|
||||
try {
|
||||
host = InetAddress.getLocalHost();
|
||||
}
|
||||
catch (UnknownHostException ignored) {
|
||||
host = InetAddress.getByName(null);
|
||||
}
|
||||
}
|
||||
|
||||
IOException exc = null;
|
||||
for (int i = 0; i < myPortsNumberToTry; i++) {
|
||||
int port = myInitialPort + i;
|
||||
@@ -98,7 +109,7 @@ public class SocketConnectionImpl<Request extends AbstractRequest, Response exte
|
||||
//noinspection BusyWait
|
||||
Thread.sleep(CONNECTION_ATTEMPT_DELAY);
|
||||
}
|
||||
setStatus(ConnectionStatus.CONNECTION_FAILED, "Cannot connect to " + myHost + ", the maximum number of connection attempts exceeded");
|
||||
setStatus(ConnectionStatus.CONNECTION_FAILED, "Cannot connect to " + (myHost != null ? myHost : "localhost") + ", the maximum number of connection attempts exceeded");
|
||||
}
|
||||
catch (InterruptedException ignored) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user