Skip to content

Commit

Permalink
Fixed bug when the Language Server us stop()-ed by Eclipse, and then …
Browse files Browse the repository at this point in the history
…later start()-ed
  • Loading branch information
ddekany committed Mar 28, 2018
1 parent 27de372 commit a266b41
Showing 1 changed file with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public abstract class LocalStreamConnectionProvider implements StreamConnectionP

private static final int PIPE_BUFFER_SIZE = 8192;

private final PipedOutputStream clientToServerStream = new PipedOutputStream();
private final PipedInputStream serverToClientStream = new PipedInputStream(PIPE_BUFFER_SIZE);
private PipedOutputStream clientToServerStream;
private PipedInputStream serverToClientStream;
private PipedInputStream clientToServerStreamReverse;
private PipedOutputStream serverToClientStreamReverse;

private Future<?> launched;

Expand All @@ -36,7 +38,11 @@ public LocalStreamConnectionProvider() {

@Override
public synchronized void start() throws IOException {
launched = launch(new PipedInputStream(clientToServerStream, PIPE_BUFFER_SIZE), new PipedOutputStream(serverToClientStream));
clientToServerStream = new PipedOutputStream();
serverToClientStream = new PipedInputStream(PIPE_BUFFER_SIZE);
clientToServerStreamReverse = new PipedInputStream(clientToServerStream, PIPE_BUFFER_SIZE);
serverToClientStreamReverse = new PipedOutputStream(serverToClientStream);
launched = launch(clientToServerStreamReverse, serverToClientStreamReverse);
}

protected abstract Future<?> launch(InputStream clientToServerStream, OutputStream serverToClientStream) throws IOException;
Expand All @@ -58,8 +64,43 @@ public InputStream getErrorStream() {

@Override
public synchronized void stop() {
// TODO Not sure if it works like this...
launched.cancel(true);
if (launched != null) {
// TODO Not sure if it works like this...
launched.cancel(true);
launched = null;

try {
clientToServerStream.close();
} catch (IOException e) {
// TODO Log
e.printStackTrace();
}
clientToServerStream = null;

try {
clientToServerStreamReverse.close();
} catch (IOException e) {
// TODO Log
e.printStackTrace();
}
clientToServerStreamReverse = null;

try {
serverToClientStreamReverse.close();
} catch (IOException e) {
// TODO Log
e.printStackTrace();
}
serverToClientStreamReverse = null;

try {
serverToClientStream.close();
} catch (IOException e) {
// TODO Log
e.printStackTrace();
}
serverToClientStream = null;
}
}

}

0 comments on commit a266b41

Please sign in to comment.