Search in sources :

Example 1 with MessageJsonHandler

use of org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler in project ballerina by ballerina-lang.

the class BallerinaLangServerService method launchRPCServer.

private <T> Launcher<T> launchRPCServer(Object localService, Class<T> remoteInterface) {
    Consumer<GsonBuilder> configureGson = (gsonBuilder) -> {
    };
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap();
    supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(remoteInterface));
    if (localService instanceof JsonRpcMethodProvider) {
        JsonRpcMethodProvider rpcMethodProvider = (JsonRpcMethodProvider) localService;
        supportedMethods.putAll(rpcMethodProvider.supportedMethods());
    } else {
        supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(localService.getClass()));
    }
    MessageJsonHandler jsonHandler = new MessageJsonHandler(supportedMethods, configureGson);
    MessageConsumer outGoingMessageStream = new WSRPCMessageConsumer(this, jsonHandler);
    RemoteEndpoint serverEndpoint = new RemoteEndpoint(outGoingMessageStream, ServiceEndpoints.toEndpoint(localService));
    jsonHandler.setMethodProvider(serverEndpoint);
    final MessageConsumer messageConsumer = serverEndpoint;
    final MessageProducer reader = new WSRPCMessageProducer(this, jsonHandler);
    final T remoteProxy = ServiceEndpoints.toServiceObject(serverEndpoint, remoteInterface);
    return new Launcher<T>() {

        public Future<?> startListening() {
            return ConcurrentMessageProcessor.startProcessing(reader, messageConsumer, Executors.newCachedThreadPool());
        }

        public T getRemoteProxy() {
            return remoteProxy;
        }
    };
}
Also used : ConcurrentMessageProcessor(org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor) LanguageClient(org.eclipse.lsp4j.services.LanguageClient) OnError(javax.websocket.OnError) CloseReason(javax.websocket.CloseReason) OnMessage(javax.websocket.OnMessage) LoggerFactory(org.slf4j.LoggerFactory) Constants(org.ballerinalang.composer.service.ballerina.langserver.Constants) MessageProducer(org.eclipse.lsp4j.jsonrpc.MessageProducer) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OnOpen(javax.websocket.OnOpen) ComposerService(org.ballerinalang.composer.server.spi.ComposerService) Future(java.util.concurrent.Future) OnClose(javax.websocket.OnClose) Map(java.util.Map) LinkedList(java.util.LinkedList) Launcher(org.eclipse.lsp4j.jsonrpc.Launcher) ServiceType(org.ballerinalang.composer.server.spi.ServiceType) Logger(org.slf4j.Logger) Session(javax.websocket.Session) ServiceEndpoints(org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints) MessageJsonHandler(org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler) IOException(java.io.IOException) ServerEndpoint(javax.websocket.server.ServerEndpoint) MessageConsumer(org.eclipse.lsp4j.jsonrpc.MessageConsumer) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) List(java.util.List) ServerConstants(org.ballerinalang.composer.server.core.ServerConstants) JsonRpcMethod(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod) ServiceInfo(org.ballerinalang.composer.server.spi.ServiceInfo) JsonRpcMethodProvider(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethodProvider) BallerinaLanguageServer(org.ballerinalang.langserver.BallerinaLanguageServer) RemoteEndpoint(org.eclipse.lsp4j.jsonrpc.RemoteEndpoint) JsonRpcMethodProvider(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethodProvider) MessageConsumer(org.eclipse.lsp4j.jsonrpc.MessageConsumer) MessageJsonHandler(org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler) GsonBuilder(com.google.gson.GsonBuilder) RemoteEndpoint(org.eclipse.lsp4j.jsonrpc.RemoteEndpoint) LinkedHashMap(java.util.LinkedHashMap) JsonRpcMethod(org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod) Launcher(org.eclipse.lsp4j.jsonrpc.Launcher) MessageProducer(org.eclipse.lsp4j.jsonrpc.MessageProducer)

Aggregations

GsonBuilder (com.google.gson.GsonBuilder)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 Consumer (java.util.function.Consumer)1 CloseReason (javax.websocket.CloseReason)1 OnClose (javax.websocket.OnClose)1 OnError (javax.websocket.OnError)1 OnMessage (javax.websocket.OnMessage)1 OnOpen (javax.websocket.OnOpen)1 Session (javax.websocket.Session)1 ServerEndpoint (javax.websocket.server.ServerEndpoint)1 ServerConstants (org.ballerinalang.composer.server.core.ServerConstants)1 ComposerService (org.ballerinalang.composer.server.spi.ComposerService)1