Closed mickaelistria closed 8 years ago
@mickaelistria Do you use ConcurrentMessageReader or plain StreamMessageReader?
Plain StreamMessageReader. But I coul duse the ConcurrentMessageReader if that's better for background work. Do you have an example? What value should be given to ExecutorService?
@mickaelistria new ConcurrentMessageReader(new StreamMessageReader(...), executorService))
yeah, my question was more what is a good value to pass as executor service?
Currently it let you use the same executor service for LanguageClientEndpoint and ConcurrentMessageReader. There could be some factory that does it for you. But it cannot not be a part of LanguageClientEndpoint, since generally there can be clients which don't want non-blocking behaviour. For example for web sockets one can provide a special reader which is called on a message event and just delegates to the steam reader.
Here is how I've implemented it:
ExecutorService executorService = Executors.newCachedThreadPool();
this.languageClient = new LanguageClientEndpoint(executorService);
this.lspStreamProvider.start();
MessageJsonHandler jsonHandler = new MessageJsonHandler();
jsonHandler.setMethodResolver(this.languageClient);
MessageReader reader = new ConcurrentMessageReader(new StreamMessageReader(this.lspStreamProvider.getInputStream(), jsonHandler), executorService);
MessageWriter writer = new StreamMessageWriter(this.lspStreamProvider.getOutputStream(), jsonHandler);
languageClient.connect(reader, writer);
It seems like LanguageClientEndpoint.connect() is now a blocking operation, which requires to be started in a separate thread/job. This is not the usual way for a connect(..) method and not the way it used to work with previous versions of ls-api. Most example of connect(...) I have in mind are non-blocking and responsible of setting up the necessary threads, returning a connection object that can allow to join on some operations.