<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.emf.codegen</groupId>
<artifactId>ecore</artifactId>
<version>2.35.0.v20230801-1141</version>
<description>POM was created from install:install-file</description>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>org.eclipse.emf.codegen</groupId>
<artifactId>ecore</artifactId>
<versioning>
<release>2.35.0.v20230801-1141</release>
<versions>
<version>2.35.0.v20230801-1141</version>
</versions>
<lastUpdated>20240318162310</lastUpdated>
</versioning>
</metadata>
fd330dd06e1a84d440dfd08a6b7d209be50a60a4
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>org.eclipse.emf</groupId>
<artifactId>codegen</artifactId>
<versioning>
<release>2.23.0.v20230211-1150</release>
<versions>
<version>2.23.0.v20230211-1150</version>
</versions>
<lastUpdated>20240318162313</lastUpdated>
</versioning>
</metadata>
c518194b04bda554c52d21a98b9515fe0b78d1f7
\ No newline at end of file
package org.etsi.mts.tdl.web;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.Channels;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.function.Function;
import org.eclipse.lsp4j.jsonrpc.JsonRpcException;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
import org.eclipse.lsp4j.jsonrpc.MessageIssueException;
import org.eclipse.lsp4j.jsonrpc.messages.Message;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.xtext.ide.server.LanguageServerImpl;
import org.eclipse.xtext.ide.server.ServerModule;
import org.etsi.mts.tdl.helper.TDLHelper;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author dietrich - Initial contribution and API
*/
public class RunServer {
public static void main(String[] args) throws InterruptedException, IOException {
TDLHelper.init();
Injector injector = Guice.createInjector(new ServerModule());
LanguageServerImpl languageServer = injector.getInstance(LanguageServerImpl.class);
Function<MessageConsumer, MessageConsumer> wrapper = consumer -> {
MessageConsumer result = new MessageConsumer() {
@Override
public void consume(Message message) throws MessageIssueException, JsonRpcException {
System.out.println(message);
consumer.consume(message);
}
};
return result;
};
Launcher<LanguageClient> launcher = createSocketLauncher(languageServer, LanguageClient.class, new InetSocketAddress("localhost", 5007), Executors.newCachedThreadPool(), wrapper);
languageServer.connect(launcher.getRemoteProxy());
Future<?> future = launcher.startListening();
while (!future.isDone()) {
Thread.sleep(10_000l);
}
}
static <T> Launcher<T> createSocketLauncher(Object localService, Class<T> remoteInterface, SocketAddress socketAddress, ExecutorService executorService, Function<MessageConsumer, MessageConsumer> wrapper) throws IOException {
AsynchronousServerSocketChannel serverSocket = AsynchronousServerSocketChannel.open().bind(socketAddress);
AsynchronousSocketChannel socketChannel;
try {
socketChannel = serverSocket.accept().get();
return Launcher.createIoLauncher(localService, remoteInterface, Channels.newInputStream(socketChannel), Channels.newOutputStream(socketChannel), executorService, wrapper);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return null;
}
}
\ No newline at end of file