com.google.protobuf.Descriptors.ServiceDescriptor Java Examples
The following examples show how to use
com.google.protobuf.Descriptors.ServiceDescriptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProtoReflectionService.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
private void processService(ServiceDescriptor service, FileDescriptor fd) { String serviceName = service.getFullName(); checkState( !fileDescriptorsBySymbol.containsKey(serviceName), "Service already defined: %s", serviceName); fileDescriptorsBySymbol.put(serviceName, fd); for (MethodDescriptor method : service.getMethods()) { String methodName = method.getFullName(); checkState( !fileDescriptorsBySymbol.containsKey(methodName), "Method already defined: %s", methodName); fileDescriptorsBySymbol.put(methodName, fd); } }
Example #2
Source File: ProtoReflectionService.java From grpc-java with Apache License 2.0 | 6 votes |
private void processService(ServiceDescriptor service, FileDescriptor fd) { String serviceName = service.getFullName(); checkState( !fileDescriptorsBySymbol.containsKey(serviceName), "Service already defined: %s", serviceName); fileDescriptorsBySymbol.put(serviceName, fd); for (MethodDescriptor method : service.getMethods()) { String methodName = method.getFullName(); checkState( !fileDescriptorsBySymbol.containsKey(methodName), "Method already defined: %s", methodName); fileDescriptorsBySymbol.put(methodName, fd); } }
Example #3
Source File: ProtoReflectionService.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
/** * Checks for updates to the server's mutable services and updates the index if any changes are * detected. A change is any addition or removal in the set of file descriptors attached to the * mutable services or a change in the service names. * * @return The (potentially updated) index. */ private ServerReflectionIndex updateIndexIfNecessary() { synchronized (lock) { if (serverReflectionIndex == null) { serverReflectionIndex = new ServerReflectionIndex(server.getImmutableServices(), server.getMutableServices()); return serverReflectionIndex; } Set<FileDescriptor> serverFileDescriptors = new HashSet<FileDescriptor>(); Set<String> serverServiceNames = new HashSet<String>(); List<ServerServiceDefinition> serverMutableServices = server.getMutableServices(); for (ServerServiceDefinition mutableService : serverMutableServices) { io.grpc.ServiceDescriptor serviceDescriptor = mutableService.getServiceDescriptor(); if (serviceDescriptor.getSchemaDescriptor() instanceof ProtoFileDescriptorSupplier) { String serviceName = serviceDescriptor.getName(); FileDescriptor fileDescriptor = ((ProtoFileDescriptorSupplier) serviceDescriptor.getSchemaDescriptor()) .getFileDescriptor(); serverFileDescriptors.add(fileDescriptor); serverServiceNames.add(serviceName); } } // Replace the index if the underlying mutable services have changed. Check both the file // descriptors and the service names, because one file descriptor can define multiple // services. FileDescriptorIndex mutableServicesIndex = serverReflectionIndex.getMutableServicesIndex(); if (!mutableServicesIndex.getServiceFileDescriptors().equals(serverFileDescriptors) || !mutableServicesIndex.getServiceNames().equals(serverServiceNames)) { serverReflectionIndex = new ServerReflectionIndex(server.getImmutableServices(), serverMutableServices); } return serverReflectionIndex; } }
Example #4
Source File: ProtoGenerator.java From fuchsia with Apache License 2.0 | 5 votes |
private void generateProtoFromDescriptor(ServiceDescriptor descriptor, Appendable out) throws IOException { out.append("service " + descriptor.getName() + " {\n"); for (MethodDescriptor methodDescriptor : descriptor.getMethods()) { generateProtoFromDescriptor(methodDescriptor, out); } out.append("}\n"); }
Example #5
Source File: ProtoGenerator.java From fuchsia with Apache License 2.0 | 5 votes |
public void generateProtoFromDescriptor(FileDescriptor descriptor, Appendable out, Descriptor wrapperMessage) throws IOException { String package1 = descriptor.getPackage(); if (package1 != null) { out.append("package " + package1 + ";\n"); } FileOptions options = descriptor.getOptions(); String javaPackage = options.getJavaPackage(); if (javaPackage != null) { out.append("option java_package = \"" + javaPackage + "\";\n"); } String javaOuterClassname = options.getJavaOuterClassname(); if (javaOuterClassname != null) { out.append("option java_outer_classname = \"" + javaOuterClassname + "\";\n"); } for (ServiceDescriptor serviceDescriptor : descriptor.getServices()) { generateProtoFromDescriptor(serviceDescriptor, out); } for (Descriptor messageDescriptor : descriptor.getMessageTypes()) { if (wrapperMessage != null && messageDescriptor.equals(wrapperMessage)) { out.append("// This is the message you can send to this service (wrapper message):\n"); } generateProtoFromDescriptor(messageDescriptor, out, "", new LinkedHashMap<Descriptor, Boolean>()); } for (EnumDescriptor enumDescriptor : descriptor.getEnumTypes()) { generateProtoFromDescriptor(enumDescriptor, out, ""); } }
Example #6
Source File: ProtocolBuffersMetaData.java From BIMserver with GNU Affero General Public License v3.0 | 5 votes |
public ServiceDescriptorContainer(ServiceDescriptor serviceDescriptor) { this.serviceDescriptor = serviceDescriptor; for (MethodDescriptor methodDescriptor : serviceDescriptor.getMethods()) { this.methodDescriptors.put( methodDescriptor.getName(), new MethodDescriptorContainer(this, methodDescriptor) ); } }
Example #7
Source File: ProtoReflectionService.java From grpc-java with Apache License 2.0 | 5 votes |
private void processFileDescriptor(FileDescriptor fd) { String fdName = fd.getName(); checkState(!fileDescriptorsByName.containsKey(fdName), "File name already used: %s", fdName); fileDescriptorsByName.put(fdName, fd); for (ServiceDescriptor service : fd.getServices()) { processService(service, fd); } for (Descriptor type : fd.getMessageTypes()) { processType(type, fd); } for (FieldDescriptor extension : fd.getExtensions()) { processExtension(extension, fd); } }
Example #8
Source File: ProtoReflectionService.java From grpc-java with Apache License 2.0 | 5 votes |
FileDescriptorIndex(List<ServerServiceDefinition> services) { Queue<FileDescriptor> fileDescriptorsToProcess = new ArrayDeque<>(); Set<String> seenFiles = new HashSet<>(); for (ServerServiceDefinition service : services) { io.grpc.ServiceDescriptor serviceDescriptor = service.getServiceDescriptor(); if (serviceDescriptor.getSchemaDescriptor() instanceof ProtoFileDescriptorSupplier) { FileDescriptor fileDescriptor = ((ProtoFileDescriptorSupplier) serviceDescriptor.getSchemaDescriptor()) .getFileDescriptor(); String serviceName = serviceDescriptor.getName(); checkState( !serviceNames.contains(serviceName), "Service already defined: %s", serviceName); serviceFileDescriptors.add(fileDescriptor); serviceNames.add(serviceName); if (!seenFiles.contains(fileDescriptor.getName())) { seenFiles.add(fileDescriptor.getName()); fileDescriptorsToProcess.add(fileDescriptor); } } } while (!fileDescriptorsToProcess.isEmpty()) { FileDescriptor currentFd = fileDescriptorsToProcess.remove(); processFileDescriptor(currentFd); for (FileDescriptor dependencyFd : currentFd.getDependencies()) { if (!seenFiles.contains(dependencyFd.getName())) { seenFiles.add(dependencyFd.getName()); fileDescriptorsToProcess.add(dependencyFd); } } } }
Example #9
Source File: RpcForwarder.java From protobuf-socket-rpc with MIT License | 5 votes |
/** * Get matching method. */ private MethodDescriptor getMethod(SocketRpcProtos.Request rpcRequest, ServiceDescriptor descriptor) throws RpcException { MethodDescriptor method = descriptor.findMethodByName( rpcRequest.getMethodName()); if (method == null) { throw new RpcException( ErrorReason.METHOD_NOT_FOUND, String.format("Could not find method %s in service %s", rpcRequest.getMethodName(), descriptor.getFullName()), null); } return method; }
Example #10
Source File: DescriptorsTest.java From travelguide with Apache License 2.0 | 5 votes |
public void testServiceDescriptor() throws Exception { ServiceDescriptor service = TestService.getDescriptor(); assertEquals("TestService", service.getName()); assertEquals("protobuf_unittest.TestService", service.getFullName()); assertEquals(UnittestProto.getDescriptor(), service.getFile()); assertEquals(2, service.getMethods().size()); MethodDescriptor fooMethod = service.getMethods().get(0); assertEquals("Foo", fooMethod.getName()); assertEquals(UnittestProto.FooRequest.getDescriptor(), fooMethod.getInputType()); assertEquals(UnittestProto.FooResponse.getDescriptor(), fooMethod.getOutputType()); assertEquals(fooMethod, service.findMethodByName("Foo")); MethodDescriptor barMethod = service.getMethods().get(1); assertEquals("Bar", barMethod.getName()); assertEquals(UnittestProto.BarRequest.getDescriptor(), barMethod.getInputType()); assertEquals(UnittestProto.BarResponse.getDescriptor(), barMethod.getOutputType()); assertEquals(barMethod, service.findMethodByName("Bar")); assertNull(service.findMethodByName("NoSuchMethod")); for (int i = 0; i < service.getMethods().size(); i++) { assertEquals(i, service.getMethods().get(i).getIndex()); } }
Example #11
Source File: ServiceResolver.java From grpc-swagger with MIT License | 5 votes |
private ServiceDescriptor findService(String packageName, String serviceName) { // TODO(dino): Consider creating an index. for (FileDescriptor fileDescriptor : fileDescriptors) { if (!fileDescriptor.getPackage().equals(packageName)) { // Package does not match this file, ignore. continue; } ServiceDescriptor serviceDescriptor = fileDescriptor.findServiceByName(serviceName); if (serviceDescriptor != null) { return serviceDescriptor; } } throw new IllegalArgumentException("Unable to find service with name: " + serviceName); }
Example #12
Source File: ServiceResolver.java From grpc-swagger with MIT License | 5 votes |
/** * Returns the descriptor of a protobuf method with the supplied grpc method name. If the method * cannot be found, this throws {@link IllegalArgumentException}. */ public MethodDescriptor resolveServiceMethod(GrpcMethodDefinition definition) { ServiceDescriptor service = findService(definition.getPackageName(), definition.getServiceName()); MethodDescriptor method = service.findMethodByName(definition.getMethodName()); if (method == null) { throw new IllegalArgumentException( "Unable to find method " + definition.getMethodName() + " in service " + definition.getServiceName()); } return method; }
Example #13
Source File: ServiceResolver.java From milkman with MIT License | 5 votes |
private ServiceDescriptor findService(String serviceName, String packageName) { // TODO(dino): Consider creating an index. for (FileDescriptor fileDescriptor : fileDescriptors) { if (!fileDescriptor.getPackage().equals(packageName)) { // Package does not match this file, ignore. continue; } ServiceDescriptor serviceDescriptor = fileDescriptor.findServiceByName(serviceName); if (serviceDescriptor != null) { return serviceDescriptor; } } throw new IllegalArgumentException("Unable to find service with name: " + serviceName); }
Example #14
Source File: ServiceResolver.java From milkman with MIT License | 5 votes |
private MethodDescriptor resolveServiceMethod( String serviceName, String methodName, String packageName) { ServiceDescriptor service = findService(serviceName, packageName); MethodDescriptor method = service.findMethodByName(methodName); if (method == null) { throw new IllegalArgumentException( "Unable to find method " + methodName + " in service " + serviceName); } return method; }
Example #15
Source File: ServiceResolver.java From milkman with MIT License | 5 votes |
/** Lists all of the services found in the file descriptors */ public Iterable<ServiceDescriptor> listServices() { ArrayList<ServiceDescriptor> serviceDescriptors = new ArrayList<ServiceDescriptor>(); for (FileDescriptor fileDescriptor: fileDescriptors) { serviceDescriptors.addAll(fileDescriptor.getServices()); } return serviceDescriptors; }
Example #16
Source File: ServiceResolver.java From grpc-swagger with MIT License | 5 votes |
/** * Lists all of the services found in the file descriptors */ public Iterable<ServiceDescriptor> listServices() { ArrayList<ServiceDescriptor> serviceDescriptors = new ArrayList<ServiceDescriptor>(); for (FileDescriptor fileDescriptor : fileDescriptors) { serviceDescriptors.addAll(fileDescriptor.getServices()); } return serviceDescriptors; }
Example #17
Source File: ServiceResolver.java From grpc-swagger with MIT License | 5 votes |
private ServiceDescriptor findService(String packageName, String serviceName) { // TODO(dino): Consider creating an index. for (FileDescriptor fileDescriptor : fileDescriptors) { if (!fileDescriptor.getPackage().equals(packageName)) { // Package does not match this file, ignore. continue; } ServiceDescriptor serviceDescriptor = fileDescriptor.findServiceByName(serviceName); if (serviceDescriptor != null) { return serviceDescriptor; } } throw new IllegalArgumentException("Unable to find service with name: " + serviceName); }
Example #18
Source File: ServiceResolver.java From grpc-swagger with MIT License | 5 votes |
/** * Returns the descriptor of a protobuf method with the supplied grpc method name. If the method * cannot be found, this throws {@link IllegalArgumentException}. */ public MethodDescriptor resolveServiceMethod(GrpcMethodDefinition definition) { ServiceDescriptor service = findService(definition.getPackageName(), definition.getServiceName()); MethodDescriptor method = service.findMethodByName(definition.getMethodName()); if (method == null) { throw new IllegalArgumentException( "Unable to find method " + definition.getMethodName() + " in service " + definition.getServiceName()); } return method; }
Example #19
Source File: ServiceResolver.java From grpc-swagger with MIT License | 5 votes |
/** * Lists all of the services found in the file descriptors */ public Iterable<ServiceDescriptor> listServices() { ArrayList<ServiceDescriptor> serviceDescriptors = new ArrayList<ServiceDescriptor>(); for (FileDescriptor fileDescriptor : fileDescriptors) { serviceDescriptors.addAll(fileDescriptor.getServices()); } return serviceDescriptors; }
Example #20
Source File: ProtoReflectionService.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
private void processFileDescriptor(FileDescriptor fd) { String fdName = fd.getName(); checkState(!fileDescriptorsByName.containsKey(fdName), "File name already used: %s", fdName); fileDescriptorsByName.put(fdName, fd); for (ServiceDescriptor service : fd.getServices()) { processService(service, fd); } for (Descriptor type : fd.getMessageTypes()) { processType(type, fd); } for (FieldDescriptor extension : fd.getExtensions()) { processExtension(extension, fd); } }
Example #21
Source File: ProtoReflectionService.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
FileDescriptorIndex(List<ServerServiceDefinition> services) { Queue<FileDescriptor> fileDescriptorsToProcess = new ArrayDeque<FileDescriptor>(); Set<String> seenFiles = new HashSet<String>(); for (ServerServiceDefinition service : services) { io.grpc.ServiceDescriptor serviceDescriptor = service.getServiceDescriptor(); if (serviceDescriptor.getSchemaDescriptor() instanceof ProtoFileDescriptorSupplier) { FileDescriptor fileDescriptor = ((ProtoFileDescriptorSupplier) serviceDescriptor.getSchemaDescriptor()) .getFileDescriptor(); String serviceName = serviceDescriptor.getName(); checkState( !serviceNames.contains(serviceName), "Service already defined: %s", serviceName); serviceFileDescriptors.add(fileDescriptor); serviceNames.add(serviceName); if (!seenFiles.contains(fileDescriptor.getName())) { seenFiles.add(fileDescriptor.getName()); fileDescriptorsToProcess.add(fileDescriptor); } } } while (!fileDescriptorsToProcess.isEmpty()) { FileDescriptor currentFd = fileDescriptorsToProcess.remove(); processFileDescriptor(currentFd); for (FileDescriptor dependencyFd : currentFd.getDependencies()) { if (!seenFiles.contains(dependencyFd.getName())) { seenFiles.add(dependencyFd.getName()); fileDescriptorsToProcess.add(dependencyFd); } } } }
Example #22
Source File: DescriptorsTest.java From travelguide with Apache License 2.0 | 4 votes |
public void testFileDescriptor() throws Exception { FileDescriptor file = UnittestProto.getDescriptor(); assertEquals("google/protobuf/unittest.proto", file.getName()); assertEquals("protobuf_unittest", file.getPackage()); assertEquals("UnittestProto", file.getOptions().getJavaOuterClassname()); assertEquals("google/protobuf/unittest.proto", file.toProto().getName()); assertEquals(Arrays.asList(UnittestImport.getDescriptor()), file.getDependencies()); Descriptor messageType = TestAllTypes.getDescriptor(); assertEquals(messageType, file.getMessageTypes().get(0)); assertEquals(messageType, file.findMessageTypeByName("TestAllTypes")); assertNull(file.findMessageTypeByName("NoSuchType")); assertNull(file.findMessageTypeByName("protobuf_unittest.TestAllTypes")); for (int i = 0; i < file.getMessageTypes().size(); i++) { assertEquals(i, file.getMessageTypes().get(i).getIndex()); } EnumDescriptor enumType = ForeignEnum.getDescriptor(); assertEquals(enumType, file.getEnumTypes().get(0)); assertEquals(enumType, file.findEnumTypeByName("ForeignEnum")); assertNull(file.findEnumTypeByName("NoSuchType")); assertNull(file.findEnumTypeByName("protobuf_unittest.ForeignEnum")); assertEquals(Arrays.asList(ImportEnum.getDescriptor()), UnittestImport.getDescriptor().getEnumTypes()); for (int i = 0; i < file.getEnumTypes().size(); i++) { assertEquals(i, file.getEnumTypes().get(i).getIndex()); } ServiceDescriptor service = TestService.getDescriptor(); assertEquals(service, file.getServices().get(0)); assertEquals(service, file.findServiceByName("TestService")); assertNull(file.findServiceByName("NoSuchType")); assertNull(file.findServiceByName("protobuf_unittest.TestService")); assertEquals(Collections.emptyList(), UnittestImport.getDescriptor().getServices()); for (int i = 0; i < file.getServices().size(); i++) { assertEquals(i, file.getServices().get(i).getIndex()); } FieldDescriptor extension = UnittestProto.optionalInt32Extension.getDescriptor(); assertEquals(extension, file.getExtensions().get(0)); assertEquals(extension, file.findExtensionByName("optional_int32_extension")); assertNull(file.findExtensionByName("no_such_ext")); assertNull(file.findExtensionByName( "protobuf_unittest.optional_int32_extension")); assertEquals(Collections.emptyList(), UnittestImport.getDescriptor().getExtensions()); for (int i = 0; i < file.getExtensions().size(); i++) { assertEquals(i, file.getExtensions().get(i).getIndex()); } }
Example #23
Source File: DescriptorsTest.java From travelguide with Apache License 2.0 | 4 votes |
public void testCustomOptions() throws Exception { Descriptor descriptor = UnittestCustomOptions.TestMessageWithCustomOptions.getDescriptor(); assertTrue( descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1)); assertEquals(Integer.valueOf(-56), descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1)); FieldDescriptor field = descriptor.findFieldByName("field1"); assertNotNull(field); assertTrue( field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1)); assertEquals(Long.valueOf(8765432109L), field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1)); EnumDescriptor enumType = UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor(); assertTrue( enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1)); assertEquals(Integer.valueOf(-789), enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1)); ServiceDescriptor service = UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor(); assertTrue( service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1)); assertEquals(Long.valueOf(-9876543210L), service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1)); MethodDescriptor method = service.findMethodByName("Foo"); assertNotNull(method); assertTrue( method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1)); assertEquals(UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2, method.getOptions().getExtension(UnittestCustomOptions.methodOpt1)); }
Example #24
Source File: GrpcDocServicePlugin.java From armeria with Apache License 2.0 | 4 votes |
ServiceEntry(ServiceDescriptor service, List<EndpointInfo> endpointInfos) { this.service = service; this.endpointInfos = ImmutableList.copyOf(endpointInfos); }
Example #25
Source File: GrpcDocServicePlugin.java From armeria with Apache License 2.0 | 4 votes |
ServiceEntryBuilder(ServiceDescriptor service) { this.service = service; }
Example #26
Source File: ProtoReflectionService.java From grpc-java with Apache License 2.0 | 4 votes |
/** * Retrieves the index for services of the server that dispatches the current call. Computes * one if not exist. The index is updated if any changes to the server's mutable services are * detected. A change is any addition or removal in the set of file descriptors attached to the * mutable services or a change in the service names. */ private ServerReflectionIndex getRefreshedIndex() { synchronized (lock) { Server server = InternalServer.SERVER_CONTEXT_KEY.get(); ServerReflectionIndex index = serverReflectionIndexes.get(server); if (index == null) { index = new ServerReflectionIndex(server.getImmutableServices(), server.getMutableServices()); serverReflectionIndexes.put(server, index); return index; } Set<FileDescriptor> serverFileDescriptors = new HashSet<>(); Set<String> serverServiceNames = new HashSet<>(); List<ServerServiceDefinition> serverMutableServices = server.getMutableServices(); for (ServerServiceDefinition mutableService : serverMutableServices) { io.grpc.ServiceDescriptor serviceDescriptor = mutableService.getServiceDescriptor(); if (serviceDescriptor.getSchemaDescriptor() instanceof ProtoFileDescriptorSupplier) { String serviceName = serviceDescriptor.getName(); FileDescriptor fileDescriptor = ((ProtoFileDescriptorSupplier) serviceDescriptor.getSchemaDescriptor()) .getFileDescriptor(); serverFileDescriptors.add(fileDescriptor); serverServiceNames.add(serviceName); } } // Replace the index if the underlying mutable services have changed. Check both the file // descriptors and the service names, because one file descriptor can define multiple // services. FileDescriptorIndex mutableServicesIndex = index.getMutableServicesIndex(); if (!mutableServicesIndex.getServiceFileDescriptors().equals(serverFileDescriptors) || !mutableServicesIndex.getServiceNames().equals(serverServiceNames)) { index = new ServerReflectionIndex(server.getImmutableServices(), serverMutableServices); serverReflectionIndexes.put(server, index); } return index; } }
Example #27
Source File: ProtocolBuffersMetaData.java From BIMserver with GNU Affero General Public License v3.0 | 4 votes |
public ServiceDescriptor getServiceDescriptor() { return serviceDescriptor; }
Example #28
Source File: ProtoServiceDescriptorSupplier.java From grpc-nebula-java with Apache License 2.0 | 2 votes |
/** * Returns service descriptor to the proto service. */ ServiceDescriptor getServiceDescriptor();
Example #29
Source File: ProtoServiceDescriptorSupplier.java From grpc-java with Apache License 2.0 | 2 votes |
/** * Returns service descriptor to the proto service. */ ServiceDescriptor getServiceDescriptor();