use of org.eclipse.lsp4j.jsonrpc.RemoteEndpoint 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;
}
};
}
Aggregations