use of org.yamcs.api.WebSocketTopic in project yamcs by yamcs.
the class HttpServer method addApi.
public void addApi(Api<Context> api) {
apis.add(api);
for (MethodDescriptor method : api.getDescriptorForType().getMethods()) {
RpcDescriptor descriptor = protobufRegistry.getRpc(method.getFullName());
if (descriptor == null) {
throw new UnsupportedOperationException("Unable to find rpc definition: " + method.getFullName());
}
if (WEBSOCKET_ROUTE.equals(descriptor.getHttpRoute())) {
topics.add(new Topic(api, descriptor.getWebSocketTopic(), descriptor));
for (WebSocketTopic topic : descriptor.getAdditionalWebSocketTopics()) {
topics.add(new Topic(api, topic, descriptor));
}
} else {
routes.add(new Route(api, descriptor.getHttpRoute(), descriptor, metricRegistry));
for (HttpRoute route : descriptor.getAdditionalHttpRoutes()) {
routes.add(new Route(api, route, descriptor, metricRegistry));
}
}
}
// Regenerate JSON converters with type support (needed for the "Any" type)
TypeRegistry.Builder typeRegistryb = TypeRegistry.newBuilder();
typeRegistryb.add(CancelOptions.getDescriptor());
typeRegistryb.add(Reply.getDescriptor());
apis.forEach(a -> typeRegistryb.add(a.getDescriptorForType().getFile().getMessageTypes()));
TypeRegistry typeRegistry = typeRegistryb.build();
jsonParser = JsonFormat.parser().usingTypeRegistry(typeRegistry);
jsonPrinter = JsonFormat.printer().usingTypeRegistry(typeRegistry);
// Sort in a way that increases chances of a good URI match
Collections.sort(routes);
}
use of org.yamcs.api.WebSocketTopic in project yamcs by yamcs.
the class ProtobufRegistry method importDefinitions.
public void importDefinitions(InputStream in) throws IOException {
if (in == null) {
throw new NullPointerException("input stream cannot be null");
}
FileDescriptorSet proto = FileDescriptorSet.parseFrom(in, extensionRegistry);
// Index all messages by fully-qualified protobuf name
for (FileDescriptorProto file : proto.getFileList()) {
scanComments(file);
String javaPackage = file.getOptions().getJavaPackage();
javaPackages.put(file.getName(), javaPackage);
for (DescriptorProto messageType : file.getMessageTypeList()) {
String qname = file.getPackage() + "." + messageType.getName();
messageTypes.put(qname, messageType);
}
}
// Index RPCs
for (FileDescriptorProto file : proto.getFileList()) {
for (ServiceDescriptorProto service : file.getServiceList()) {
for (MethodDescriptorProto method : service.getMethodList()) {
MethodOptions options = method.getOptions();
String serviceName = service.getName();
String methodName = method.getName();
DescriptorProto inputType = messageTypes.get(method.getInputType().substring(1));
DescriptorProto outputType = messageTypes.get(method.getOutputType().substring(1));
if (options.hasExtension(AnnotationsProto.route)) {
HttpRoute route = options.getExtension(AnnotationsProto.route);
RpcDescriptor descriptor = new RpcDescriptor(serviceName, methodName, inputType, outputType, route);
String qname = String.join(".", file.getPackage(), serviceName, methodName);
rpcs.put(qname, descriptor);
} else if (options.hasExtension(AnnotationsProto.websocket)) {
WebSocketTopic topic = options.getExtension(AnnotationsProto.websocket);
RpcDescriptor descriptor = new RpcDescriptor(serviceName, methodName, inputType, outputType, topic);
String qname = String.join(".", file.getPackage(), serviceName, methodName);
rpcs.put(qname, descriptor);
}
}
}
}
}
Aggregations